-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
184 lines (151 loc) · 7.8 KB
/
run.sh
File metadata and controls
184 lines (151 loc) · 7.8 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
#!/usr/bin/env bash
set -e
echo "
╔═══════════════════════════════════════════════╗
║ ║
║ _ _____________ _____ ___ ║
║ / |/ / __/_ __/ | /| / / _ | / _ \ ║
║ / / _/ / / | |/ |/ / __ |/ , _/ ║
║ /_/|_/___/ /_/ |__/|__/_/ |_/_/|_| ║
║ OFFICIAL ║
║ ║
╠═══════════════════════════════════════════════╣
║ Thanks for using our DOCKER image! Should you ║
║ have issues, please reach out or create a ║
║ github issue. Thanks! ║
║ ║
║ For more information: ║
║ github.com/netwarlan ║
╚═══════════════════════════════════════════════╝"
## Set default values if none were provided
## ==============================================
L4D2_SERVER_PORT="${L4D2_SERVER_PORT:-27015}"
L4D2_SERVER_MAXPLAYERS="${L4D2_SERVER_MAXPLAYERS:-4}"
L4D2_SERVER_MAP="${L4D2_SERVER_MAP:-c1m1_hotel}"
L4D2_SVLAN="${L4D2_SVLAN:-0}"
L4D2_SERVER_HOSTNAME="${L4D2_SERVER_HOSTNAME:-L4D2 Server}"
L4D2_SERVER_REMOTE_CFG="${L4D2_SERVER_REMOTE_CFG:-}"
L4D2_SERVER_UPDATE_ON_START="${L4D2_SERVER_UPDATE_ON_START:-true}"
L4D2_SERVER_VALIDATE_ON_START="${L4D2_SERVER_VALIDATE_ON_START:-false}"
L4D2_SERVER_UPDATE_ONLY_THEN_STOP="${L4D2_SERVER_UPDATE_ONLY_THEN_STOP:-false}"
L4D2_SERVER_VALIDATE_ONLY_THEN_STOP="${L4D2_SERVER_VALIDATE_ONLY_THEN_STOP:-false}"
L4D2_SERVER_CONFIG="${L4D2_SERVER_CONFIG:-server.cfg}"
## Format password variables for config file
[[ -n "$L4D2_SERVER_PW" ]] && L4D2_SERVER_PW="sv_password $L4D2_SERVER_PW"
[[ -n "$L4D2_SERVER_RCONPW" ]] && L4D2_SERVER_RCONPW="rcon_password $L4D2_SERVER_RCONPW"
## Validate numeric inputs
if [[ ! "$L4D2_SERVER_PORT" =~ ^[0-9]+$ ]]; then
echo "Error: L4D2_SERVER_PORT must be a valid number"
exit 1
fi
if [[ ! "$L4D2_SERVER_MAXPLAYERS" =~ ^[0-9]+$ ]]; then
echo "Error: L4D2_SERVER_MAXPLAYERS must be a valid number"
exit 1
fi
## Download game files only (without starting server)
## ==============================================
if [[ "$L4D2_SERVER_UPDATE_ONLY_THEN_STOP" = true ]] || [[ "$L4D2_SERVER_VALIDATE_ONLY_THEN_STOP" = true ]]; then
echo "
╔═══════════════════════════════════════════════╗
║ Downloading game files only ║
╚═══════════════════════════════════════════════╝"
if [[ "$L4D2_SERVER_VALIDATE_ONLY_THEN_STOP" = true ]]; then
VALIDATE_FLAG='validate'
else
VALIDATE_FLAG=''
fi
## Workaround: https://github.com/ValveSoftware/steam-for-linux/issues/11522
## Download with windows platform, then re-run with linux to get correct binaries
"$STEAMCMD_DIR/steamcmd.sh" \
+@sSteamCmdForcePlatformType windows \
+force_install_dir "$GAME_DIR" \
+login "$STEAMCMD_USER" "$STEAMCMD_PASSWORD" "$STEAMCMD_AUTH_CODE" \
+app_update "$STEAMCMD_APP" \
+quit
"$STEAMCMD_DIR/steamcmd.sh" \
+@sSteamCmdForcePlatformType linux \
+force_install_dir "$GAME_DIR" \
+login "$STEAMCMD_USER" "$STEAMCMD_PASSWORD" "$STEAMCMD_AUTH_CODE" \
+app_update "$STEAMCMD_APP" $VALIDATE_FLAG \
+quit
echo "
╔═══════════════════════════════════════════════╗
║ Game files downloaded. Stopping container. ║
╚═══════════════════════════════════════════════╝"
exit 0
fi
## Update on startup
## ==============================================
if [[ "$L4D2_SERVER_UPDATE_ON_START" = true ]] || [[ "$L4D2_SERVER_VALIDATE_ON_START" = true ]]; then
echo "
╔═══════════════════════════════════════════════╗
║ Checking for updates ║
╚═══════════════════════════════════════════════╝"
if [[ "$L4D2_SERVER_VALIDATE_ON_START" = true ]]; then
VALIDATE_FLAG='validate'
else
VALIDATE_FLAG=''
fi
## Workaround: https://github.com/ValveSoftware/steam-for-linux/issues/11522
## Download with windows platform, then re-run with linux to get correct binaries
"$STEAMCMD_DIR/steamcmd.sh" \
+@sSteamCmdForcePlatformType windows \
+force_install_dir "$GAME_DIR" \
+login "$STEAMCMD_USER" "$STEAMCMD_PASSWORD" "$STEAMCMD_AUTH_CODE" \
+app_update "$STEAMCMD_APP" \
+quit
"$STEAMCMD_DIR/steamcmd.sh" \
+@sSteamCmdForcePlatformType linux \
+force_install_dir "$GAME_DIR" \
+login "$STEAMCMD_USER" "$STEAMCMD_PASSWORD" "$STEAMCMD_AUTH_CODE" \
+app_update "$STEAMCMD_APP" $VALIDATE_FLAG \
+quit
fi
## Build server config
## ==============================================
echo "
╔═══════════════════════════════════════════════╗
║ Building server config ║
╚═══════════════════════════════════════════════╝"
cat <<EOF > "${GAME_DIR}/left4dead2/cfg/$L4D2_SERVER_CONFIG"
// Values passed from Docker environment
$L4D2_SERVER_PW
$L4D2_SERVER_RCONPW
host_name_store 1
host_info_show 1
host_players_show 2
EOF
## Download config if needed
## ==============================================
if [[ -n "$L4D2_SERVER_REMOTE_CFG" ]]; then
echo "
╔═══════════════════════════════════════════════╗
║ Downloading remote config ║
╚═══════════════════════════════════════════════╝"
echo " Downloading config..."
L4D2_SERVER_CONFIG=$(basename "$L4D2_SERVER_REMOTE_CFG")
curl --silent -O --output-dir "$GAME_DIR/left4dead2/cfg/" "$L4D2_SERVER_REMOTE_CFG"
echo " Setting $L4D2_SERVER_CONFIG as our server exec"
chmod 770 "$GAME_DIR/left4dead2/cfg/$L4D2_SERVER_CONFIG"
fi
## Print Variables
## ==============================================
echo "
╔═══════════════════════════════════════════════╗
║ Server set with provided values ║
╚═══════════════════════════════════════════════╝"
printenv | grep L4D2 || true
## Run
## ==============================================
echo "
╔═══════════════════════════════════════════════╗
║ Starting server ║
╚═══════════════════════════════════════════════╝"
## Escaped double quotes help to ensure hostnames with spaces are kept intact
"$GAME_DIR/srcds_run" -game left4dead2 -console -usercon \
+hostname \"${L4D2_SERVER_HOSTNAME}\" \
+exec "$L4D2_SERVER_CONFIG" \
+port "$L4D2_SERVER_PORT" \
+maxplayers "$L4D2_SERVER_MAXPLAYERS" \
+map "$L4D2_SERVER_MAP" \
+sv_lan "$L4D2_SVLAN"