[LEDE-DEV] [RFC 11/13] base-files: add support for staged sysupgrades from failsafe mode

Matthias Schiffer mschiffer at universe-factory.net
Sun Apr 23 17:07:00 PDT 2017


Signed-off-by: Matthias Schiffer <mschiffer at universe-factory.net>
---
 .../base-files/files/lib/preinit/40_run_failsafe_hook  |  6 +++++-
 .../base-files/files/lib/preinit/99_10_failsafe_login  | 11 +++++++----
 package/base-files/files/sbin/sysupgrade               | 18 +++++++++++++-----
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/package/base-files/files/lib/preinit/40_run_failsafe_hook b/package/base-files/files/lib/preinit/40_run_failsafe_hook
index 7301f77349..533b0a9771 100644
--- a/package/base-files/files/lib/preinit/40_run_failsafe_hook
+++ b/package/base-files/files/lib/preinit/40_run_failsafe_hook
@@ -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
 }
 
diff --git a/package/base-files/files/lib/preinit/99_10_failsafe_login b/package/base-files/files/lib/preinit/99_10_failsafe_login
index 3147cdc5a6..728c63b2e8 100644
--- a/package/base-files/files/lib/preinit/99_10_failsafe_login
+++ b/package/base-files/files/lib/preinit/99_10_failsafe_login
@@ -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
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 18dfa50e05..5ec8762628 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -244,9 +244,17 @@ run_hooks "" $sysupgrade_pre_upgrade
 v "Commencing upgrade."
 [ -n "$(rootfs_type)" ] && v "All shell sessions will be closed now."
 
+COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2'
+
 install_bin /sbin/upgraded
-ubus call system sysupgrade "{
-	\"prefix\": \"$RAM_ROOT\",
-	\"path\": $(json_string "$IMAGE"),
-	\"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
-- 
2.12.2




More information about the Lede-dev mailing list