base-files: add support for staged sysupgrades from failsafe mode
[openwrt/openwrt.git] / package / base-files / files / sbin / sysupgrade
index 2d67371ef74b4b970076a069e97f4fd6a1e0bc95..809e789f9f436aaeb47a906d46c94d5952583e5a 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/sh
 
-[ "$1" = "nand" ] && exec /lib/upgrade/stage2 "$2" "$3"
-
 . /lib/functions.sh
 . /lib/functions/system.sh
 
@@ -253,8 +251,16 @@ run_hooks "" $sysupgrade_pre_upgrade
 
 install_bin /sbin/upgraded
 v "Commencing upgrade. All shell sessions will be closed now."
-ubus call system sysupgrade "{
-       \"prefix\": \"$RAM_ROOT\",
-       \"path\": $(json_string "$IMAGE"),
-       \"command\": \". /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2\"
-}"
+
+COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2'
+
+if [ -n "$FAILSAFE" ]; then
+       printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade
+       lock -u /tmp/.failsafe
+else
+       ubus call system sysupgrade "{
+               \"prefix\": $(json_string "$RAM_ROOT"),
+               \"path\": $(json_string "$IMAGE"),
+               \"command\": $(json_string "$COMMAND")
+       }"
+fi