sinit-tools/shutdown

42 lines
548 B
Plaintext
Raw Normal View History

2014-10-10 18:06:14 +04:00
#!/bin/sh
usage() { echo "Usage: shutdown <-p|-r>"; }
2016-04-14 17:58:33 +03:00
_poweroff() {
echo 'Shutting down.'
init_signal=USR1
}
_reboot() {
echo 'Rebooting.'
init_signal='INT'
}
2014-10-10 18:06:14 +04:00
main() {
while [ "$1" ]; do
case "$1" in
2016-04-14 17:58:33 +03:00
-p|--poweroff) _poweroff;;
-r|--reboot) _reboot;;
2014-10-10 18:06:14 +04:00
-h|--help|--usage) usage; return;;
*) usage; return 1
esac
shift
done
exe_name="${0##*/}"
2016-04-14 17:58:33 +03:00
if [ -z "$init_signal" ]; then
2014-10-10 18:06:14 +04:00
case "$exe_name" in
2016-04-14 18:01:14 +03:00
poweroff) _poweroff;;
reboot) _reboot;;
2014-10-10 18:06:14 +04:00
*) usage; return 1;;
esac
2016-04-14 17:58:33 +03:00
fi
2014-10-10 18:06:14 +04:00
kill -s "$init_signal" 1
}
main "$@"