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