base-files: move stage2 upgrade to separated file
authorRafał Miłecki <rafal@milecki.pl>
Wed, 3 Jul 2019 07:51:49 +0000 (09:51 +0200)
committerRISCi_ATOM <bob@bobcall.me>
Fri, 13 Sep 2019 19:58:05 +0000 (15:58 -0400)
do_upgrade_stage2() isn't really any common code. It isn't used anywhere
except for /sbin/sysupgrade that passes it to the stage2.

Moving its code to separated file also simplifies COMMAND variable.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
(cherry picked from commit f7edd94a6588aa6a3e2e7a72410a34392a9fbe78)

package/base-files/files/lib/upgrade/common.sh
package/base-files/files/lib/upgrade/do_stage2 [new file with mode: 0755]
package/base-files/files/lib/upgrade/stage2
package/base-files/files/sbin/sysupgrade

index a13a6aaf5aefbfcf9178340506c32e71439d9d50..2afa0addb46ceda225d365a82df5fcf11a6f1f35 100644 (file)
@@ -225,25 +225,3 @@ default_do_upgrade() {
        fi
        [ $? -ne 0 ] && exit 1
 }
-
-do_upgrade_stage2() {
-       v "Performing system upgrade..."
-       if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
-               platform_do_upgrade "$IMAGE"
-       else
-               default_do_upgrade "$IMAGE"
-       fi
-
-       if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
-               platform_copy_config
-       fi
-
-       v "Upgrade completed"
-       sleep 1
-
-       v "Rebooting system..."
-       umount -a
-       reboot -f
-       sleep 5
-       echo b 2>/dev/null >/proc/sysrq-trigger
-}
diff --git a/package/base-files/files/lib/upgrade/do_stage2 b/package/base-files/files/lib/upgrade/do_stage2
new file mode 100755 (executable)
index 0000000..8aae452
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+. /lib/functions.sh
+
+include /lib/upgrade
+
+v "Performing system upgrade..."
+if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
+       platform_do_upgrade "$IMAGE"
+else
+       default_do_upgrade "$IMAGE"
+fi
+
+if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
+       platform_copy_config
+fi
+
+v "Upgrade completed"
+sleep 1
+
+v "Rebooting system..."
+umount -a
+reboot -f
+sleep 5
+echo b 2>/dev/null >/proc/sysrq-trigger
index 05d9214377fd293a19b8adb86d6c9e8e58968340..0a11cb2005e81e2d69bc1b720d678930337ef812 100755 (executable)
@@ -59,7 +59,7 @@ switch_to_ramfs() {
                local file="$(which "$binary" 2>/dev/null)"
                [ -n "$file" ] && install_bin "$file"
        done
-       install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
+       install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh /lib/upgrade/do_stage2 $RAMFS_COPY_DATA
 
        [ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
 
index 54d7a64b48524bf7918044394ee49e8da08e119b..73291262e7dc57915f63fc93e4338ab8a8b8fd6d 100755 (executable)
@@ -363,7 +363,7 @@ fi
 install_bin /sbin/upgraded
 v "Commencing upgrade. Closing all shell sessions."
 
-COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2'
+COMMAND='/lib/upgrade/do_stage2'
 
 if [ -n "$FAILSAFE" ]; then
        printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade