base-files: add support for staged sysupgrades from failsafe mode
authorMatthias Schiffer <mschiffer@universe-factory.net>
Sun, 23 Apr 2017 23:31:04 +0000 (01:31 +0200)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 29 May 2017 21:50:33 +0000 (23:50 +0200)
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
package/base-files/files/lib/preinit/40_run_failsafe_hook
package/base-files/files/lib/preinit/99_10_failsafe_login
package/base-files/files/sbin/sysupgrade

index 7301f77349a1a1e42fcef9bcbc927ef55c83b991..533b0a9771e1aac603f00ecf7a4622ea9fee969d 100644 (file)
@@ -5,8 +5,12 @@
 run_failsafe_hook() {
     [ "$pi_preinit_no_failsafe" = "y" ] && return
     if [ "$FAILSAFE" = "true" ]; then
+       lock /tmp/.failsafe
        boot_run_hook failsafe
-       lock -w /tmp/.failsafe
+       while [ ! -e /tmp/sysupgrade ]; do
+           lock -w /tmp/.failsafe
+       done
+       exit
     fi
 }
 
index 3147cdc5a68a69cef6b1af6618a4e2367a143c2c..728c63b2e8aebf970cd7dff0d15518ccda83029c 100644 (file)
@@ -8,10 +8,13 @@ failsafe_netlogin () {
 }
 
 failsafe_shell() {
-       lock /tmp/.failsafe
-       ash --login
-       echo "Please reboot system when done with failsafe network logins"
-       while true; do sleep 1; done
+       local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')"
+       [ -n "$console" ] || console=console
+       [ -c "/dev/$console" ] || return 0
+       while true; do
+               ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
+               sleep 1
+       done &
 }
 
 boot_hook_add failsafe failsafe_netlogin
index 200a0e520b5df8bcc208f4d8fd731756e94294fb..809e789f9f436aaeb47a906d46c94d5952583e5a 100755 (executable)
@@ -251,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