#!/bin/sh
-[ "$1" = "nand" ] && exec /lib/upgrade/stage2 "$2" "$3"
-
. /lib/functions.sh
. /lib/functions/system.sh
# initialize defaults
-RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
-RAMFS_COPY_DATA="" # extra data files
export MTD_CONFIG_ARGS=""
export INTERACTIVE=0
export VERBOSE=1
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