31 lines
462 B
Plaintext
31 lines
462 B
Plaintext
|
#!/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) init_signal='USR1';;
|
||
|
reboot) init_signal='INT';;
|
||
|
*) usage; return 1;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
kill -s "$init_signal" 1
|
||
|
}
|
||
|
|
||
|
main "$@"
|