-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
netinstall.sh
136 lines (118 loc) · 4.02 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#
# Net Installer, used with curl
#
arkstGithubRepo="arkmanager/ark-server-tools"
steamcmd_user="$1"
shift
args=()
unstable=
userinstall=
userinstall2=
for arg in "$@"; do
case "$arg" in
--unstable) unstable=1; ;;
--repo=*) arkstGithubRepo="${arg#--repo=}"; ;;
--perform-user-install) userinstall2=yes; ;;
--yes-i-really-want-to-perform-a-user-install) userinstall=yes; ;;
*)
if [[ -n "$channel" || "$arg" == --* ]]; then
args+=("$arg")
else
channel="$arg"
fi
;;
esac
done
if [ -z "$channel" ]; then
channel="master"
fi
if [[ "$steamcmd_user" == "--me" && -z "$userinstall2" ]]; 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 want this."
exit 1
elif [[ "$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 --yes-i-really-want-to-perform-a-user-install if you really want this."
exit 1
elif [[ "$steamcmd_user" == "--me" ]]; 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 "You have been warned."
fi
function die(){
echo "$@" >&2
exit
}
function doInstallFromCommit(){
local commit="$1"
shift
tmpdir="$(mktemp -t -d "ark-server-tools-XXXXXXXX")"
if [ -z "$tmpdir" ]; then echo "Unable to create temporary directory"; exit 1; fi
cd "$tmpdir" || die "Unable to change to temporary directory"
echo "Downloading installer"
curl -s -L "https://github.com/${arkstGithubRepo}/archive/${commit}.tar.gz" | tar -xz
cd "ark-server-tools-${commit}/tools" || die "Unable to change to extracted directory"
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" "$@"
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=
echo "Getting latest release..."
# Read the variables from github
while IFS=$'\t' read -r n v; do
case "${n}" in
tag_name) tagname="${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..."
# shellcheck disable=SC2155
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"
shift
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" || die "Unable to change to temporary directory"
if [ "$channel" = "master" ] && [ -z "$unstable" ]; then
doInstallFromRelease "${args[@]}"
else
doInstallFromBranch "$channel" "${args[@]}"
fi