-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbye.sh
executable file
·85 lines (82 loc) · 1.9 KB
/
bye.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# File: bye.sh
# Author: Jason Charney, BSCS (jrcharneyATgmailDOTcom)
# Date: 26 Apr 2016
# Info: shutdown your computer with one word instead of four.
# Note: Yeah, I could have put this in ~/.bash_aliases, but a script would be better.
usage(){
cat << EOF
It shouldn't be this hard to use.
"-y", "y", or "yes", to turn off the computer.
"-r", "r", or "reboot", to restart the computer.
"n", or "no", to cancel this program.
"-h", "h", or "help", for this prompt.
I don't have a "logout" option, because you can simply do that by typing "exit".
I don't have a "sleep" or "hibernate" option, because the Raspberry Pi doesn't have that option.
EOF
}
case $# in
0)
try=0
while read -r -p "Are you sure you want to shutdown? [Y(es)/N(o)/R(eboot)]: " ans; do
case ${ans,,} in
y|q|yes)
if [ ${ans,,} == 'q' ]; then
echo "BYE Q!" # And everybody said "YATTA!!!" :3
else
echo "Shutting down. Goodbye."
fi
sudo shutdown -h now
exit 0
;;
r|reboot|restart)
echo "Rebooting. See you soon."
sudo reboot
exit 0
;;
n|no)
echo "Staying up."
exit 0
;;
h|help|huh)
try=0
usage
;;
*)
if [ $((++try)) -lt 3 ]; then
echo "Invalid entry, please try again."
else
echo "After three tries, I'm going to stay up."
exit 1
fi
;;
esac
done
;;
1) case $1 in
-y|-f|-q|--yes|--force)
if [ ${1} == '-q' ]; then
echo "BYE Q!" # And everybody said "YATTA!!!" :3
else
echo "Shutting down. Goodbye."
fi
sudo shutdown -h now
;; # shutdown immediately
-r|--reboot|--restart)
echo "Rebooting. See you soon."
sudo reboot
;; # reboot
-h|--help)
usage
exit 0
;;
*)
echo "Invalid option. I'm staying up."
exit 1
;;
esac
;;
*) echo "ERROR: Too many arguments! I'm not going to bed yet!"
exit 1
;;
esac