Do not upgrade with SD card mounted. ()

pull/405/head
Paul Philippov 2022-08-24 23:51:27 -04:00 committed by GitHub
parent aea919a348
commit 05fc983308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 123 additions and 104 deletions
general/overlay/usr/sbin

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# OpenIPC.org | v.20220803 # OpenIPC.org | v.20220824
# #
scr_version=1.0.3 scr_version=1.0.3
@ -10,6 +10,7 @@ args=" $@"
set -e set -e
echo_c() { 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" [ -z "$HASERLVER" ] && t="\e[1;$1m$2\e[0m" || t="$2"
echo -e "$t" echo -e "$t"
} }
@ -65,7 +66,6 @@ do_update_rootfs() {
unset x unset x
} }
do_wipe_overlay() { do_wipe_overlay() {
echo_c 33 "\nOverlayFS" echo_c 33 "\nOverlayFS"
echo "Erase overlay partition" echo "Erase overlay partition"
@ -75,11 +75,8 @@ do_wipe_overlay() {
download_firmware() { download_firmware() {
echo_c 33 "\nFirmware" echo_c 33 "\nFirmware"
osr=$(get_system_build) osr=$(get_system_build)
if [[ "${osr}" == "lite" ]] || [[ "${osr}" == "" ]]; then build="-"
build="-" [ -n "${osr}" ] && [ "lite" != "${osr}" ] && build="${build}${osr}-"
else
build="-${osr}-"
fi
[ -z "$url" ] && url="https://github.com/OpenIPC/firmware/releases/download/latest/openipc.${soc}${build}br.tgz" [ -z "$url" ] && url="https://github.com/OpenIPC/firmware/releases/download/latest/openipc.${soc}${build}br.tgz"
echo "Download from $url" echo "Download from $url"
[ -z "$HASERLVER" ] && progress="-#" || progress="-s" [ -z "$HASERLVER" ] && progress="-#" || progress="-s"
@ -91,33 +88,32 @@ download_firmware() {
} }
free_resources() { 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 # killall majestic crond klogd ntpd rngd syslogd >/dev/null 2>&1 || true
# "load_$vendor" -r >/dev/null 2>&1 || true # "load_$vendor" -r >/dev/null 2>&1 || true
# #
echo_c 97 "\nStop services, sync and fresh memory" echo_c 37 "\nStop services, sync and fresh memory"
for proc in majestic crond klogd ntpd rngd syslogd for proc in majestic crond klogd ntpd rngd syslogd; do
do
echo -n "Killing $proc " echo -n "Killing $proc "
while [ -n "$(pidof $proc)" ] while [ -n "$(pidof $proc)" ]; do
do
killall $proc >/dev/null 2>&1 || true killall $proc >/dev/null 2>&1 || true
sleep 0.1 sleep 0.1
echo -n "." echo -n "."
done done
echo ". OK" echo ". OK"
done done
sync; echo 3 > /proc/sys/vm/drop_caches sync
echo 3 >/proc/sys/vm/drop_caches
} }
self_update() { self_update() {
if echo "${args}" | grep "rootfs" || echo "${args}" | grep "kernel" || echo "${args}" | grep -- "-n" > /dev/null 2>&1; then 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." echo -e "\nOffline operations."
else 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" 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
@ -125,16 +121,27 @@ self_update() {
exec /tmp/sysupgrade ${args} exec /tmp/sysupgrade ${args}
exit 1 exit 1
else else
echo "Ok, version match." echo "Same version. No update required."
fi fi
else 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 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() { 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 touch /tmp/sysupgrade.lock
} }
@ -165,31 +172,31 @@ get_system_build() {
print_sysinfo() { print_sysinfo() {
get_system_info get_system_info
echo_c 33 "OpenIPC System Updater" 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() { print_usage() {
echo " echo "
Usage: $0 [options] Usage: $0 [options]
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
--url=[URL] custom URL to update from (.tgz format) --url=[URL] custom URL 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
--force_all do not validate anything --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
-h, --help display this help and exit -h, --help display this help and exit
" "
} }
reboot_system() { reboot_system() {
[ "$skip_reboot" -eq 1 ] && echo_c 31 "\nReboot needed!" && exit 1 [ "$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 reboot -d 1 -f
} }
@ -204,83 +211,95 @@ update_rootfs=0
for i in "$@"; do for i in "$@"; do
case $i in case $i in
--force_all) --force_all)
skip_md5=1 skip_md5=1
skip_soc=1 skip_soc=1
skip_ver=1 skip_ver=1
shift shift
;; ;;
--force_md5) --force_md5)
skip_md5=1 skip_md5=1
shift shift
;; ;;
--force_soc) --force_soc)
skip_soc=1 skip_soc=1
shift shift
;; ;;
--force_ver) --force_ver)
skip_ver=1 skip_ver=1
shift shift
;; ;;
-h|--help) -h | --help)
print_sysinfo print_sysinfo
print_usage print_usage
exit 0 exit 0
;; ;;
-k ) -k)
update_kernel=1 update_kernel=1
remote_update=1 remote_update=1
shift shift
;; ;;
--kernel=*) --kernel=*)
update_kernel=1 update_kernel=1
kernel_file="${i#*=}" kernel_file="${i#*=}"
shift shift
;; ;;
-n|--wipe_overlay) -n | --wipe_overlay)
clear_overlay=1 clear_overlay=1
shift shift
;; ;;
-r) -r)
update_rootfs=1 update_rootfs=1
remote_update=1 remote_update=1
shift shift
;; ;;
--rootfs=*) --rootfs=*)
update_rootfs=1 update_rootfs=1
rootfs_file="${i#*=}" rootfs_file="${i#*=}"
shift shift
;; ;;
--url=*) --url=*)
url="${i#*=}" url="${i#*=}"
shift shift
;; ;;
-x|--no_reboot) -x | --no_reboot)
skip_reboot=1 skip_reboot=1
shift shift
;; ;;
*) *)
print_sysinfo print_sysinfo
echo_c 97 "\nUnknown option: $1" echo_c 37 "\nUnknown option: $1"
print_usage print_usage
exit 1 exit 1
;; ;;
esac esac
done done
print_sysinfo print_sysinfo
[ "$update_kernel" -eq 0 ] && \ [ "$update_kernel" -eq 0 ] &&
[ "$update_rootfs" -eq 0 ] && \ [ "$update_rootfs" -eq 0 ] &&
[ "$clear_overlay" -eq 0 ] && \ [ "$clear_overlay" -eq 0 ] &&
echo_c 97 "\nTry '$(basename "$0") --help' for options." && \ echo_c 37 "\nTry '$(basename "$0") --help' for options." &&
exit 0 exit 0
self_update self_update
check_sdcard
create_lock create_lock
free_resources free_resources
[ "$remote_update" -eq 1 ] && download_firmware [ "$remote_update" -eq 1 ] && download_firmware
[ "$update_kernel" -eq 1 ] && do_update_kernel "$kernel_file" [ "$update_kernel" -eq 1 ] && do_update_kernel "$kernel_file"
[ "$update_rootfs" -eq 1 ] && do_update_rootfs "$rootfs_file" [ "$update_rootfs" -eq 1 ] && do_update_rootfs "$rootfs_file"
[ "$clear_overlay" -eq 1 ] && do_wipe_overlay [ "$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