sinit-tools/shutdown
2016-04-14 17:58:33 +03:00

44 lines
579 B
Bash
Executable File

#!/bin/sh
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) _poweroff;;
-r|--reboot) _reboot;;
-h|--help|--usage) usage; return;;
*) usage; return 1
esac
shift
done
exe_name="${0##*/}"
if [ -z "$init_signal" ]; then
case "$exe_name" in
poweroff) poff;;
reboot)
echo 'Rebooting.'
init_signal='INT';;
*) usage; return 1;;
esac
fi
kill -s "$init_signal" 1
}
main "$@"