-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
musicbotcmd
78 lines (69 loc) · 2.09 KB
/
musicbotcmd
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
#!/bin/bash
ProgName=$(basename $0)
sub_help(){
echo "Usage: $ProgName <subcommand> [options]"
echo "Subcommands:"
echo " start Start the MusicBot service"
echo " stop Stop the MusicBot service"
echo " restart Restart the MusicBot service"
echo " logs View logs for MusicBot"
echo " startup Toggle whether MusicBot will launch on startup"
echo ""
echo "For help with each subcommand run:"
echo "$ProgName <subcommand> -h|--help"
echo ""
}
sub_start(){
sudo systemctl start musicbot
}
sub_stop(){
sudo systemctl stop musicbot
}
sub_restart(){
sudo systemctl restart musicbot
}
sub_logs(){
journalctl -u musicbot -e -f
}
sub_startup(){
option=$1
case $option in
"--enable" | "-e")
echo "Enabling MusicBot launching on startup"
sudo systemctl enable musicbot;;
"--disable" | "-d")
echo "Disabling MusicBot launching on startup"
sudo systemctl disable musicbot;;
"-h" | "--help")
echo "Usage: $ProgName startup [options]"
echo "Toggles whether MusicBot will be started on system startup"
echo ""
echo "Options:"
echo " -e, --enable Enable starting MusicBot on startup"
echo " -d, --disable Disable starting MusicBot on startup"
echo "";;
*)
if test -f /etc/systemd/system/default.target.wants/musicbot.service; then
echo "Disabling MusicBot launching on startup"
sudo systemctl disable musicbot
else
echo "Enabling MusicBot launching on startup"
sudo systemctl enable musicbot
fi;;
esac
}
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
sub_help
;;
*)
shift
sub_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run '$ProgName --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac