From ebd3d2e90e46ee0fe8fcbe4c1ce58bff856a7c3c Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 14:57:55 +0200 Subject: Makefile: Remove suspend from clean --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5d6ebb5..eb261d9 100644 --- a/Makefile +++ b/Makefile @@ -41,4 +41,4 @@ install: cp -aP services/* ${DESTDIR}/etc/sv/ clean: - -rm -f halt pause suspend + -rm -f halt pause -- cgit 1.4.1 From dd28b115e62ab5e6253bd5f1fc98da05357e7e52 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 14:58:07 +0200 Subject: Makefile: Add .PHONY --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index eb261d9..55a040b 100644 --- a/Makefile +++ b/Makefile @@ -42,3 +42,5 @@ install: clean: -rm -f halt pause + +.PHONY: all install clean -- cgit 1.4.1 From 33589dc9db67d059a1fcd8135ab793fe08b87ad0 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 14:58:53 +0200 Subject: shutdown.sh -> shutdown --- Makefile | 2 +- shutdown | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ shutdown.sh | 72 ------------------------------------------------------------- 3 files changed, 73 insertions(+), 73 deletions(-) create mode 100755 shutdown delete mode 100755 shutdown.sh diff --git a/Makefile b/Makefile index 55a040b..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 diff --git a/shutdown b/shutdown new file mode 100755 index 0000000..1fa8a5f --- /dev/null +++ b/shutdown @@ -0,0 +1,72 @@ +#!/bin/sh +# shutdown - shutdown(8) lookalike for runit + +single() { + runsvchdir single +} + +usage() { + echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >/dev/stderr; exit 1 +} + +action=single + +while getopts akrhPHfFnct: opt; do + case "$opt" in + a|n|H) echo "-$opt is not implemented" >/dev/stderr; exit 1;; + t) ;; + f) touch /fastboot;; + F) touch /forcefsck;; + k) action=true;; + c) action=cancel;; + h|P) action=halt;; + r) action=reboot;; + [?]) usage;; + esac +done +shift $(expr $OPTIND - 1) + +[ $# -eq 0 ] && usage + +time=$1; shift +message="${*:-system is going down}" + +if [ "$action" = "cancel" ]; then + kill $(cat /run/runit/shutdown.pid) + echo "${*:-shutdown cancelled}" | wall + exit +fi + +if ! touch /run/runit/shutdown.pid 2>/dev/null; then + echo "Not enough permissions to execute ${0#*/}" + exit 1 +fi +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;; +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 + 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 + rm /etc/nologin +fi + +echo "$message NOW" | wall + +$action diff --git a/shutdown.sh b/shutdown.sh deleted file mode 100755 index 1fa8a5f..0000000 --- a/shutdown.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# shutdown - shutdown(8) lookalike for runit - -single() { - runsvchdir single -} - -usage() { - echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >/dev/stderr; exit 1 -} - -action=single - -while getopts akrhPHfFnct: opt; do - case "$opt" in - a|n|H) echo "-$opt is not implemented" >/dev/stderr; exit 1;; - t) ;; - f) touch /fastboot;; - F) touch /forcefsck;; - k) action=true;; - c) action=cancel;; - h|P) action=halt;; - r) action=reboot;; - [?]) usage;; - esac -done -shift $(expr $OPTIND - 1) - -[ $# -eq 0 ] && usage - -time=$1; shift -message="${*:-system is going down}" - -if [ "$action" = "cancel" ]; then - kill $(cat /run/runit/shutdown.pid) - echo "${*:-shutdown cancelled}" | wall - exit -fi - -if ! touch /run/runit/shutdown.pid 2>/dev/null; then - echo "Not enough permissions to execute ${0#*/}" - exit 1 -fi -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;; -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 - 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 - rm /etc/nologin -fi - -echo "$message NOW" | wall - -$action -- cgit 1.4.1 From 6e03320cd69e3b9bb7647d3113d2684d3137b4cc Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 15:24:43 +0200 Subject: shutdown: simplify redirection to /dev/stderr --- shutdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shutdown b/shutdown index 1fa8a5f..7fe26ae 100755 --- a/shutdown +++ b/shutdown @@ -6,14 +6,14 @@ single() { } usage() { - echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >/dev/stderr; exit 1 + echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >&2; exit 1 } 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) echo "-$opt is not implemented" >&2; exit 1;; t) ;; f) touch /fastboot;; F) touch /forcefsck;; @@ -46,7 +46,7 @@ echo $$ >/run/runit/shutdown.pid case "$time" in now) time=0;; +*) time=${time#+};; - *:*) echo "absolute time is not implemented" >/dev/stderr; exit 1;; + *:*) echo "absolute time is not implemented" >&2; exit 1;; *) echo "invalid time"; exit 1;; esac -- cgit 1.4.1 From af68d02c0d3c576a874137e34abbe29e1ecc4c6f Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 15:54:08 +0200 Subject: shutdown: add abort helper function --- shutdown | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/shutdown b/shutdown index 7fe26ae..448e6d5 100755 --- a/shutdown +++ b/shutdown @@ -5,15 +5,20 @@ single() { runsvchdir single } +abort() { + echo "$@" >&2 + exit 1 +} + usage() { - echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >&2; 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" >&2; exit 1;; + a|n|H) abort "-$opt is not implemented";; t) ;; f) touch /fastboot;; F) touch /forcefsck;; @@ -38,16 +43,15 @@ if [ "$action" = "cancel" ]; then fi if ! touch /run/runit/shutdown.pid 2>/dev/null; then - echo "Not enough permissions to execute ${0#*/}" - exit 1 + abort "Not enough permissions to execute ${0#*/}" fi echo $$ >/run/runit/shutdown.pid case "$time" in now) time=0;; +*) time=${time#+};; - *:*) echo "absolute time is not implemented" >&2; exit 1;; - *) echo "invalid time"; exit 1;; + *:*) abort "absolute time is not implemented";; + *) abort "invalid time";; esac if [ "$time" -gt 5 ]; then -- cgit 1.4.1 From b5014c5fa2be5ce3cfb7ed3163b1f4a8fd1b87fe Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 15:56:46 +0200 Subject: shutdown: Don't use expr --- shutdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shutdown b/shutdown index 448e6d5..db4c8ac 100755 --- a/shutdown +++ b/shutdown @@ -29,7 +29,7 @@ while getopts akrhPHfFnct: opt; do [?]) usage;; esac done -shift $(expr $OPTIND - 1) +shift $((OPTIND - 1)) [ $# -eq 0 ] && usage @@ -57,7 +57,7 @@ esac if [ "$time" -gt 5 ]; then echo "$message in $time minutes" | wall echo -n "shutdown: sleeping for $time minutes... " - sleep $(expr '(' "$time" - 5 ')' '*' 60) + sleep $(((time - 5) * 60)) echo time=5 fi @@ -66,7 +66,7 @@ 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) + sleep $((time * 60)) echo rm /etc/nologin fi -- cgit 1.4.1 From 1db90dfc84e2484a7e0e7509b2d92800d035880e Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 15:59:36 +0200 Subject: shutdown: Use printf instead of echo -n The result of 'echo -n' is implementation-defined. See also: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html --- shutdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shutdown b/shutdown index db4c8ac..399ade6 100755 --- a/shutdown +++ b/shutdown @@ -56,18 +56,18 @@ esac if [ "$time" -gt 5 ]; then echo "$message in $time minutes" | wall - echo -n "shutdown: sleeping for $time minutes... " + printf "shutdown: sleeping for $time minutes... " sleep $(((time - 5) * 60)) - echo + 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... " + printf "shutdown: sleeping for $time minutes... " sleep $((time * 60)) - echo + printf "\n" rm /etc/nologin fi -- cgit 1.4.1 From ad1b077f91d4f51227b224ff2584a2b16d3bfbf5 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Tue, 31 Mar 2015 16:51:11 +0200 Subject: shutdown: simplify if clause --- shutdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shutdown b/shutdown index 399ade6..4a3147b 100755 --- a/shutdown +++ b/shutdown @@ -42,9 +42,7 @@ if [ "$action" = "cancel" ]; then exit fi -if ! touch /run/runit/shutdown.pid 2>/dev/null; then - abort "Not enough permissions to execute ${0#*/}" -fi +touch /run/runit/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}" echo $$ >/run/runit/shutdown.pid case "$time" in -- cgit 1.4.1