From 8d5c19d7bf401da58ad9a99fea42cb621ef04d5c Mon Sep 17 00:00:00 2001 From: fbt Date: Thu, 14 Apr 2016 17:58:33 +0300 Subject: [PATCH] Also that was wrong --- shutdown | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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 }