sinit-tools/shutdown

42 lines
548 B
Plaintext
Raw Permalink Normal View History

#!/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) _poweroff;;
reboot) _reboot;;
*) usage; return 1;;
esac
fi
kill -s "$init_signal" 1
}
main "$@"