|
@@ -1,4 +1,7 @@
|
|
|
#!/bin/sh
|
|
|
+
|
|
|
+[ "$1" = "nand" ] && exec /lib/upgrade/stage2 "$2" "$3"
|
|
|
+
|
|
|
. /lib/functions.sh
|
|
|
. /lib/functions/system.sh
|
|
|
|
|
@@ -11,7 +14,6 @@ export VERBOSE=1
|
|
|
export SAVE_CONFIG=1
|
|
|
export SAVE_OVERLAY=0
|
|
|
export SAVE_PARTITIONS=1
|
|
|
-export DELAY=
|
|
|
export CONF_IMAGE=
|
|
|
export CONF_BACKUP_LIST=0
|
|
|
export CONF_BACKUP=
|
|
@@ -25,7 +27,6 @@ export TEST=0
|
|
|
while [ -n "$1" ]; do
|
|
|
case "$1" in
|
|
|
-i) export INTERACTIVE=1;;
|
|
|
- -d) export DELAY="$2"; shift;;
|
|
|
-v) export VERBOSE="$(($VERBOSE + 1))";;
|
|
|
-q) export VERBOSE="$(($VERBOSE - 1))";;
|
|
|
-n) export SAVE_CONFIG=0;;
|
|
@@ -50,10 +51,9 @@ done
|
|
|
export CONFFILES=/tmp/sysupgrade.conffiles
|
|
|
export CONF_TAR=/tmp/sysupgrade.tgz
|
|
|
|
|
|
-export ARGV="$*"
|
|
|
-export ARGC="$#"
|
|
|
+IMAGE="$1"
|
|
|
|
|
|
-[ -z "$ARGV" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
|
|
|
+[ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
|
|
|
cat <<EOF
|
|
|
Usage: $0 [<upgrade-option>...] <image file or URL>
|
|
|
$0 [-q] [-i] <backup-command> <file>
|
|
@@ -90,7 +90,7 @@ EOF
|
|
|
exit 1
|
|
|
}
|
|
|
|
|
|
-[ -n "$ARGV" -a -n "$NEED_IMAGE" ] && {
|
|
|
+[ -n "$IMAGE" -a -n "$NEED_IMAGE" ] && {
|
|
|
cat <<-EOF
|
|
|
-b|--create-backup and -r|--restore-backup do not perform a firmware upgrade.
|
|
|
Do not specify both -b|-r and a firmware image.
|
|
@@ -136,14 +136,13 @@ sysupgrade_pre_upgrade="fwtool_pre_upgrade"
|
|
|
|
|
|
include /lib/upgrade
|
|
|
|
|
|
-[ "$1" = "nand" ] && nand_upgrade_stage2 $@
|
|
|
-
|
|
|
do_save_conffiles() {
|
|
|
local conf_tar="${1:-$CONF_TAR}"
|
|
|
|
|
|
[ -z "$(rootfs_type)" ] && {
|
|
|
echo "Cannot save config while running from ramdisk."
|
|
|
ask_bool 0 "Abort" && exit
|
|
|
+ rm -f "$conf_tar"
|
|
|
return 0
|
|
|
}
|
|
|
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
|
@@ -184,8 +183,33 @@ type platform_check_image >/dev/null 2>/dev/null || {
|
|
|
exit 1
|
|
|
}
|
|
|
|
|
|
+case "$IMAGE" in
|
|
|
+ http://*)
|
|
|
+ wget -O/tmp/sysupgrade.img "$IMAGE"
|
|
|
+ IMAGE=/tmp/sysupgrade.img
|
|
|
+ ;;
|
|
|
+esac
|
|
|
+
|
|
|
+IMAGE="$(readlink -f "$IMAGE")"
|
|
|
+
|
|
|
+case "$IMAGE" in
|
|
|
+ '')
|
|
|
+ echo "Image file not found."
|
|
|
+ exit 1
|
|
|
+ ;;
|
|
|
+ /tmp/*) ;;
|
|
|
+ *)
|
|
|
+ v "Image not in /tmp, copying..."
|
|
|
+ cp -f "$IMAGE" /tmp/sysupgrade.img
|
|
|
+ IMAGE=/tmp/sysupgrade.img
|
|
|
+ ;;
|
|
|
+esac
|
|
|
+
|
|
|
+export ARGV="$IMAGE"
|
|
|
+export ARGC=1
|
|
|
+
|
|
|
for check in $sysupgrade_image_check; do
|
|
|
- ( eval "$check \"\$ARGV\"" ) || {
|
|
|
+ ( $check "$IMAGE" ) || {
|
|
|
if [ $FORCE -eq 1 ]; then
|
|
|
echo "Image check '$check' failed but --force given - will update anyway!"
|
|
|
break
|
|
@@ -211,6 +235,7 @@ elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
|
|
|
[ $TEST -eq 1 ] || do_save_conffiles
|
|
|
export SAVE_CONFIG=1
|
|
|
else
|
|
|
+ [ $TEST -eq 1 ] || rm -f "$CONF_TAR"
|
|
|
export SAVE_CONFIG=0
|
|
|
fi
|
|
|
|
|
@@ -218,28 +243,18 @@ if [ $TEST -eq 1 ]; then
|
|
|
exit 0
|
|
|
fi
|
|
|
|
|
|
-run_hooks "" $sysupgrade_pre_upgrade
|
|
|
-
|
|
|
-# Some platforms/devices may want different sysupgrade process, e.g. without
|
|
|
-# killing processes yet or calling ubus system upgrade method.
|
|
|
-# This is needed e.g. on NAND devices where we just want to trigger stage1 at
|
|
|
-# this point.
|
|
|
-if type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
|
|
|
- platform_pre_upgrade "$ARGV"
|
|
|
+if [ $SAVE_PARTITIONS -eq 0 ]; then
|
|
|
+ touch /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
|
|
+else
|
|
|
+ rm -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
|
|
fi
|
|
|
|
|
|
-ubus call system upgrade
|
|
|
-touch /tmp/sysupgrade
|
|
|
-
|
|
|
-if [ ! -f /tmp/failsafe ] ; then
|
|
|
- kill_remaining TERM
|
|
|
- sleep 3
|
|
|
- kill_remaining KILL
|
|
|
-fi
|
|
|
+run_hooks "" $sysupgrade_pre_upgrade
|
|
|
|
|
|
-if [ -n "$(rootfs_type)" ]; then
|
|
|
- v "Switching to ramdisk..."
|
|
|
- run_ramfs '. /lib/functions.sh; include /lib/upgrade; do_upgrade'
|
|
|
-else
|
|
|
- do_upgrade
|
|
|
-fi
|
|
|
+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\"
|
|
|
+}"
|