-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
123 lines (104 loc) · 2.99 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
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
#!/bin/bash
AST_VERSION="${AST_VERSION:-v1.6.33}"
CONFIG_BOOTSTRAP_DIR=/bootstrap
declare -A CONFIG_PATHS;CONFIG_PATHS[".arkmanager.cfg"]="/home/steam/.arkmanager.cfg"
CONFIG_PATHS["main.cfg"]="/home/steam/.config/arkmanager/instances/main.cfg"
CONFIG_PATHS["GameUserSettings.ini"]="/home/steam/ARK/ShooterGame/Saved/Config/LinuxServer/GameUserSettings.ini"
CONFIG_PATHS["Game.ini"]="/home/steam/ARK/ShooterGame/Saved/Config/LinuxServer/Game.ini"
CONFIG_PATHS["Engine.ini"]="/home/steam/ARK/ShooterGame/Saved/LinuxServer/Engine.ini"
isASTInstalled() {
[ "$(which arkmanager)" = "/home/steam/bin/arkmanager" ]
}
isASTVersionSameAs() {
local version=$1
echo "${version}" | grep -q "^v$(arkmanager --version | grep Version | awk '{print $2}')"
}
installAST() {
local version=$1
local tempdir=$(mktemp -d)
if [ -z "${tempdir}" ]; then
>&2 echo "ERROR: Couldn't create temp directory"
exit 1
fi
cd "${tempdir}"
curl -LO https://github.com/FezVrasta/ark-server-tools/archive/${version}.zip
unzip "${version}.zip"
cd ark-server-tools-*/tools
./install.sh --me
cd ~steam && rm -rf "${tempdir}"
}
bootstrapConfig() {
local bootstrap_dir=$1
local dest_path=
for file in $(find ${bootstrap_dir} -maxdepth 1 -type f); do
dest_path="${CONFIG_PATHS[$(basename "$file")]}"
([ -f "${file}" ] && [ -n "${dest_path}" ]) || continue
mkdir -p $(dirname ${dest_path})
cp ${file} ${dest_path}
ls -al $file
ls -al $dest_path
done
}
isARKInstalled() {
[ -f "/home/steam/ARK/steamapps/appmanifest_376030.acf" ]
}
mustBeSteamUser() {
if [ $(whoami) != 'steam' ]; then
>2& echo "ERROR: Must run as steam user."
exit 1
fi
}
areModsInstalled() {
! arkmanager getpid 2>1 | grep -q 'install this mod'
}
checkForUpdates() {
mustBeSteamUser
arkmanager update --saveworld --update-mods --verbose --no-autostart --backup
}
trapSignals() {
ripInPeace() {
echo "Initializing graceful termination."
arkmanager stop --saveworld
exit 0
}
trap ripInPeace INT TERM
}
arkManager() {
mustBeSteamUser
if ! (isASTInstalled && isASTVersionSameAs "${AST_VERSION}"); then
installAST "${AST_VERSION}"
fi
if [ -d "${CONFIG_BOOTSTRAP_DIR}" ]; then
bootstrapConfig "${CONFIG_BOOTSTRAP_DIR}"
fi
if ! isARKInstalled; then
arkmanager install --verbose
checkForUpdates
fi
if ! areModsInstalled; then
arkmanager installmods --verbose
fi
if [ -n "$1" ]; then
echo "Executing: arkmanager $@"
trapSignals
arkmanager $@ &
wait "$!"
else
echo "No arkmanager command. Idling indefinitely."
sleep infinity
fi
}
main() {
case $1 in
doUpdate)
checkForUpdates
;;
bash)
exec /bin/bash
;;
*)
arkManager $@
;;
esac
}
main $@