-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstartscript.sh
More file actions
236 lines (203 loc) · 7.42 KB
/
startscript.sh
File metadata and controls
236 lines (203 loc) · 7.42 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
############################################################################
# #
# Source Server Script #
# #
# Author: #
# Ulrich Block #
# #
# Kontakt: #
# ich@ulrich-block.de #
# www.ulrich-block.de #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see http://www.gnu.org/licenses/ #
# #
# Gebrauch: ./startscript.sh {start|stop|restart|update|console|check} #
# #
# start/restart/stop: Server starten/stoppen/neustarten #
# #
# update: Mit der SteamCMD den Server aktualisieren #
# #
# console: Wechselt auf die Source Server Konsole #
# Mit 'strg + a + d' die Konsole wieder in den Hintergrund schicken #
# #
############################################################################
# Absoluter Pfad zum Server
DIR="/Verzeichnis/zum/Server"
# Startscript des Servers
DEAMON="srcds_run"
# Externe IP unter der der Server erreichbar sein soll
IP="Die.IP.vom.Server"
# Port auf den der Server lauschen soll
PORT="PortvomServer"
# Client Port des Servers
CLIENTPORT="28000"
# Source TV aktivieren
SOURCETV="1"
# Falls SourceTV genutzt wird, wird der SourceTV Server auf diesem Port gestartet
SOURCETVPORT="29000"
# Slot Anzahl
MPLAYERS="20"
# Startmap
MAP="de_dust2"
# Team Fortress 2 - tf
# Counter-Strike: Source - cstrike
# Counter-Strike: Global Offensive - csgo
# Day of Defeat: Source - dod
# Left 4 Dead 2 - left4dead2
# Half Life 2: Deathmatch - hl2mp
GAME="csgo"
# Sollte GAME="CSGO" sein
if [ "$GAME" == "csgo" ]; then
# Dieser Teil ist nur fuer CS:GO
GAMETYPE=0
GAMEMODE=1
MAPGROUP="mg_bomb"
TICK=66
CSGO="-tickrate $TICK +game_type $GAMETYPE +game_mode $GAMEMODE +mapgroup $MAPGROUP "
# Sollte GAME="CSGO" nicht sein
else
CSGO=""
fi
PARAMS="-game $GAME -ip $IP -port $PORT +tv_port $SOURCETVPORT +clientport $CLIENTPORT +maxplayers $MPLAYERS +map $MAP +tv_enable $SOURCETV $CSGO"
SCREENNAME="css"
function init {
if [ "`whoami`" = "root" ]; then
echo "Verantwortungsvolle Admins starten Gameserver nicht mit root! Allen anderen ist es untersagt!"
exit 0
fi
if [ -z "$DIR" ]; then
echo "Es wurde nichts bei der Variable DIR angegeben."
exit 0
fi
if [ -z "$DEAMON" ]; then
echo "Es wurde nichts bei der Variable DEAMON angegeben."
exit 0
fi
if [ -z "$PARAMS" ]; then
echo "Es wurde nichts bei der Variable PARAMS angegeben."
exit 0
fi
if [ -z "$SCREENNAME" ]; then
echo "Es wurde nichts bei der Variable SCREENNAME angegeben."
exit 0
fi
if [ -z "$IP" ]; then
echo "Es wurde nichts bei der Variable IP angegeben."
exit 0
fi
if [ -z "$PORT" ]; then
echo "Es wurde nichts bei der Variable PORT angegeben."
exit 0
fi
}
function start_server {
if [[ `screen -ls | grep $SCREENNAME` ]]; then
echo "Der Server laeuft bereits unter dem Screentab $SCREENNAME"
else
echo "Starte $SCREENNAME"
if [ -d $DIR ]; then
cd $DIR
screen -d -m -S $SCREENNAME ./$DEAMON $PARAMS
else
echo "Das Serververzeichnis wurde nicht angegeben"
fi
fi
}
function stop_server {
if [[ `screen -ls | grep $SCREENNAME` ]]; then
echo -n "Stoppe $SCREENNAME"
kill `screen -ls | grep $SCREENNAME | awk -F . '{print $1}'| awk '{print $1}'`
echo " ... done."
else
echo "Konnte den Screentab $SCREENNAME nicht finden"
fi
}
function update_server {
if [ -f ~/steamcmd.sh ]; then
stop_server
echo "Update"
cd
if [ "$GAME" == "csgo" ]; then
./steamcmd.sh +login anonymous +app_update 740 +force_install_dir $DIR validate +quit
elif [ "$GAME" == "cstrike" ]; then
./steamcmd.sh +login anonymous +app_update 232330 +force_install_dir $DIR validate +quit
elif [ "$GAME" == "tf" ]; then
./steamcmd.sh +login anonymous +app_update 232250 +force_install_dir $DIR validate +quit
elif [ "$GAME" == "dod" ]; then
./steamcmd.sh +login anonymous +app_update 232290 +force_install_dir $DIR validate +quit
elif [ "$GAME" == "left4dead2" ]; then
./steamcmd.sh +login anonymous +app_update 222860 +force_install_dir $DIR validate +quit
elif [ "$GAME" == "hl2mp" ]; then
./steamcmd.sh +login anonymous +app_update 232370 +force_install_dir $DIR validate +quit
else
echo "Falscher Wert fuer die Variable GAME!"
fi
start_server
else
echo "Konnte die Datei steamcmd.sh nicht im Homeverzeichnis finden!"
fi
}
function wrong_input {
echo "Usage: $0 {start|stop|restart|update|console|check}"
exit 1
}
function get_screen {
screen -r $SCREENNAME
}
# Veraltet:
#function check_ping {
# if [ "`/usr/bin/quakestat -a2s $IP:$PORT | grep -v ADDRESS | awk '{ print $2 }' | awk -F/ ' { print $1}'`" = "DOWN" ]; then
# sleep 10
# if [ "`/usr/bin/quakestat -a2s $IP:$PORT | grep -v ADDRESS | awk '{ print $2 }' | awk -F/ ' { print $1}'`" = "DOWN" ]; then
# stop_server
# start_server
# fi
# fi
#}
function check_ping {
if [[ "`printf '\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00' | netcat -u -w 1 $IP $PORT`" == "" ]]; then
sleep 10
if [[ "`printf '\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00' | netcat -u -w 1 $IP $PORT`" == "" ]]; then
stop_server
start_server
fi
fi
}
init
case "$1" in
start)
start_server
;;
stop)
stop_server
;;
restart)
stop_server
start_server
;;
update)
update_server
;;
console)
get_screen
;;
check)
check_ping
;;
*)
wrong_input
;;
esac
exit 0