blob: 7d1157a05b23df6f60a97b96b85d1f12af6e4c44 [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
Milton Miller39b6faa2016-02-05 13:56:18 -060037 /update ${1+"$@"}
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060038fi
39
40echo Remaining mounts:
41cat /proc/mounts
42
43test "umount_proc" && umount /proc && rmdir /proc
44
45
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060046# 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