diff --git a/shutdown b/shutdown index ab72979..a850e3d 100755 --- a/shutdown +++ b/shutdown @@ -2,11 +2,21 @@ usage() { echo "Usage: shutdown <-p|-r>"; } +_poweroff() { + echo 'Shutting down.' + init_signal=USR1 +} + +_reboot() { + echo 'Rebooting.' + init_signal='INT' +} + main() { while [ "$1" ]; do case "$1" in - -p|--poweroff) init_signal='10';; - -r|--reboot) init_signal='2';; + -p|--poweroff) _poweroff;; + -r|--reboot) _reboot;; -h|--help|--usage) usage; return;; *) usage; return 1 @@ -16,19 +26,16 @@ main() { exe_name="${0##*/}" - [ "$init_signal" ] || { + if [ -z "$init_signal" ]; then case "$exe_name" in - poweroff) - echo 'Shutting down.' - init_signal='USR1';; - + poweroff) poff;; reboot) echo 'Rebooting.' init_signal='INT';; *) usage; return 1;; esac - } + fi kill -s "$init_signal" 1 }