37 lines
520 B
Bash
Executable File
37 lines
520 B
Bash
Executable File
#!/bin/sh
|
|
|
|
usage() { echo "Usage: shutdown <-p|-r>"; }
|
|
|
|
main() {
|
|
while [ "$1" ]; do
|
|
case "$1" in
|
|
-p|--poweroff) init_signal='10';;
|
|
-r|--reboot) init_signal='2';;
|
|
|
|
-h|--help|--usage) usage; return;;
|
|
*) usage; return 1
|
|
esac
|
|
shift
|
|
done
|
|
|
|
exe_name="${0##*/}"
|
|
|
|
[ "$init_signal" ] || {
|
|
case "$exe_name" in
|
|
poweroff)
|
|
echo 'Shutting down.'
|
|
init_signal='USR1';;
|
|
|
|
reboot)
|
|
echo 'Rebooting.'
|
|
init_signal='INT';;
|
|
|
|
*) usage; return 1;;
|
|
esac
|
|
}
|
|
|
|
kill -s "$init_signal" 1
|
|
}
|
|
|
|
main "$@"
|