summarylogtreecommitdiffstats
path: root/tshock.sh
blob: ec3a49d2156784f3ad73f23d993be372ecdbd83a (plain)
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
#!/bin/bash

CONFDIR='/etc/conf.d/tshock'

if [ -n "$2" ]; then
	INSTANCE=$2
else
	INSTANCE=default
fi

if [ -r ${CONFDIR}/${INSTANCE}.conf ]; then
	source ${CONFDIR}/${INSTANCE}.conf
else
	echo "TShock could not be started because ${CONFDIR}/${INSTANCE}.conf could not be read."
	exit 1
fi

TMUX_CONSOLE=tshock-console-${INSTANCE}

case "$1" in
	start)
		if [ ! $(tmux has -t ${TMUX_CONSOLE}) ]; then
			tmux new-session -d -s ${TMUX_CONSOLE} -d "cd ${BASEDIR}; mono TerrariaServer.exe -port ${PORT} -world My\ Games/Terraria/Worlds/${WORLD}.wld"
			if [ $? -gt 0 ]; then
				exit 1
			fi
		else
			echo "Tshock already running"
			exit 1
		fi
		;;

	stop)
		tmux send-keys -t ${TMUX_CONSOLE} 'broadcast NOTICE: Server shutting down in 5 seconds!' C-m
		sleep 5
		tmux send-keys -t ${TMUX_CONSOLE} 'exit' C-m
		sleep 10
		;;

	console)
		tmux attach -t ${TMUX_CONSOLE}
		;;

	install)
		bash -c "cd ${BASEDIR}; mono TerrariaServer.exe"
		;;

	*)
		echo "usage: $0 {start|backup|console|install} [instance]"
esac

exit 0