blob: d530265cd724843ae9260875b832d2771a2ce594 [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 Millerd93b48e2016-02-05 11:19:58 -060028image=/run/initramfs/image-
29if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e ${image}u-boot-env &&
Milton D. Miller IIbf7bfd42016-01-27 20:18:16 -060030 ! cmp /run/mtd:u-boot-env /run/fw_env
31then
Milton Millerd93b48e2016-02-05 11:19:58 -060032 ln -sn /run/fw_env ${image}u-boot-env
Milton D. Miller IIbf7bfd42016-01-27 20:18:16 -060033fi
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060034
Milton Millerd93b48e2016-02-05 11:19:58 -060035if test -x /update && ls $image* > /dev/null 2>&1
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060036then
37 exec /update ${1+"$@"}
38fi
39
40echo Remaining mounts:
41cat /proc/mounts
42
43test "umount_proc" && umount /proc && rmdir /proc
44
45
46
47# Execute the command systemd told us to ...
48if test -d /oldroot && test "$1"
49then
50 if test "$1" == kexec
51 then
52 $1 -f -e
53 else
54 $1 -f
55 fi
56fi
57
58
59echo "Execute ${1-reboot} -f if all unounted ok, or exec /init"
60
61export PS1=shutdown-sh#\
62exec /bin/sh