sinit-tools/shutdown
fbt eef7392bff Fixing a borked repo
Signed-off-by: fbt <fbt@fleshless.org>
2019-04-30 19:12:44 +03:00

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