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 D. Miller II | bf7bfd4 | 2016-01-27 20:18:16 -0600 | [diff] [blame] | 28 | if 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 |
| 30 | then |
Milton Miller | 34b1dca | 2016-02-05 11:06:39 -0600 | [diff] [blame] | 31 | ln -sn /run/fw_env /image-u-boot-env |
Milton D. Miller II | bf7bfd4 | 2016-01-27 20:18:16 -0600 | [diff] [blame] | 32 | fi |
Milton D. Miller II | d89d5e0 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 33 | |
Milton Miller | fc6a317 | 2016-02-05 11:06:39 -0600 | [diff] [blame] | 34 | if test -x /update && ls /image-* > /dev/null 2>&1 |
Milton D. Miller II | d89d5e0 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 35 | then |
| 36 | exec /update ${1+"$@"} |
| 37 | fi |
| 38 | |
| 39 | echo Remaining mounts: |
| 40 | cat /proc/mounts |
| 41 | |
| 42 | test "umount_proc" && umount /proc && rmdir /proc |
| 43 | |
| 44 | |
| 45 | |
| 46 | # Execute the command systemd told us to ... |
| 47 | if test -d /oldroot && test "$1" |
| 48 | then |
| 49 | if test "$1" == kexec |
| 50 | then |
| 51 | $1 -f -e |
| 52 | else |
| 53 | $1 -f |
| 54 | fi |
| 55 | fi |
| 56 | |
| 57 | |
| 58 | echo "Execute ${1-reboot} -f if all unounted ok, or exec /init" |
| 59 | |
| 60 | export PS1=shutdown-sh#\ |
| 61 | exec /bin/sh |