Revert "sysupgrade: run only one instance at a time."
[openwrt/openwrt.git] / package / base-files / files / sbin / sysupgrade
index e6588bffcf61d0ae5cb906011ac32fa99283cb45..c095ca81c50c71021af2dc04a561ac22f6b7442b 100755 (executable)
@@ -1,5 +1,6 @@
 #!/bin/sh
 . /lib/functions.sh
+. /lib/functions/system.sh
 
 # initialize defaults
 RAMFS_COPY_BIN=""      # extra programs for temporary ramfs root
@@ -9,6 +10,7 @@ export INTERACTIVE=0
 export VERBOSE=1
 export SAVE_CONFIG=1
 export SAVE_OVERLAY=0
+export SAVE_PARTITIONS=1
 export DELAY=
 export CONF_IMAGE=
 export CONF_BACKUP_LIST=0
@@ -28,6 +30,7 @@ while [ -n "$1" ]; do
                -q) export VERBOSE="$(($VERBOSE - 1))";;
                -n) export SAVE_CONFIG=0;;
                -c) export SAVE_OVERLAY=1;;
+               -p) export SAVE_PARTITIONS=0;;
                -b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
                -r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
                -l|--list-backup) export CONF_BACKUP_LIST=1; break;;
@@ -61,6 +64,7 @@ upgrade-option:
        -i           interactive mode
        -c           attempt to preserve all changed files in /etc/
        -n           do not save configuration over reflash
+       -p           do not attempt to restore the partition table after flash.
        -T | --test
                     Verify image and config .tar.gz but do not actually flash.
        -F | --force
@@ -101,14 +105,20 @@ add_uci_conffiles() {
        local file="$1"
        ( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
                /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
-               -type f 2>/dev/null;
+               -type f -o -type l 2>/dev/null;
          opkg list-changed-conffiles ) | sort -u > "$file"
        return 0
 }
 
 add_overlayfiles() {
        local file="$1"
-       find /overlay/etc/ -type f | sed \
+       if [ -d /overlay/upper ]; then
+               local overlaydir="/overlay/upper"
+       else
+               local overlaydir="/overlay"
+       fi
+       find $overlaydir/etc/ -type f -o -type l | sed \
+               -e 's,^/overlay\/upper/,/,' \
                -e 's,^/overlay/,/,' \
                -e '\,/META_[a-zA-Z0-9]*$,d' \
                -e '\,/functions.sh$,d' \
@@ -118,13 +128,16 @@ add_overlayfiles() {
 }
 
 # hooks
-sysupgrade_image_check="platform_check_image"
+sysupgrade_image_check="fwtool_check_image platform_check_image"
+sysupgrade_pre_upgrade="fwtool_pre_upgrade"
 [ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \
        sysupgrade_init_conffiles="add_uci_conffiles" || \
        sysupgrade_init_conffiles="add_overlayfiles"
 
 include /lib/upgrade
 
+[ "$1" = "nand" ] && nand_upgrade_stage2 $@
+
 do_save_conffiles() {
        local conf_tar="${1:-$CONF_TAR}"
 
@@ -207,6 +220,14 @@ fi
 
 run_hooks "" $sysupgrade_pre_upgrade
 
+# Some platforms/devices may want different sysupgrade process, e.g. without
+# killing processes yet or calling ubus system upgrade method.
+# This is needed e.g. on NAND devices where we just want to trigger stage1 at
+# this point.
+if type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
+       platform_pre_upgrade "$ARGV"
+fi
+
 ubus call system upgrade
 touch /tmp/sysupgrade