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