mirror of https://github.com/OpenIPC/firmware.git
Do not upgrade with SD card mounted. (#404)
parent
aea919a348
commit
05fc983308
|
@ -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="-"
|
||||||
else
|
[ -n "${osr}" ] && [ "lite" != "${osr}" ] && build="${build}${osr}-"
|
||||||
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,13 +172,13 @@ 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)
|
||||||
|
@ -189,7 +196,7 @@ Usage: $0 [options]
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +268,7 @@ for i in "$@"; do
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_sysinfo
|
print_sysinfo
|
||||||
echo_c 97 "\nUnknown option: $1"
|
echo_c 37 "\nUnknown option: $1"
|
||||||
print_usage
|
print_usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
@ -270,17 +277,29 @@ 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
|
||||||
|
|
||||||
|
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
|
reboot_system
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue