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