-
Notifications
You must be signed in to change notification settings - Fork 28
/
server.sh
executable file
·230 lines (181 loc) · 5.5 KB
/
server.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
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
#!/bin/bash
set -e
if [ "${DEBUG}" = "true" ]; then
set -x
fi
shopt -s extglob
steam_dir="${HOME}/Steam"
server_dir="${HOME}/server"
server_installed_lock_file="${server_dir}/installed.lock"
csgo_dir="${server_dir}/csgo"
csgo_custom_files_dir="${CSGO_CUSTOM_FILES_DIR-"/usr/csgo"}"
install() {
echo '> Installing server ...'
set -x
$steam_dir/steamcmd.sh \
+force_install_dir $server_dir \
+login anonymous \
+app_update 740 validate \
+quit
set +x
echo '> Done'
touch $server_installed_lock_file
}
sync_custom_files() {
echo "> Checking for custom files at \"$csgo_custom_files_dir\" ..."
if [ -d "$csgo_custom_files_dir" ]; then
echo "> Found custom files. Syncing with \"${csgo_dir}\" ..."
set -x
cp -asf $csgo_custom_files_dir/* $csgo_dir # Copy custom files as soft links
find $csgo_dir -xtype l -delete # Find and delete broken soft links
set +x
echo '> Done'
else
echo '> No custom files found'
fi
}
should_add_server_configs() {
if [ "${SERVER_CONFIGS-"false"}" = "true" ]; then
cd $csgo_dir
version="${SERVER_CONFIGS_VERSION-"1.1.0"}"
server_configs_url="https://github.com/timche/csgo-server-configs/releases/download/v${version}/csgo-server-configs-${version}.zip"
if [ ! -f "server_configs" ]; then
touch "server_configs"
fi
installed=$(< server_configs)
if [ "${installed}" != "${server_configs_url}" ] || [ "${VALIDATE_SERVER_FILES-"false"}" = "true" ]; then
wget -q -O server_configs.zip $server_configs_url
unzip -qo server_configs.zip
rm server_configs.zip
echo $server_configs_url > "server_configs"
fi
fi
}
should_disable_bots() {
cd $csgo_dir
if [ "${CSGO_DISABLE_BOTS-"false"}" = "true" ]; then
if [ -f "botchatter.db" ]; then
mv "botchatter.db" "botchatter.disabled.db"
fi
if [ -f "botprofilecoop.db" ]; then
mv "botprofilecoop.db" "botprofilecoop.disabled.db"
fi
if [ -f "botprofile.db" ]; then
mv "botprofile.db" "botprofile.disabled.db"
fi
else
if [ -f "botchatter.disabled.db" ]; then
mv "botchatter.disabled.db" "botchatter.db"
fi
if [ -f "botprofilecoop.disabled.db" ]; then
mv "botprofilecoop.disabled.db" "botprofilecoop.db"
fi
if [ -f "botprofile.disabled.db" ]; then
mv "botprofile.disabled.db" "botprofile.db"
fi
fi
}
start() {
echo '> Starting server ...'
additionalParams=""
if [ -n "$CSGO_GSLT" ]; then
additionalParams+=" +sv_setsteamaccount $CSGO_GSLT"
else
echo '> Warning: Environment variable "CSGO_GSLT" is not set, but is required to run the server on the internet. Running the server in LAN mode instead.'
additionalParams+=" +sv_lan 1"
fi
if [ -n "$CSGO_PW" ]; then
additionalParams+=" +sv_password $CSGO_PW"
fi
if [ -n "$CSGO_HOSTNAME" ]; then
additionalParams+=" +hostname $CSGO_HOSTNAME"
additionalParams+=
fi
if [ -n "$CSGO_WS_API_KEY" ]; then
additionalParams+=" -authkey $CSGO_WS_API_KEY"
fi
if [ "${CSGO_FORCE_NETSETTINGS-"false"}" = "true" ]; then
additionalParams+=" +sv_minrate 786432 +sv_mincmdrate 128 +sv_minupdaterate 128"
fi
if [ "${CSGO_TV_ENABLE-"false"}" = "true" ]; then
additionalParams+=" +tv_enable 1"
additionalParams+=" +tv_delaymapchange ${CSGO_TV_DELAYMAPCHANGE-1}"
additionalParams+=" +tv_delay ${CSGO_TV_DELAY-45}"
additionalParams+=" +tv_deltacache ${CSGO_TV_DELTACACHE-2}"
additionalParams+=" +tv_dispatchmode ${CSGO_TV_DISPATCHMODE-1}"
additionalParams+=" +tv_maxclients ${CSGO_TV_MAXCLIENTS-10}"
additionalParams+=" +tv_maxrate ${CSGO_TV_MAXRATE-0}"
additionalParams+=" +tv_overridemaster ${CSGO_TV_OVERRIDEMASTER-0}"
additionalParams+=" +tv_snapshotrate ${CSGO_TV_SNAPSHOTRATE-128}"
additionalParams+=" +tv_timeout ${CSGO_TV_TIMEOUT-60}"
additionalParams+=" +tv_transmitall ${CSGO_TV_TRANSMITALL-1}"
if [ -n "${CSGO_TV_NAME}" ]; then
additionalParams+=" +tv_name ${CSGO_TV_NAME}"
fi
if [ -n "${CSGO_TV_PORT}" ]; then
additionalParams+=" +tv_port ${CSGO_TV_PORT}"
fi
if [ -n "${CSGO_TV_PASSWORD}" ]; then
additionalParams+=" +tv_password ${CSGO_TV_PASSWORD}"
fi
fi
set -x
exec $server_dir/srcds_run \
-game csgo \
-console \
-norestart \
-usercon \
-nobreakpad \
+ip "${CSGO_IP-0.0.0.0}" \
-port "${CSGO_PORT-27015}" \
-tickrate "${CSGO_TICKRATE-128}" \
-maxplayers_override "${CSGO_MAX_PLAYERS-16}" \
+game_type "${CSGO_GAME_TYPE-0}" \
+game_mode "${CSGO_GAME_MODE-1}" \
+mapgroup "${CSGO_MAP_GROUP-mg_active}" \
+map "${CSGO_MAP-de_dust2}" \
+rcon_password "${CSGO_RCON_PW-changeme}" \
$additionalParams \
$CSGO_PARAMS
}
update() {
if [ "${VALIDATE_SERVER_FILES-"false"}" = "true" ]; then
echo '> Validating server files and checking for server update ...'
else
echo '> Checking for server update ...'
fi
if [ "${VALIDATE_SERVER_FILES-"false"}" = "true" ]; then
set -x
$steam_dir/steamcmd.sh \
+force_install_dir $server_dir \
+login anonymous \
+app_update 740 validate \
+quit
set +x
else
set -x
$steam_dir/steamcmd.sh \
+force_install_dir $server_dir \
+login anonymous \
+app_update 740 \
+quit
set +x
fi
echo '> Done'
}
install_or_update() {
if [ -f "$server_installed_lock_file" ]; then
update
else
install
fi
}
if [ ! -z $1 ]; then
$1
else
install_or_update
should_add_server_configs
should_disable_bots
sync_custom_files
start
fi