diff options
Diffstat (limited to 'shutdown')
-rwxr-xr-x | shutdown | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/shutdown b/shutdown index b456647..9b6bba4 100755 --- a/shutdown +++ b/shutdown @@ -6,7 +6,7 @@ single() { } abort() { - echo "$@" >&2 + printf '%s\n' "$1" >&2 exit 1 } @@ -37,7 +37,10 @@ time=$1; shift message="${*:-system is going down}" if [ "$action" = "cancel" ]; then - kill $(cat /run/runit/shutdown.pid) + kill "$(cat /run/runit/shutdown.pid)" + if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then + rm /etc/nologin + fi echo "${*:-shutdown cancelled}" | wall exit fi @@ -52,23 +55,19 @@ case "$time" in *) abort "invalid time";; esac -if [ "$time" -gt 5 ]; then - echo "$message in $time minutes" | wall - printf "shutdown: sleeping for $time minutes... " - sleep $(((time - 5) * 60)) - printf "\n" - time=5 -fi +for break in 5 0; do + [ "$time" -gt "$break" ] || continue + [ "$break" = 0 ] && touch /etc/nologin -if [ "$time" -gt 0 ]; then - echo "$message in $time minutes" | wall - touch /etc/nologin - printf "shutdown: sleeping for $time minutes... " - sleep $((time * 60)) - printf "\n" - rm /etc/nologin -fi + printf '%s in %s minutes\n' "$message" "$time" | wall + printf 'shutdown: sleeping for %s minutes... ' "$(( time - break ))" + sleep $(( (time - break) * 60 )) + time="$break" + printf '\n' + + [ "$break" = 0 ] && rm /etc/nologin +done -echo "$message NOW" | wall +printf '%s NOW\n' "$message" | wall $action |