-
Notifications
You must be signed in to change notification settings - Fork 8
/
server-install-debian12.sh
378 lines (314 loc) · 12.3 KB
/
server-install-debian12.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
#
# Install script for ARK Survival Ascended on Debian 12
#
# Uses Glorious Eggroll's build of Proton
# Please ensure to run this script as root (or at least with sudo)
#
# @LICENSE AGPLv3
# @AUTHOR Charlie Powell - [email protected]
# @SOURCE https://github.com/cdp1337/ARKSurvivalAscended-Linux
#
# F*** Nitrado
############################################
## Parameter Configuration
############################################
# https://github.com/GloriousEggroll/proton-ge-custom
PROTON_URL="https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton9-20/GE-Proton9-20.tar.gz"
PROTON_TGZ="$(basename "$PROTON_URL")"
PROTON_NAME="$(basename "$PROTON_TGZ" ".tar.gz")"
# Force installation directory for game
# steam produces varying results, sometimes in ~/.local/share/Steam, other times in ~/Steam
GAME="ArkSurvivalAscended"
GAMEDIR="/home/steam/$GAME"
STEAMDIR="/home/steam/.local/share/Steam"
# Wine/Proton compatiblity directory
COMPATDIR="$STEAMDIR/compatibilitytools.d"
# Specific "filesystem" directory for installed version of Proton
GAMECOMPATDIR="$COMPATDIR/$PROTON_NAME/files/share/default_pfx"
# Binary path for Proton
PROTONBIN="$COMPATDIR/$PROTON_NAME/proton"
# List of game maps currently available
GAMEMAPS="ark-island ark-aberration ark-club ark-scorched ark-thecenter"
############################################
## Pre-exec Checks
############################################
# Only allow running as root
if [ "$LOGNAME" != "root" ]; then
echo "Please run this script as root! (If you ran with 'su', use 'su -' instead)" >&2
exit 1
fi
# This script can run on an existing server, but should not run while the game is actively running.
if [ $(ps aux | grep ArkAscendedServer.exe | wc -l) -gt 1 ]; then
echo "It appears that the ARK server is already running, please stop it before running this script."
exit 1
fi
# Determine if this is a new installation or an upgrade (/repair)
if [ -e /etc/systemd/system/ark-island.service ]; then
INSTALLTYPE="upgrade"
else
INSTALLTYPE="new"
fi
############################################
## User Prompts (pre setup)
############################################
# Ask the user some information before installing.
echo "================================================================================"
echo " ARK Survival Ascended *unofficial* Installer"
echo ""
if [ "$INSTALLTYPE" == "new" ]; then
echo "? What is the community name of the server? (e.g. My Awesome ARK Server)"
echo -n "> "
read COMMUNITYNAME
if [ "$COMMUNITYNAME" == "" ]; then
COMMUNITYNAME="My Awesome ARK Server"
fi
fi
############################################
## Dependency Installation and Setup
############################################
# Create a "steam" user account
# This will create the account with no password, so if you need to log in with this user,
# run `sudo passwd steam` to set a password.
[ -d /home/steam ] || useradd -m -U steam
# We will use this directory as a working directory for source files that need downloaded.
[ -d /opt/game-resources ] || mkdir -p /opt/game-resources
# Preliminary requirements
dpkg --add-architecture i386
apt update
apt install -y software-properties-common apt-transport-https dirmngr ca-certificates curl wget sudo firewalld
# Enable "non-free" repos for Debian (for steamcmd)
# https://stackoverflow.com/questions/76688863/apt-add-repository-doesnt-work-on-debian-12
add-apt-repository -y -U http://deb.debian.org/debian -c non-free-firmware -c non-free
# Install steam repo
curl -s http://repo.steampowered.com/steam/archive/stable/steam.gpg > /usr/share/keyrings/steam.gpg
echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] http://repo.steampowered.com/steam/ stable steam" > /etc/apt/sources.list.d/steam.list
# Install steam binary and steamcmd
apt update
apt install -y lib32gcc-s1 steamcmd
# Grab Proton from Glorious Eggroll
if [ ! -e "/opt/game-resources/$PROTON_TGZ" ]; then
wget "$PROTON_URL" -O "/opt/game-resources/$PROTON_TGZ"
fi
# Extract GE Proton into this user's Steam path
[ -d "$COMPATDIR" ] || sudo -u steam mkdir -p "$COMPATDIR"
sudo -u steam tar -x -C "$COMPATDIR/" -f "/opt/game-resources/$PROTON_TGZ"
############################################
## Upgrade Checks
############################################
for MAP in $GAMEMAPS; do
# Ensure the override directory exists for the admin modifications to the CLI arguments.
[ -e /etc/systemd/system/${MAP}.service.d ] || mkdir -p /etc/systemd/system/${MAP}.service.d
# Release 2023.10.31 - Issue #8
if [ -e /etc/systemd/system/${MAP}.service ]; then
# Check if the service is already installed and move any modifications to the override.
# This is important for existing installs so the admin modifications to CLI arguments do not get overwritten.
if [ ! -e /etc/systemd/system/${MAP}.service.d/override.conf ]; then
# Override does not exist yet, merge in any changes in the default service file.
SERVICE_EXEC_LINE="$(grep -E '^ExecStart=' /etc/systemd/system/${MAP}.service)"
cat > /etc/systemd/system/${MAP}.service.d/override.conf <<EOF
[Service]
$SERVICE_EXEC_LINE
EOF
fi
fi
done
## End Release 2023.10.31 - Issue #8
############################################
## Game Installation
############################################
# Install ARK Survival Ascended Dedicated
sudo -u steam /usr/games/steamcmd +force_install_dir $GAMEDIR/AppFiles +login anonymous +app_update 2430930 validate +quit
# STAGING / TESTING - skip ark because it's huge; AppID 90 is Team Fortress 1 (a tiny server useful for testing)
#sudo -u steam /usr/games/steamcmd +force_install_dir $GAMEDIR/AppFiles +login anonymous +app_update 90 validate +quit
if [ $? -ne 0 ]; then
echo "Could not install ARK Survival Ascended Dedicated Server, exiting"
exit 1
fi
# Install the systemd service files for ARK Survival Ascended Dedicated Server
for MAP in $GAMEMAPS; do
# Different maps will have different settings, (to allow them to coexist on the same server)
if [ "$MAP" == "ark-island" ]; then
DESC="Island"
NAME="TheIsland_WP"
MODS=""
GAMEPORT=7701
RCONPORT=27001
elif [ "$MAP" == "ark-aberration" ]; then
DESC="Aberration"
NAME="Aberration_P"
MODS=""
GAMEPORT=7702
RCONPORT=27002
elif [ "$MAP" == "ark-club" ]; then
DESC="Club"
NAME="BobsMissions_WP"
MODS="1005639"
GAMEPORT=7703
RCONPORT=27003
elif [ "$MAP" == "ark-scorched" ]; then
DESC="Scorched"
NAME="ScorchedEarth_P"
MODS=""
GAMEPORT=7704
RCONPORT=27004
elif [ "$MAP" == "ark-thecenter" ]; then
DESC="TheCenter"
NAME="TheCenter_P"
MODS=""
GAMEPORT=7705
RCONPORT=27005
fi
# Install system service file to be loaded by systemd
cat > /etc/systemd/system/${MAP}.service <<EOF
[Unit]
Description=ARK Survival Ascended Dedicated Server (${DESC})
After=network.target
[Service]
Type=simple
LimitNOFILE=10000
User=steam
Group=steam
WorkingDirectory=$GAMEDIR/AppFiles/ShooterGame/Binaries/Win64
Environment=XDG_RUNTIME_DIR=/run/user/$(id -u)
Environment="STEAM_COMPAT_CLIENT_INSTALL_PATH=$STEAMDIR"
Environment="STEAM_COMPAT_DATA_PATH=$GAMEDIR/prefixes/$MAP"
# Check $GAMEDIR/services to adjust the CLI arguments
Restart=on-failure
RestartSec=20s
[Install]
WantedBy=multi-user.target
EOF
if [ ! -e /etc/systemd/system/${MAP}.service.d/override.conf ]; then
# Override does not exist yet, create boilerplate file.
# This is the main file that the admin will use to modify CLI arguments,
# so we do not want to overwrite their work if they have already modified it.
cat > /etc/systemd/system/${MAP}.service.d/override.conf <<EOF
[Service]
# Edit this line to adjust start parameters of the server
# After modifying, please remember to run `sudo systemctl daemon-reload` to apply changes to the system.
ExecStart=$PROTONBIN run ArkAscendedServer.exe ${NAME}?listen?SessionName="${COMMUNITYNAME} (${DESC})"?RCONPort=${RCONPORT} -port=${GAMEPORT} -servergamelog -mods=$MODS
EOF
fi
# Set the owner of the override to steam so that user account can modify it.
chown steam:steam /etc/systemd/system/${MAP}.service.d/override.conf
if [ ! -e $GAMEDIR/prefixes/$MAP ]; then
# Install a new prefix for this specific map
# Proton 9 seems to have issues with launching multiple binaries in the same prefix.
[ -d $GAMEDIR/prefixes ] || sudo -u steam mkdir -p $GAMEDIR/prefixes
sudo -u steam cp $GAMECOMPATDIR $GAMEDIR/prefixes/$MAP -r
fi
done
# Create start/stop helpers for all maps
cat > $GAMEDIR/start_all.sh <<EOF
#!/bin/bash
#
# Start all ARK server maps that are enabled
GAMEMAPS="$GAMEMAPS"
function start_game {
echo "Starting game instance \$1..."
sudo systemctl start \$1
echo "Waiting 60 seconds for threads to start"
for i in {0..9}; do
sleep 6
echo -n '.'
done
# Check status real quick
sudo systemctl status \$1 | grep Active
}
function update_game {
echo "Running game update"
sudo -u steam /usr/games/steamcmd +force_install_dir $GAMEDIR/AppFiles +login anonymous +app_update 2430930 validate +quit
if [ \$? -ne 0 ]; then
echo "Game update failed, not starting"
exit 1
fi
}
if [ \$(ps aux | grep ArkAscendedServer.exe | wc -l) -le 1 ]; then
update_game
else
echo "Game server is already running, not updating"
fi
for MAP in \$GAMEMAPS; do
if [ "\$(systemctl is-enabled \$MAP)" == "enabled" -a "\$(systemctl is-active \$MAP)" == "inactive" ]; then
start_game \$MAP
fi
done
EOF
chown steam:steam $GAMEDIR/start_all.sh
chmod +x $GAMEDIR/start_all.sh
cat > $GAMEDIR/stop_all.sh <<EOF
#!/bin/bash
#
# Stop all ARK server maps that are enabled
GAMEMAPS="$GAMEMAPS"
function stop_game {
echo "Stopping game instance \$1..."
sudo systemctl stop \$1
echo "Waiting 10 seconds for threads to settle"
for i in {0..9}; do
echo -n '.'
done
# Check status real quick
sudo systemctl status \$1 | grep Active
}
for MAP in \$GAMEMAPS; do
if [ "\$(systemctl is-enabled \$MAP)" == "enabled" -a "\$(systemctl is-active \$MAP)" == "active" ]; then
stop_game \$MAP
fi
done
EOF
chown steam:steam $GAMEDIR/stop_all.sh
chmod +x $GAMEDIR/stop_all.sh
# Reload systemd to pick up the new service files
systemctl daemon-reload
############################################
## Security Configuration
############################################
# Configure firewall
[ -d "/etc/firewalld/services" ] || mkdir -p /etc/firewalld/services
cat > /etc/firewalld/services/ark-survival.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>ARK Survival Ascended</short>
<description>ARK Survival Ascended game server</description>
<port port="7701-7720" protocol="udp"/>
<port port="27001-27020" protocol="tcp"/>
</service>
EOF
firewall-cmd --permanent --zone=public --add-service=ark-survival
############################################
## Post-Install Configuration
############################################
# Create some helpful links for the user.
[ -e "$GAMEDIR/services" ] || sudo -u steam mkdir -p "$GAMEDIR/services"
for MAP in $GAMEMAPS; do
[ -h "$GAMEDIR/services/${MAP}.conf" ] || sudo -u steam ln -s /etc/systemd/system/${MAP}.service.d/override.conf "$GAMEDIR/services/${MAP}.conf"
done
[ -h "$GAMEDIR/GameUserSettings.ini" ] || sudo -u steam ln -s $GAMEDIR/AppFiles/ShooterGame/Saved/Config/WindowsServer/GameUserSettings.ini "$GAMEDIR/GameUserSettings.ini"
[ -h "$GAMEDIR/Game.ini" ] || sudo -u steam ln -s $GAMEDIR/AppFiles/ShooterGame/Saved/Config/WindowsServer/Game.ini "$GAMEDIR/Game.ini"
[ -h "$GAMEDIR/ShooterGame.log" ] || sudo -u steam ln -s $GAMEDIR/AppFiles/ShooterGame/Saved/Logs/ShooterGame.log "$GAMEDIR/ShooterGame.log"
echo "================================================================================"
echo "If everything went well, ARK Survival Ascended should be installed!"
echo ""
for MAP in $GAMEMAPS; do
echo "? Enable game map ${MAP}? (y/N)"
echo -n "> "
read OPT
if [ "$OPT" == "y" -o "$OPT" == "Y" ]; then
systemctl enable $MAP
else
echo "Not enabling ${MAP}, you can always enable it in the future with 'sudo systemctl enable $MAP'"
fi
echo ""
done
echo ""
echo "To restart a map: sudo systemctl restart NAME-OF-MAP"
echo "To start a map: sudo systemctl start NAME-OF-MAP"
echo "To stop a map: sudo systemctl stop NAME-OF-MAP"
echo "Game files: $GAMEDIR/AppFiles/"
echo "Runtime configuration: $GAMEDIR/services/"
echo "Game log: $GAMEDIR/ShooterGame.log"
echo "Game user settings: $GAMEDIR/GameUserSettings.ini"
echo "To start all maps: $GAMEDIR/start_all.sh"
echo "To stop all maps: $GAMEDIR/stop_all.sh"