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(-) (limited to 'shutdown') 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