[no ci] sysupgrade: allow upgrade from local archive (#1678)

pull/1680/head
viktorxda 2025-01-24 09:08:14 +01:00 committed by GitHub
parent a3bc752449
commit dde6589987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 43 additions and 44 deletions

View File

@ -3,14 +3,11 @@
# OpenIPC.org | 2024 # OpenIPC.org | 2024
# #
scr_version=1.0.43 scr_version=1.0.44
args=" $@" args="$@"
LOCK_FILE=/tmp/sysupgrade.lock LOCK_FILE=/tmp/sysupgrade.lock
IPCINFO=/tmp/ipcinfo
[ -f ${IPCINFO} ] && chmod +x ${IPCINFO} || IPCINFO=$(which ipcinfo)
echo_c() { echo_c() {
# 31 red, 32 green, 33 yellow, 34 blue, 35 magenta, 36 cyan, 37 white, 38 grey # 31 red, 32 green, 33 yellow, 34 blue, 35 magenta, 36 cyan, 37 white, 38 grey
@ -61,11 +58,11 @@ do_update_rootfs() {
[ -z "$x" ] && x="/tmp/rootfs.squashfs.$soc" [ -z "$x" ] && x="/tmp/rootfs.squashfs.$soc"
echo_c 33 "\nRootFS" echo_c 33 "\nRootFS"
echo "Update rootfs from $x" echo "Update rootfs from $x"
[ ! -f "$x" ] && die "File ${x} not found" [ ! -f "$x" ] && die "File $x not found"
local y=/tmp/rootfs local y=/tmp/rootfs
if mkdir -p "$y" && loop=$(losetup -f) && losetup "$loop" "$x" && mount "$loop" "$y"; then if mkdir -p "$y" && loop=$(losetup -f) && losetup "$loop" "$x" && mount "$loop" "$y"; then
rootfs_version=$(get_system_version "$y") rootfs_version=$(get_system_version "$y")
check_soc "$(head -1 ${y}/etc/hostname | cut -d- -f2)" check_soc "$(head -1 $y/etc/hostname | cut -d- -f2)"
compare_versions "$system_version" "$rootfs_version" && exit_update=1 compare_versions "$system_version" "$rootfs_version" && exit_update=1
umount "$y" && rm -rf "$y" && losetup -d "$loop" umount "$y" && rm -rf "$y" && losetup -d "$loop"
[ "1" = "$exit_update" ] && return 0 [ "1" = "$exit_update" ] && return 0
@ -86,15 +83,17 @@ do_wipe_overlay() {
download_firmware() { download_firmware() {
[ "$flash_type" = "nand" ] && echo_c 31 "\nNote: the updater uses the NOR package for updating NAND" [ "$flash_type" = "nand" ] && echo_c 31 "\nNote: the updater uses the NOR package for updating NAND"
echo_c 33 "\nFirmware" echo_c 33 "\nFirmware"
[ "$branch_dev" = "1" ] && branch="dev" || branch="latest"
osr=$(get_system_build) osr=$(get_system_build)
ftype="nor" build="$soc-nor-$osr"
build="${soc}-${ftype}-${osr}" if [ -n "$archive" ]; then
[ -z "$url" ] && url=$(fw_printenv -n upgrade || echo "https://github.com/OpenIPC/firmware/releases/download/${branch}/openipc.${build}.tgz") [ ! -f "$archive" ] && die "File $archive not found"
echo "Download from $url" gzip -d "$archive" -c | tar xf - -C /tmp && echo_c 32 "Local archive unpacked" || die "Cannot extract $archive"
[ -z "$HASERLVER" ] && progress="-#" || progress="-s" else
[ "$(curl -o /dev/null -s -k -w '%{http_code}\n' "$url")" = "000" ] && die "Check your network!" [ -z "$url" ] && url=$(fw_printenv -n upgrade || echo "https://github.com/OpenIPC/firmware/releases/download/latest/openipc.$build.tgz")
curl --connect-timeout 30 -s -k -m 120 -L "$url" ${progress} -o - | gzip -d | tar xf - -C /tmp && echo_c 32 "Received and unpacked" || die "Cannot retrieve $url" echo "Download from $url"
[ "$(curl -o /dev/null -s -k -w '%{http_code}\n' "$url")" = "000" ] && die "Check your network!"
curl --connect-timeout 30 -s -k -m 120 -L "$url" -s -o - | gzip -d | tar xf - -C /tmp && echo_c 32 "Received and unpacked" || die "Cannot retrieve $url"
fi
if [ "1" != "$skip_md5" ]; then if [ "1" != "$skip_md5" ]; then
(cd /tmp && md5sum -s -c *.md5sum) || die "Wrong checksum!" (cd /tmp && md5sum -s -c *.md5sum) || die "Wrong checksum!"
fi fi
@ -103,7 +102,7 @@ download_firmware() {
free_resources() { free_resources() {
echo_c 37 "\nStop services, sync files, free up memory" echo_c 37 "\nStop services, sync files, free up memory"
killall -q -3 majestic killall -q -3 majestic
sleep 1 sleep 1
/etc/init.d/S60crond stop /etc/init.d/S60crond stop
/etc/init.d/S49ntpd stop /etc/init.d/S49ntpd stop
/etc/init.d/S02klogd stop /etc/init.d/S02klogd stop
@ -135,17 +134,17 @@ sync_time() {
} }
self_update() { self_update() {
if echo "${args}" | grep -E "\-(k|r|w|url)" >/dev/null 2>&1; then if echo "$args" | grep -E "\-(k|r|w|url)" >/dev/null 2>&1; then
sync_time sync_time
echo -e "\nChecking for sysupgrade update..." echo -e "\nChecking for sysupgrade update..."
curl -s -k -L -o /tmp/sysupgrade "https://raw.githubusercontent.com/OpenIPC/firmware/master/general/overlay/usr/sbin/sysupgrade" curl -s -k -L -o /tmp/sysupgrade "https://raw.githubusercontent.com/OpenIPC/firmware/master/general/overlay/usr/sbin/sysupgrade"
if [ -f /tmp/sysupgrade ] && grep -q "#!/bin/sh" /tmp/sysupgrade; then if [ -f /tmp/sysupgrade ] && grep -q "#!/bin/sh" /tmp/sysupgrade; then
dstv=$(grep scr_version /tmp/sysupgrade | head -1 | cut -f 2 -d '=') dstv=$(grep scr_version /tmp/sysupgrade | head -1 | cut -f 2 -d '=')
if ! [ "${scr_version}" = "${dstv}" ]; then if ! [ "$scr_version" = "$dstv" ]; then
echo "A new version is available, trying to activate updated script..." echo "A new version is available, trying to activate updated script..."
chmod +x /tmp/sysupgrade chmod +x /tmp/sysupgrade
echo -e "Done. Restarting...\n" echo -e "Done. Restarting...\n"
exec /tmp/sysupgrade ${args} exec /tmp/sysupgrade $args
exit 1 exit 1
else else
echo "Same version. No update required." echo "Same version. No update required."
@ -166,9 +165,9 @@ check_sdcard() {
echo_c 34 "$d" echo_c 34 "$d"
local f local f
for f in $stoplist; do for f in $stoplist; do
echo "- checking for ${d}/${f}" echo "- checking for $d/$f"
if [ -f "${d}/${f}" ]; then if [ -f "$d/$f" ]; then
echo_c 31 "\nCannot upgrade! Recovery file ${d}/${f} found on the mounted SD card!" echo_c 31 "\nCannot upgrade! Recovery file $d/$f found on the mounted SD card!"
echo_c 37 "Please remove the card from the slot and restart sysupgrade." echo_c 37 "Please remove the card from the slot and restart sysupgrade."
exit 1 exit 1
fi fi
@ -194,12 +193,12 @@ get_kernel_version() {
} }
get_system_info() { get_system_info() {
vendor=$(${IPCINFO} -v) vendor=$(ipcinfo -v)
soc=$(fw_printenv -n soc) || die "SoC is not defined in U-Boot environment" soc=$(fw_printenv -n soc) || die "SoC is not defined in U-Boot environment"
kernel_device=$(get_device "kernel") kernel_device=$(get_device "kernel")
kernel_version=$(get_kernel_version "$kernel_device") kernel_version=$(get_kernel_version "$kernel_device")
system_version=$(get_system_version "") system_version=$(get_system_version "")
flash_type=$(${IPCINFO} -F) flash_type=$(ipcinfo -F)
} }
get_system_version() { get_system_version() {
@ -212,7 +211,7 @@ get_system_build() {
print_sysinfo() { print_sysinfo() {
get_system_info get_system_info
echo_c 33 "OpenIPC System Updater v${scr_version}" echo_c 33 "OpenIPC System Updater v$scr_version"
echo_c 36 "\nVendor\t$vendor\nSoC\t$soc\nKernel\t$kernel_version\nRootFS\t$system_version" echo_c 36 "\nVendor\t$vendor\nSoC\t$soc\nKernel\t$kernel_version\nRootFS\t$system_version"
} }
@ -220,20 +219,20 @@ print_usage() {
echo " echo "
Usage: $0 [options] Usage: $0 [options]
Where: Where:
-k Update kernel from online repository. -k Update kernel from online repository.
-r Update rootfs from online repository. -r Update rootfs from online repository.
-d Update firmware from development branch. --url=[URL] Custom URL to update from (.tgz format).
--url=[URL] Custom URL to update from (.tgz format). --archive=[FILE] Custom archive to update from (.tgz format).
--kernel=[FILE] Update kernel from file (uImage format). --kernel=[FILE] Update kernel from file (uImage format).
--rootfs=[FILE] Update rootfs from file (squashfs format). --rootfs=[FILE] Update rootfs from file (squashfs format).
--force_md5 Do not validate MD5 hash. --force_md5 Do not validate MD5 hash.
--force_soc Do not validate processor. --force_soc Do not validate processor.
--force_ver Do not validate release version. --force_ver Do not validate release version.
-f, --force_all Do not validate anything. -f, --force_all Do not validate anything.
-n, --wipe_overlay Wipe overlay partition. -n, --wipe_overlay Wipe overlay partition.
-x, --no_reboot Do not reboot after updating. -x, --no_reboot Do not reboot after updating.
-z, --no_update Do not update self. -z, --no_update Do not update self.
-h, --help Display this help and exit. -h, --help Display this help and exit.
" "
} }
@ -274,11 +273,6 @@ for i in "$@"; do
shift shift
;; ;;
-d)
branch_dev=1
shift
;;
-h | --help) -h | --help)
print_sysinfo print_sysinfo
print_usage print_usage
@ -326,6 +320,11 @@ for i in "$@"; do
shift shift
;; ;;
--archive=*)
archive="${i#*=}"
shift
;;
-x | --no_reboot) -x | --no_reboot)
skip_reboot=1 skip_reboot=1
shift shift