forked from TapeWerm/MCscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCstop.sh
executable file
·59 lines (51 loc) · 1.22 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
#!/usr/bin/env bash
syntax='`./MCstop.sh $sessionname [$tmux_socket]`'
server_do() {
# Enter $* in the first pane of the first window of session $sessionname on socket $tmux_socket
tmux -S "$tmux_socket" send-keys -t "$sessionname:0.0" "$*" Enter
}
countdown() {
warning="Server stopping in $*"
server_do say "$warning"
echo "$warning"
}
case $1 in
--help|-h)
echo Warn Minecraft Java Edition or Bedrock Edition server running in tmux session 10 seconds before stopping.
echo "$syntax"
echo Best ran by systemd before shutdown.
exit
;;
esac
if [ "$#" -lt 1 ]; then
>&2 echo Not enough arguments
>&2 echo "$syntax"
exit 1
elif [ "$#" -gt 2 ]; then
>&2 echo Too much arguments
>&2 echo "$syntax"
exit 1
fi
sessionname=$1
if [ -n "$2" ]; then
# Remove trailing slash
tmux_socket=${2%/}
else
# $USER = `whoami` and is not set in cron
tmux_socket=/tmp/tmux-$(id -u "$(whoami)")/default
fi
if ! tmux -S "$tmux_socket" ls | grep -q "^$sessionname:"; then
>&2 echo "No session $sessionname on socket $tmux_socket"
exit 2
fi
countdown 10 seconds
sleep 5
server_do say "It was nice knowing you. What's your name again?"
sleep 2
countdown 3 seconds
sleep 1
countdown 2 seconds
sleep 1
countdown 1 second
sleep 1
server_do stop