blob: d29db265d3debe30bdaca4efeec6031d00e35bee [file] [log] [blame]
Milton D. Miller IId89d5e02016-01-20 14:57:54 -06001#!/bin/sh
2
3echo shutdown: "$@"
4
5export PS1=shutdown-sh#\
6# exec bin/sh
7
8if [ ! -e /proc/mounts ]
9then
10 mkdir -p /proc
11 mount proc proc -tproc
12 umount_proc=1
13else
14 umount_proc=
15fi
16
17# remove an empty oldroot, that means we are not invoked from systemd-shutdown
18rmdir /oldroot 2>/dev/null
19
20set -x
21for f in $( awk '/oldroot/ { print $2 }' < /proc/mounts | sort -r )
22do
23 umount $f
24done
25set +x
26
Milton D. Miller IIbf7bfd42016-01-27 20:18:16 -060027if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e /image-u-boot-env &&
28 ! cmp /run/mtd:u-boot-env /run/fw_env
29then
Milton Miller34b1dca2016-02-05 11:06:39 -060030 ln -sn /run/fw_env /image-u-boot-env
Milton D. Miller IIbf7bfd42016-01-27 20:18:16 -060031fi
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060032
33if test -x /update && ls image-* > /dev/null 2>&1
34then
35 exec /update ${1+"$@"}
36fi
37
38echo Remaining mounts:
39cat /proc/mounts
40
41test "umount_proc" && umount /proc && rmdir /proc
42
43
44
45# Execute the command systemd told us to ...
46if test -d /oldroot && test "$1"
47then
48 if test "$1" == kexec
49 then
50 $1 -f -e
51 else
52 $1 -f
53 fi
54fi
55
56
57echo "Execute ${1-reboot} -f if all unounted ok, or exec /init"
58
59export PS1=shutdown-sh#\
60exec /bin/sh