-
-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathnetinstall.sh
More file actions
executable file
·153 lines (135 loc) · 4.75 KB
/
netinstall.sh
File metadata and controls
executable file
·153 lines (135 loc) · 4.75 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#
# Net Installer, used with curl
#
arkstGithubRepo="arkmanager/ark-server-tools"
steamcmd_user="$1"
shift
args=()
unstable=
userinstall=
userinstall2=
commit=
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; ;;
--commit=*) commit="${arg#--commit=}"; ;;
--tag=*)
tagname="${arg#--tag=}"
commit="$(curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/tags/${tagname}" | sed -n 's/^ *"sha": "\(.*\)",.*/\1/p')"
if [ -z "$commit" ]; then
echo "Tag ${tagname} not found"
exit 1
elif [ "$(echo "$commit" | wc -l)" -ne 1 ]; then
echo "Tag ${tagname} is matched more than one tag."
curl -s "https://api.github.com/repos/${arkstGithubRepo}/git/refs/tags/${tagname}" | sed -n 's/^ *"ref": "refs\/tags\/\(.*\)",.*/\1/p'
exit 1
fi
echo "Tag ${tagname} found at commit ${commit}"
;;
*)
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 [ -n "$commit" ]; then
doInstallFromCommit "$commit" "${args[@]}"
elif [ "$channel" = "master" ] && [ -z "$unstable" ]; then
doInstallFromRelease "${args[@]}"
else
doInstallFromBranch "$channel" "${args[@]}"
fi