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