2022-03-08 11:48:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Copyright (C) 2020-present Fewtarius
|
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
2022-04-10 20:38:54 +00:00
|
|
|
|
2022-12-04 15:12:10 +00:00
|
|
|
ORGANIZATION="${GIT_ORGANIZATION}"
|
2022-04-11 22:14:56 +00:00
|
|
|
BRANCH="$(get_setting updates.branch)"
|
2022-12-04 15:12:10 +00:00
|
|
|
case ${BRANCH} in
|
|
|
|
dev)
|
|
|
|
PROJECT="${GIT_REPO}-dev"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PROJECT="${GIT_REPO}"
|
|
|
|
;;
|
|
|
|
esac
|
2022-04-10 20:38:54 +00:00
|
|
|
|
2022-04-11 22:14:56 +00:00
|
|
|
FORCE="$(get_setting updates.force)"
|
|
|
|
|
2022-04-10 20:38:54 +00:00
|
|
|
GIT_REPO="https://github.com/${ORGANIZATION}/${PROJECT}"
|
|
|
|
GIT_API="https://api.github.com/repos/${ORGANIZATION}/${PROJECT}"
|
2022-03-08 11:48:16 +00:00
|
|
|
UPDATE_PATH="/storage/.update"
|
2022-04-02 11:31:34 +00:00
|
|
|
EXTENSION="tar"
|
2022-03-08 11:48:16 +00:00
|
|
|
|
|
|
|
function check_network() {
|
|
|
|
GW=$(ip route | awk '/eth0/ {a=$0} END{print $1}')
|
|
|
|
if [[ ${GW} =~ [0-9] ]]
|
|
|
|
then
|
|
|
|
echo true
|
|
|
|
else
|
|
|
|
echo false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_available() {
|
|
|
|
echo $(df | awk '/'$1'/ {printf $4; exit}')
|
|
|
|
}
|
|
|
|
|
|
|
|
get_size() {
|
|
|
|
echo $(df | awk '/'$1'/ {printf $2; exit}')
|
|
|
|
}
|
|
|
|
|
|
|
|
check_space() {
|
|
|
|
MYSIZE="$(get_$1 $2)"
|
|
|
|
VOLNAME="$3"
|
|
|
|
REQUIRED="$4"
|
|
|
|
if [ "${MYSIZE}" -lt "${REQUIRED}" ]
|
|
|
|
then
|
|
|
|
NEEDED=$(( (${REQUIRED} - ${MYSIZE} ) / 1024 ))
|
2022-09-14 21:35:38 +00:00
|
|
|
echo -e "There is not enough free space available ${VOLNAME} to install this update. Free up an additional ${NEEDED}MB, or reflash the newer version."
|
|
|
|
echo "Exiting in 5 seconds..." && sleep 5
|
2022-03-08 11:48:16 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-07-24 12:04:29 +00:00
|
|
|
get_changelog() {
|
|
|
|
echo "Fetching change log."
|
2023-08-24 21:02:07 +00:00
|
|
|
echo -e "Change Log" >/storage/.cache/changelog
|
|
|
|
lynx --dump "${GIT_REPO}/releases/latest" 2>/dev/null | awk '/Contributors|Assets [0-9]/ {exit}; /Change Log/{p++;if(p==1){next}}p;' >>/storage/.cache/changelog
|
|
|
|
if [ ! "$?" = "0" ]
|
|
|
|
then
|
|
|
|
echo "Unable to fetch the change log, please ensure you have a network connection." >>/storage/.cache/changelog
|
|
|
|
fi
|
2023-07-24 12:04:29 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 21:02:07 +00:00
|
|
|
get_release_list() {
|
|
|
|
DATA=($(curl -H 'Cache-Control: no-cache' -Ls "${GIT_API}/releases" 2>/dev/null | python -c "import sys, json; data=json.load(sys.stdin); print(\"\\n\".join([str(data[i]['tag_name']) for i in range(10)]))"))
|
|
|
|
if [ ! -z "${DATA}" ]
|
|
|
|
then
|
|
|
|
printf "%s\n" "${DATA[@]}"
|
|
|
|
else
|
|
|
|
echo "Unable to fetch releases."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
### Check for passed arguments. If we receive changelog, fetch it. If we receive a version, force install it.
|
|
|
|
###
|
|
|
|
|
|
|
|
case ${1} in
|
|
|
|
changelog)
|
|
|
|
get_changelog >/dev/null 2>&1
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
releases)
|
|
|
|
get_release_list
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
[0-9][0-9]*)
|
|
|
|
LATEST_RELEASE_TAG=${1}
|
|
|
|
FORCE=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-03-08 11:48:16 +00:00
|
|
|
ONLINE_STATUS=$(check_network)
|
|
|
|
if [ ! "${ONLINE_STATUS}" == true ]
|
|
|
|
then
|
2022-09-14 21:35:38 +00:00
|
|
|
echo "System not online, cannot continue..."
|
|
|
|
echo "Exiting in 5 seconds..." && sleep 5
|
2022-03-08 11:48:16 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-14 21:35:38 +00:00
|
|
|
echo -e "=> ${OS_NAME} UPGRADE UTILITY"
|
2022-03-08 11:48:16 +00:00
|
|
|
|
|
|
|
# Check storage
|
2022-09-23 11:44:30 +00:00
|
|
|
check_space size flash boot 2048000 2>/dev/null
|
|
|
|
|
|
|
|
if [ "$(mountpoint -q /storage/roms)" ]
|
|
|
|
then
|
|
|
|
check_space available .update GAMES 4096000 2>/dev/null
|
|
|
|
fi
|
2022-03-08 11:48:16 +00:00
|
|
|
|
2023-08-24 21:02:07 +00:00
|
|
|
if [ -z "${LATEST_RELEASE_TAG}" ]
|
2022-03-08 11:48:16 +00:00
|
|
|
then
|
2023-08-24 21:02:07 +00:00
|
|
|
# Download
|
|
|
|
LATEST_RELEASE_TAG=$(curl -H 'Cache-Control: no-cache' -Ls "${GIT_API}/releases" | python -c "import sys, json; print(json.load(sys.stdin)[0]['tag_name'])")
|
|
|
|
if [ "${OS_VERSION}" -ge "${LATEST_RELEASE_TAG}" ] && [ ! "${FORCE}" = "1" ]
|
|
|
|
then
|
|
|
|
echo "No new updates are available..."
|
|
|
|
echo "Exiting in 5 seconds..." && sleep 5
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-03-08 11:48:16 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-14 21:35:38 +00:00
|
|
|
echo -e "\nFetching: ${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION}"
|
|
|
|
curl -Lo "${UPDATE_PATH}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION}" "${GIT_REPO}/releases/download/${LATEST_RELEASE_TAG}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.tar"
|
|
|
|
echo -e "Fetching: ${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION}.sha256"
|
|
|
|
curl -Lo "${UPDATE_PATH}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION}.sha256" "${GIT_REPO}/releases/download/${LATEST_RELEASE_TAG}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.tar.sha256"
|
2022-03-08 11:48:16 +00:00
|
|
|
|
2022-09-14 21:35:38 +00:00
|
|
|
echo -e "\nVerifying download, please wait..."
|
2022-03-08 11:48:16 +00:00
|
|
|
# Verify
|
2022-03-30 23:14:07 +00:00
|
|
|
MYSUM=$(sha256sum ${UPDATE_PATH}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION} | awk '{print $1}')
|
|
|
|
DLSUM=$(cat ${UPDATE_PATH}/${OS_NAME}-${HW_DEVICE}.${HW_ARCH}-${LATEST_RELEASE_TAG}.${EXTENSION}.sha256 | awk '{print $1}')
|
2022-03-08 11:48:16 +00:00
|
|
|
|
|
|
|
if [ ! "${MYSUM}" == "${DLSUM}" ]
|
|
|
|
then
|
2022-09-14 21:35:38 +00:00
|
|
|
echo "Verification failed, cleaning up and exiting..."
|
2022-03-12 11:15:45 +00:00
|
|
|
rm -f ${UPDATE_PATH}/*
|
2022-05-12 19:21:00 +00:00
|
|
|
sleep 5
|
2022-09-14 21:35:38 +00:00
|
|
|
clear
|
2022-03-08 11:48:16 +00:00
|
|
|
exit 1
|
|
|
|
else
|
2022-09-14 21:35:38 +00:00
|
|
|
echo "Verification successful..."
|
2022-03-08 11:48:16 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-24 12:04:29 +00:00
|
|
|
get_changelog
|
|
|
|
|
2022-04-11 22:14:56 +00:00
|
|
|
if [ "${FORCE}" == "1" ]
|
|
|
|
then
|
|
|
|
set_setting updates.force 0
|
|
|
|
fi
|
|
|
|
|
2022-09-14 21:35:38 +00:00
|
|
|
echo -e "\nRebooting to complete OS upgrade..."
|
2022-03-08 11:48:16 +00:00
|
|
|
sync
|
2022-03-22 20:07:23 +00:00
|
|
|
sleep 3
|
2022-03-08 11:48:16 +00:00
|
|
|
reboot
|