-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
58 lines (46 loc) · 1.4 KB
/
run.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
#!/usr/bin/env bash
set -euo pipefail
SHARE=/home/steam/.local/share
STEAMAPP="${SHARE}/Steam/steamapps/common/Euro Truck Simulator 2 Dedicated Server"
GAMEDIR="${SHARE}/Euro Truck Simulator 2"
function install_gamedata() {
# Check if GAMEDATA_URL is set to download and install
[[ -n ${GAMEDATA_URL:-} ]] || {
log "No GAMEDATA_URL provided, skipping gamedata-install"
return 0
}
curl -sSfL "${GAMEDATA_URL}" | tar -xz -C "${GAMEDIR}"
}
function log() {
echo "[$(date +%H:%M:%S)] $@" >&2
}
function main() {
# Check for updates / do first-time installation
log "Starting game installation / update"
steamcmd +runscript /home/steam/ets2-install.txt
if ! [[ -e "${GAMEDIR}/server_config.sii" ]]; then
log "No server config found, running game for first time to generate..."
run_game || true # exit(1) is expected here
fi
install_gamedata
wait_for_gamedata
run_game
}
function run_game() {
# Execute server
log "Starting server..."
cd "${STEAMAPP}/bin/linux_x64"
export LD_LIBRARY_PATH='$ORIGIN/../../linux64'
exec ./eurotrucks2_server
}
function wait_for_gamedata() {
local backoff=1
local max_backoff=120
until [[ -e "${GAMEDIR}/server_packages.sii" ]]; do
log "server_packages.sii not found, you need to install it manually into ${GAMEDIR}"
sleep $backoff
backoff=$((backoff * 2))
[ $backoff -lt $max_backoff ] || backoff=$max_backoff
done
}
main