forked from arkmanager/ark-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netinstall.sh
119 lines (102 loc) · 3.08 KB
/
netinstall.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
#!/bin/bash
#
# Net Installer, used with curl
#
arkstGithubRepo="FezVrasta/ark-server-tools"
steamcmd_user="$1"
shift
args=()
output=/dev/null
unstable=
userinstall=
for arg in "$@"; do
case "$arg" in
--verbose) output=/dev/fd/1; ;;
--output=*) output="${1#--output=}"; ;;
--unstable) unstable=1; ;;
--perform-user-install) userinstall=yes; ;;
*)
if [ -n "$channel" ]; then
args+="$arg"
else
channel="$arg"
fi
;;
esac
done
if [ -z "$channel" ]; then
channel="master"
fi
if [[ "$steamcmd_user" == "--me" && -z "$userinstall" ]]; then
echo "You have requested a user-install. You probably don't want this."
echo "A user-install will create ~/.config/arkmanager/instances/main.cfg"
echo "This config file will override /etc/arkmanager/instances/main.cfg"
echo "Add --perform-user-install if you really want this."
exit 1
fi
function doInstallFromCommit(){
local commit="$1"
tmpdir="$(mktemp -t -d "ark-server-tools-XXXXXXXX")"
if [ -z "$tmpdir" ]; then echo "Unable to create temporary directory"; exit 1; fi
cd "$tmpdir"
echo "Downloading installer"
curl -s -L "https://github.com/${arkstGithubRepo}/archive/${commit}.tar.gz" | tar -xz
cd "ark-server-tools-${commit}/tools"
if [ ! -f "install.sh" ]; then echo "install.sh not found in $PWD"; exit 1; fi
sed -i -e "s|^arkstCommit='.*'|arkstCommit='${commit}'|" \
-e "s|^arkstTag='.*'|arkstTag='${tagname}'|" \
arkmanager
echo "Running install.sh"
bash install.sh "$steamcmd_user" "${reinstall_args[@]}"
result=$?
cd /
rm -rf "$tmpdir"
if [ "$result" = 0 ] || [ "$result" = 2 ]; then
echo "ARK Server Tools successfully installed"
else
echo "ARK Server Tools install failed"
fi
return $result
}
function doInstallFromRelease(){
local tagname=
local desc=
echo "Getting latest release..."
# Read the variables from github
while IFS=$'\t' read n v; do
case "${n}" in
tag_name) tagname="${v}"; ;;
body) desc="${v}"
esac
done < <(curl -s "https://api.github.com/repos/${arkstGithubRepo}/releases/latest" | sed -n 's/^ "\([^"]*\)": "*\([^"]*\)"*,*/\1\t\2/p')
if [ -n "$tagname" ]; then
echo "Latest release is ${tagname}"
echo "Getting commit for latest release..."
local commit="$(curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/tags/${tagname}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p')"
doInstallFromCommit "$commit"
else
echo "Unable to get latest release"
return 1
fi
}
function doInstallFromBranch(){
channel="$1"
commit="`curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/heads/${channel}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p'`"
if [ -z "$commit" ]; then
if [ -n "$unstable" ]; then
echo "Channel ${channel} not found - trying master"
doInstallFromBranch master
else
doInstallFromRelease
fi
else
doInstallFromCommit "$commit"
fi
}
# Download and untar installation files
cd "$TEMP"
if [ "$channel" = "master" ] && [ -z "$unstable" ]; then
doInstallFromRelease
else
doInstallFromBranch "$channel"
fi