diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-03-31 16:54:31 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-03-31 16:54:31 +0200 |
commit | 12c657aa09efeed53e54ecb8f3fbd40c46d32746 (patch) | |
tree | 0443be2e1d97bfaf9eb1ec714fbad4c1e469ea84 | |
parent | 03d9a47488e6775cbe1e983863564b2e00d2183a (diff) | |
parent | ad1b077f91d4f51227b224ff2584a2b16d3bfbf5 (diff) | |
download | runit-void-12c657aa09efeed53e54ecb8f3fbd40c46d32746.tar.gz runit-void-12c657aa09efeed53e54ecb8f3fbd40c46d32746.tar.xz runit-void-12c657aa09efeed53e54ecb8f3fbd40c46d32746.zip |
Merge pull request #31 from nmeum/halt
Various small shutdown(8) improvements
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | shutdown (renamed from shutdown.sh) | 32 |
2 files changed, 21 insertions, 17 deletions
diff --git a/Makefile b/Makefile index 5d6ebb5..5747f5f 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install: install -d ${DESTDIR}/${PREFIX}/sbin install -m755 halt ${DESTDIR}/${PREFIX}/sbin install -m755 pause ${DESTDIR}/${PREFIX}/sbin - install -m755 shutdown.sh ${DESTDIR}/${PREFIX}/sbin/shutdown + install -m755 shutdown ${DESTDIR}/${PREFIX}/sbin/shutdown install -m755 modules-load ${DESTDIR}/${PREFIX}/sbin/modules-load install -m755 zzz ${DESTDIR}/${PREFIX}/sbin ln -sf zzz ${DESTDIR}/${PREFIX}/sbin/ZZZ @@ -41,4 +41,6 @@ install: cp -aP services/* ${DESTDIR}/etc/sv/ clean: - -rm -f halt pause suspend + -rm -f halt pause + +.PHONY: all install clean diff --git a/shutdown.sh b/shutdown index 1fa8a5f..4a3147b 100755 --- a/shutdown.sh +++ b/shutdown @@ -5,15 +5,20 @@ single() { runsvchdir single } +abort() { + echo "$@" >&2 + exit 1 +} + usage() { - echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >/dev/stderr; exit 1 + abort "Usage: shutdown [-fF] [-kchPr] time [warning message]" } action=single while getopts akrhPHfFnct: opt; do case "$opt" in - a|n|H) echo "-$opt is not implemented" >/dev/stderr; exit 1;; + a|n|H) abort "-$opt is not implemented";; t) ;; f) touch /fastboot;; F) touch /forcefsck;; @@ -24,7 +29,7 @@ while getopts akrhPHfFnct: opt; do [?]) usage;; esac done -shift $(expr $OPTIND - 1) +shift $((OPTIND - 1)) [ $# -eq 0 ] && usage @@ -37,33 +42,30 @@ if [ "$action" = "cancel" ]; then exit fi -if ! touch /run/runit/shutdown.pid 2>/dev/null; then - echo "Not enough permissions to execute ${0#*/}" - exit 1 -fi +touch /run/runit/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}" echo $$ >/run/runit/shutdown.pid case "$time" in now) time=0;; +*) time=${time#+};; - *:*) echo "absolute time is not implemented" >/dev/stderr; exit 1;; - *) echo "invalid time"; exit 1;; + *:*) abort "absolute time is not implemented";; + *) abort "invalid time";; esac if [ "$time" -gt 5 ]; then echo "$message in $time minutes" | wall - echo -n "shutdown: sleeping for $time minutes... " - sleep $(expr '(' "$time" - 5 ')' '*' 60) - echo + printf "shutdown: sleeping for $time minutes... " + sleep $(((time - 5) * 60)) + printf "\n" time=5 fi if [ "$time" -gt 0 ]; then echo "$message in $time minutes" | wall touch /etc/nologin - echo -n "shutdown: sleeping for $time minutes... " - sleep $(expr "$time" '*' 60) - echo + printf "shutdown: sleeping for $time minutes... " + sleep $((time * 60)) + printf "\n" rm /etc/nologin fi |