base-files: always use staged sysupgrade
[openwrt/openwrt.git] / package / base-files / files / lib / upgrade / stage2
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/system.sh
5
6 export IMAGE="$1"
7 COMMAND="$2"
8
9 export ARGV="$IMAGE"
10 export ARGC=1
11
12 export SAVE_CONFIG=1
13 export SAVE_PARTITIONS=1
14
15 export INTERACTIVE=0
16 export VERBOSE=1
17 export CONFFILES=/tmp/sysupgrade.conffiles
18 export CONF_TAR=/tmp/sysupgrade.tgz
19
20
21 [ -f "$CONF_TAR" ] || export SAVE_CONFIG=0
22 [ -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap ] && export SAVE_PARTITIONS=0
23
24 include /lib/upgrade
25
26
27 killall -9 telnetd
28 killall -9 dropbear
29 killall -9 ash
30
31 kill_remaining TERM
32 sleep 3
33 kill_remaining KILL 1
34
35 sleep 1
36
37
38 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
39 IS_PRE_UPGRADE=1 platform_pre_upgrade "$IMAGE"
40
41 # Needs to be unset again because of busybox weirdness ...
42 IS_PRE_UPGRADE=
43 fi
44
45 if [ -n "$(rootfs_type)" ]; then
46 echo "Switching to ramdisk..."
47 run_ramfs "$COMMAND"
48 else
49 exec /bin/busybox ash -c "$COMMAND"
50 fi