-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·61 lines (46 loc) · 1.47 KB
/
entrypoint.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
#!/usr/bin/env bash
# The openttd content directory changes if the -c option is supplied.
# Without -c option, the content directory is ~/.local/share/openttd,
# with -c option, the content directory is the directory containing the loaded cfg.
# As workaround, we always supply the -c option, using a default config file if no custom config is present.
set -o errexit
set -o pipefail
log() {
echo >&2 "$*"
}
content="/data"
addgroup --gid "${PGID}" --system openttd &>/dev/null
adduser --uid "${PUID}" --system --ingroup openttd --disabled-password --home "$content" openttd &>/dev/null
cd "$content"
# openttd option arguments
args=()
# container args
if [[ $# -gt 0 ]]; then
args+=("$*")
fi
# dedicated server mode
args+=("-D0.0.0.0:3979")
if [[ ! -f "openttd.cfg" ]]; then
log "Creating empty config"
touch ./openttd.cfg
fi
args+=("-c openttd.cfg")
if [[ -n $LOAD_AUTOSAVE ]]; then
# shellcheck disable=SC2010 # ls sort by time
latest_savegame=$(ls -t "save/autosave/" 2>/dev/null | grep -E "autosave[0-9]+.sav" | head -1)
if [[ -n "$latest_savegame" ]]; then
save_file="save/autosave/$latest_savegame"
else
log "No autosave found!"
fi
fi
if [[ -z $save_file && -f save/template.sav ]]; then
save_file="save/template.sav"
fi
if [[ -n $save_file ]]; then
log "Loading save: $save_file"
args+=("-g $save_file")
fi
chown -R openttd:openttd "$content"
log "Starting server with options: ${args[*]}"
sudo -u openttd sh -c "/opt/openttd/openttd ${args[*]}"