diff --git a/general/overlay/usr/sbin/sysupgrade b/general/overlay/usr/sbin/sysupgrade index fbce3acf..80dd8cbe 100755 --- a/general/overlay/usr/sbin/sysupgrade +++ b/general/overlay/usr/sbin/sysupgrade @@ -1,6 +1,6 @@ #!/bin/sh # -# OpenIPC.org | v.20220803 +# OpenIPC.org | v.20220824 # scr_version=1.0.3 @@ -10,6 +10,7 @@ args=" $@" set -e echo_c() { + # 31 red, 32 green, 33 yellow, 34 blue, 35 magenta, 36 cyan, 37 white, 38 grey [ -z "$HASERLVER" ] && t="\e[1;$1m$2\e[0m" || t="$2" echo -e "$t" } @@ -65,7 +66,6 @@ do_update_rootfs() { unset x } - do_wipe_overlay() { echo_c 33 "\nOverlayFS" echo "Erase overlay partition" @@ -75,11 +75,8 @@ do_wipe_overlay() { download_firmware() { echo_c 33 "\nFirmware" osr=$(get_system_build) - if [[ "${osr}" == "lite" ]] || [[ "${osr}" == "" ]]; then - build="-" - else - build="-${osr}-" - fi + build="-" + [ -n "${osr}" ] && [ "lite" != "${osr}" ] && build="${build}${osr}-" [ -z "$url" ] && url="https://github.com/OpenIPC/firmware/releases/download/latest/openipc.${soc}${build}br.tgz" echo "Download from $url" [ -z "$HASERLVER" ] && progress="-#" || progress="-s" @@ -91,33 +88,32 @@ download_firmware() { } free_resources() { - # echo_c 97 "\nStop services, unload modules" + # echo_c 37 "\nStop services, unload modules" # killall majestic crond klogd ntpd rngd syslogd >/dev/null 2>&1 || true # "load_$vendor" -r >/dev/null 2>&1 || true # - echo_c 97 "\nStop services, sync and fresh memory" - for proc in majestic crond klogd ntpd rngd syslogd - do + echo_c 37 "\nStop services, sync and fresh memory" + for proc in majestic crond klogd ntpd rngd syslogd; do echo -n "Killing $proc " - while [ -n "$(pidof $proc)" ] - do + while [ -n "$(pidof $proc)" ]; do killall $proc >/dev/null 2>&1 || true sleep 0.1 echo -n "." done echo ". OK" done - sync; echo 3 > /proc/sys/vm/drop_caches + sync + echo 3 >/proc/sys/vm/drop_caches } self_update() { - if echo "${args}" | grep "rootfs" || echo "${args}" | grep "kernel" || echo "${args}" | grep -- "-n" > /dev/null 2>&1; then - echo -e "\nOffline upgrade or Overlay clean, skip sysupgrade version check." + if echo "${args}" | grep "rootfs" || echo "${args}" | grep "kernel" || echo "${args}" | grep -- "-n" >/dev/null 2>&1; then + echo -e "\nOffline operations." else - echo -e "\nOnline upgrade, checking sysupgrade version..." + 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" 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 echo "A new version is available, trying to activate updated script..." chmod +x /tmp/sysupgrade @@ -125,16 +121,27 @@ self_update() { exec /tmp/sysupgrade ${args} exit 1 else - echo "Ok, version match." + echo "Same version. No update required." fi else - echo -e "\nVersion check failed. Possible network connection problem, script is corrupt or not found. Continue with bundled version." + echo -e "\nVersion checking failed, proceeding with the installed version." fi - fi + fi +} + +check_sdcard() { + if mount | grep /mnt/mmc >/dev/null; then + echo_c 31 "\nCannot upgrade! There is a mounted SD card in the slot!" + echo_c 37 "Please remove the card from the slot and restart sysupgrade." + exit 1 + fi } create_lock() { - [ -f /tmp/sysupgrade.lock ] && echo -e "\e[1;31m\nAnother sysupgrade process is already running!\e[0m\n" && exit 1 + if [ -f /tmp/sysupgrade.lock ]; then + echo_c 31 "\nAnother sysupgrade process is already running!" + exit 1 + fi touch /tmp/sysupgrade.lock } @@ -165,31 +172,31 @@ get_system_build() { print_sysinfo() { get_system_info echo_c 33 "OpenIPC System Updater" - echo_c 96 "\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" } print_usage() { echo " Usage: $0 [options] - - -k update kernel from online repository - -r update rootfs from online repository - --url=[URL] custom URL to update from (.tgz format) - --kernel=[FILE] update kernel from file (uImage format) - --rootfs=[FILE] update rootfs from file (squashfs format) - --force_md5 do not validate MD5 hash - --force_soc do not validate processor - --force_ver do not validate release version - --force_all do not validate anything - -n, --wipe_overlay wipe overlay partition - -x, --no_reboot do not reboot after updating - -h, --help display this help and exit +Where: + -k update kernel from online repository + -r update rootfs from online repository + --url=[URL] custom URL to update from (.tgz format) + --kernel=[FILE] update kernel from file (uImage format) + --rootfs=[FILE] update rootfs from file (squashfs format) + --force_md5 do not validate MD5 hash + --force_soc do not validate processor + --force_ver do not validate release version + --force_all do not validate anything + -n, --wipe_overlay wipe overlay partition + -x, --no_reboot do not reboot after updating + -h, --help display this help and exit " } reboot_system() { [ "$skip_reboot" -eq 1 ] && echo_c 31 "\nReboot needed!" && exit 1 - echo_c 97 "\nUnconditional reboot" + echo_c 37 "\nUnconditional reboot" reboot -d 1 -f } @@ -204,83 +211,95 @@ update_rootfs=0 for i in "$@"; do case $i in - --force_all) - skip_md5=1 - skip_soc=1 - skip_ver=1 - shift - ;; - --force_md5) - skip_md5=1 - shift - ;; - --force_soc) - skip_soc=1 - shift - ;; - --force_ver) - skip_ver=1 - shift - ;; - -h|--help) - print_sysinfo - print_usage - exit 0 - ;; - -k ) - update_kernel=1 - remote_update=1 - shift - ;; - --kernel=*) - update_kernel=1 - kernel_file="${i#*=}" - shift - ;; - -n|--wipe_overlay) - clear_overlay=1 - shift - ;; - -r) - update_rootfs=1 - remote_update=1 - shift - ;; - --rootfs=*) - update_rootfs=1 - rootfs_file="${i#*=}" - shift - ;; - --url=*) - url="${i#*=}" - shift - ;; - -x|--no_reboot) - skip_reboot=1 - shift - ;; - *) - print_sysinfo - echo_c 97 "\nUnknown option: $1" - print_usage - exit 1 - ;; + --force_all) + skip_md5=1 + skip_soc=1 + skip_ver=1 + shift + ;; + --force_md5) + skip_md5=1 + shift + ;; + --force_soc) + skip_soc=1 + shift + ;; + --force_ver) + skip_ver=1 + shift + ;; + -h | --help) + print_sysinfo + print_usage + exit 0 + ;; + -k) + update_kernel=1 + remote_update=1 + shift + ;; + --kernel=*) + update_kernel=1 + kernel_file="${i#*=}" + shift + ;; + -n | --wipe_overlay) + clear_overlay=1 + shift + ;; + -r) + update_rootfs=1 + remote_update=1 + shift + ;; + --rootfs=*) + update_rootfs=1 + rootfs_file="${i#*=}" + shift + ;; + --url=*) + url="${i#*=}" + shift + ;; + -x | --no_reboot) + skip_reboot=1 + shift + ;; + *) + print_sysinfo + echo_c 37 "\nUnknown option: $1" + print_usage + exit 1 + ;; esac done print_sysinfo -[ "$update_kernel" -eq 0 ] && \ -[ "$update_rootfs" -eq 0 ] && \ -[ "$clear_overlay" -eq 0 ] && \ -echo_c 97 "\nTry '$(basename "$0") --help' for options." && \ -exit 0 +[ "$update_kernel" -eq 0 ] && + [ "$update_rootfs" -eq 0 ] && + [ "$clear_overlay" -eq 0 ] && + echo_c 37 "\nTry '$(basename "$0") --help' for options." && + exit 0 self_update + +check_sdcard + create_lock free_resources + [ "$remote_update" -eq 1 ] && download_firmware [ "$update_kernel" -eq 1 ] && do_update_kernel "$kernel_file" [ "$update_rootfs" -eq 1 ] && do_update_rootfs "$rootfs_file" [ "$clear_overlay" -eq 1 ] && do_wipe_overlay -reboot_system + +if [ "1" = "$skip_reboot" ]; then + echo_c 33 "You asked me not to reboot, so I won't." + echo_c 37 "Please reboot the camera manually whenever possible." +else + reboot_system +fi + +exit 0