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 | |
| 27 | |
| 28 | if test -x /update && ls image-* > /dev/null 2>&1 |
| 29 | then |
| 30 | exec /update ${1+"$@"} |
| 31 | fi |
| 32 | |
| 33 | echo Remaining mounts: |
| 34 | cat /proc/mounts |
| 35 | |
| 36 | test "umount_proc" && umount /proc && rmdir /proc |
| 37 | |
| 38 | |
| 39 | |
| 40 | # Execute the command systemd told us to ... |
| 41 | if test -d /oldroot && test "$1" |
| 42 | then |
| 43 | if test "$1" == kexec |
| 44 | then |
| 45 | $1 -f -e |
| 46 | else |
| 47 | $1 -f |
| 48 | fi |
| 49 | fi |
| 50 | |
| 51 | |
| 52 | echo "Execute ${1-reboot} -f if all unounted ok, or exec /init" |
| 53 | |
| 54 | export PS1=shutdown-sh#\ |
| 55 | exec /bin/sh |