diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2017-04-22 00:54:50 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2017-05-29 23:50:32 +0200 |
commit | 30f61a34b4cfd2c676fea4a919e089d6a77254e9 (patch) | |
tree | 7871075ece4c004f08f90da8f9a4692d11ae782c /package/base-files/files/lib/upgrade/common.sh | |
parent | 393817df5d7046fadf137f9b0a363cb00551d2de (diff) | |
download | upstream-30f61a34b4cfd2c676fea4a919e089d6a77254e9.tar.gz upstream-30f61a34b4cfd2c676fea4a919e089d6a77254e9.tar.bz2 upstream-30f61a34b4cfd2c676fea4a919e089d6a77254e9.zip |
base-files: always use staged sysupgrade
Support for the -d and -p options is dropped; it may be added again at some
point by adding these flags to the ubus sysupgrade call.
A downside of this is that we get a lot less information about the progress
of the upgrade: as soon as the actual upgrade starts, all shell sessions
are killed to allow unmounting the root filesystem.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Diffstat (limited to 'package/base-files/files/lib/upgrade/common.sh')
-rw-r--r-- | package/base-files/files/lib/upgrade/common.sh | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index e3519ca2cb..17248c2b1d 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -56,7 +56,6 @@ run_ramfs() { # <command> [...] /bin/rm /usr/bin/basename /bin/kill /bin/chmod /usr/bin/find \ /bin/mknod - install_bin /bin/uclient-fetch /bin/wget install_bin /sbin/mtd install_bin /sbin/mount_root install_bin /sbin/snapshot @@ -96,51 +95,37 @@ run_ramfs() { # <command> [...] exec /bin/busybox ash -c "$*" } -kill_remaining() { # [ <signal> ] +kill_remaining() { # [ <signal> [ <loop> ] ] local sig="${1:-TERM}" + local loop="${2:-0}" + local run=true + local stat + echo -n "Sending $sig to remaining processes ... " - local my_pid=$$ - local my_ppid=$(cut -d' ' -f4 /proc/$my_pid/stat) - local my_ppisupgraded= - grep -q upgraded /proc/$my_ppid/cmdline >/dev/null && { - local my_ppisupgraded=1 - } - - local stat - for stat in /proc/[0-9]*/stat; do - [ -f "$stat" ] || continue - - local pid name state ppid rest - read pid name state ppid rest < $stat - name="${name#(}"; name="${name%)}" - - local cmdline - read cmdline < /proc/$pid/cmdline - - # Skip kernel threads - [ -n "$cmdline" ] || continue - - if [ $$ -eq 1 ] || [ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then - # Running as init process, kill everything except me - if [ $pid -ne $$ ] && [ $pid -ne $my_ppid ]; then - echo -n "$name " - kill -$sig $pid 2>/dev/null - fi - else - case "$name" in - # Skip essential services - *procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*|*relayd*) : ;; - - # Killable process - *) - if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then - echo -n "$name " - kill -$sig $pid 2>/dev/null - fi - ;; - esac - fi + while $run; do + run=false + for stat in /proc/[0-9]*/stat; do + [ -f "$stat" ] || continue + + local pid name state ppid rest + read pid name state ppid rest < $stat + name="${name#(}"; name="${name%)}" + + # Skip PID1, ourself and our children + [ $pid -ne 1 -a $pid -ne $$ -a $ppid -ne $$ ] || continue + + local cmdline + read cmdline < /proc/$pid/cmdline + + # Skip kernel threads + [ -n "$cmdline" ] || continue + + echo -n "$name " + kill -$sig $pid 2>/dev/null + + [ $loop -eq 1 ] && run=true + done done echo "" } @@ -175,28 +160,31 @@ v() { [ "$VERBOSE" -ge 1 ] && echo "$@" } +json_string() { + local v="$1" + v="${v//\\/\\\\}" + v="${v//\"/\\\"}" + echo "\"$v\"" +} + rootfs_type() { /bin/mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }' } get_image() { # <source> [ <command> ] local from="$1" - local conc="$2" - local cmd - - case "$from" in - http://*|ftp://*) cmd="wget -O- -q";; - *) cmd="cat";; - esac - if [ -z "$conc" ]; then - local magic="$(eval $cmd \"$from\" 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" + local cat="$2" + + if [ -z "$cat" ]; then + local magic="$(dd if="$from" bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" case "$magic" in - 1f8b) conc="zcat";; - 425a) conc="bzcat";; + 1f8b) cat="zcat";; + 425a) cat="bzcat";; + *) cat="cat";; esac fi - eval "$cmd \"$from\" 2>/dev/null ${conc:+| $conc}" + $cat "$from" 2>/dev/null } get_magic_word() { @@ -320,12 +308,14 @@ default_do_upgrade() { fi } -do_upgrade() { +do_upgrade_stage2() { v "Performing system upgrade..." - if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then - platform_do_upgrade "$ARGV" + if [ -n "$do_upgrade" ]; then + $do_upgrade "$IMAGE" + elif type 'platform_do_upgrade' >/dev/null 2>/dev/null; then + platform_do_upgrade "$IMAGE" else - default_do_upgrade "$ARGV" + default_do_upgrade "$IMAGE" fi if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then @@ -333,12 +323,11 @@ do_upgrade() { fi v "Upgrade completed" - [ -n "$DELAY" ] && sleep "$DELAY" - ask_bool 1 "Reboot" && { - v "Rebooting system..." - umount -a - reboot -f - sleep 5 - echo b 2>/dev/null >/proc/sysrq-trigger - } + sleep 1 + + v "Rebooting system..." + umount -a + reboot -f + sleep 5 + echo b 2>/dev/null >/proc/sysrq-trigger } |