}
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
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