-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmcstop.sh
executable file
·87 lines (76 loc) · 1.95 KB
/
mcstop.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
85
86
87
#!/bin/bash
console() { # Passes commands to the console.
if screen -list | grep -q "\.$server_session"; then
screen -S "$server_session" -X stuff ''"$*\n"''
else
exit 1
fi
}
stopmc() {
if screen -list | grep -q "\.$server_session"; then
console 'save-all' # Save worlds.
sleep "1s"
console 'title @a actionbar {"text":"Server shutdown in '30's!","color":"dark_red"}'
sleep 20s
for i in {10..1}
do
console 'title @a actionbar {"text":"Server shutdown in '$i's","color":"gold"}'
sleep 1s
done
sleep 0.5s
console 'title @a actionbar {"text":"Shutdown NOW!","color":"dark_red"}'
console 'stop'
stop_timeout
else
exit 1
fi
}
stopproxy() {
if screen -list | grep -q "\.$server_session"; then
sleep "1s"
console 'end'
stop_timeout
else
exit 1
fi
}
stop_timeout(){
while true; do
if screen -list | grep -q "\.$server_session"; then
sleep "1s"
else
break
echo "done."
sleep "2s"
fi
done
}
# Updates this script from the remote repository.
self_update(){
if [ "$(whoami)" != "root" ]; then printf "This script requires root privileges\n"; exit 1; fi
wget https://raw.githubusercontent.com/spacelord09/mcserver-deploy/master/mcstop.sh -O "$0"
chmod +x "$0"
}
for i in "$@"; do
case $i in
--update)
self_update
exit 0
;;
--stop=*)
server_session="${i#*=}"
stopmc
exit 0
;;
--stopproxy=*)
server_session="${i#*=}"
stopproxy
;;
-h|--help)
printf "\n ${c_green}-h,\t --help${normal}\t\tShow this message and exit\n"
exit 1
;;
esac
shift
done
exit 0