forked from pterodactyl-installer/pterodactyl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-daemon.sh
executable file
·311 lines (262 loc) · 7.39 KB
/
install-daemon.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
###########################################################
# pterodactyl-installer for daemon
# Copyright Vilhelm Prytz 2018-2019
#
# https://github.com/VilhelmPrytz/pterodactyl-installer
###########################################################
# check if user is root or not
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with root privileges (sudo)." 1>&2
exit 1
fi
# check for curl
CURLPATH="$(which curl)"
if [ -z "$CURLPATH" ]; then
echo "* curl is required in order for this script to work."
echo "* install using apt on Debian/Ubuntu or yum on CentOS"
exit 1
fi
# check for python
PYTHONPATH="$(which python)"
if [ -z "$PYTHONPATH" ]; then
echo "* python is required in order for this script to work."
echo "* install using apt on Debian/Ubuntu or yum on CentOS"
exit 1
fi
# define version using information from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
echo "* Retrieving release information.."
VERSION="$(get_latest_release "pterodactyl/daemon")"
# DL urls
DL_URL="https://github.com/pterodactyl/daemon/releases/download/$VERSION/daemon.tar.gz"
CONFIGS_URL="https://raw.githubusercontent.com/VilhelmPrytz/pterodactyl-installer/master/configs"
# variables
OS="debian"
# visual functions
function print_error {
COLOR_RED='\033[0;31m'
COLOR_NC='\033[0m'
echo ""
echo -e "* ${COLOR_RED}ERROR${COLOR_NC}: $1"
echo ""
}
function print_brake {
for ((n=0;n<$1;n++));
do
echo -n "#"
done
echo ""
}
# other functions
function detect_distro {
echo "$(python -c 'import platform ; print platform.dist()[0]')" | awk '{print tolower($0)}'
}
function detect_os_version {
echo "$(python -c 'import platform ; print platform.dist()[1].split(".")[0]')"
}
function check_os_comp {
if [ "$OS" == "ubuntu" ]; then
if [ "$OS_VERSION" == "16" ]; then
SUPPORTED=true
elif [ "$OS_VERSION" == "18" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
elif [ "$OS" == "debian" ]; then
if [ "$OS_VERSION" == "9" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
elif [ "$OS" == "centos" ]; then
if [ "$OS_VERSION" == "7" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
else
SUPPORTED=false
fi
# exit if not supported
if [ "$SUPPORTED" == true ]; then
echo "* $OS $OS_VERSION is supported."
else
echo "* $OS $OS_VERSION is not supported"
print_error "Unsupported OS"
exit 1
fi
}
############################
## INSTALLATION FUNCTIONS ##
############################
function yum_update {
yum update -y
}
function apt_update {
apt update -y
apt upgrade -y
}
function install_dep {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
apt_update
# install dependencies
apt -y install tar unzip make gcc g++ python
elif [ "$OS" == "centos" ]; then
yum_update
# install dependencies
yum -y install tar unzip make gcc
yum -y install gcc-c++
else
print_error "Invalid OS."
exit 1
fi
}
function install_docker {
echo "* Installing docker .."
if [ "$OS" == "debian" ]; then
# install dependencies for Docker
apt-get update
apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
# get their GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
# show fingerprint to user
apt-key fingerprint 0EBFCD88
# add APT repo
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
# install docker
apt-get update
apt-get -y install docker-ce
# make sure it's enabled & running
systemctl start docker
systemctl enable docker
elif [ "$OS" == "ubuntu" ]; then
# install dependencies for Docker
apt-get update
apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# get their GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# show fingerprint to user
apt-key fingerprint 0EBFCD88
# add APT repo
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# install docker
apt-get update
apt-get -y install docker-ce
# make sure it's enabled & running
systemctl start docker
systemctl enable docker
elif [ "$OS" == "centos" ]; then
# install dependencies for Docker
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
# add repo to yum
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# install Docker
yum install -y docker-ce
# make sure it's enabled & running
systemctl start docker
systemctl enable docker
fi
echo "* Docker has now been installed."
}
function install_nodejs {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt -y install nodejs
elif [ "$OS" == "centos" ]; then
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum -y install nodejs
fi
}
function ptdl_dl {
echo "* Installing pterodactyl daemon .. "
mkdir -p /srv/daemon /srv/daemon-data
cd /srv/daemon
curl -L $DL_URL | tar --strip-components=1 -xzv
npm install --only=production
echo "* Done."
}
function systemd_file {
echo "* Installing systemd service.."
curl -o /etc/systemd/system/wings.service $CONFIGS_URL/wings.service
systemctl daemon-reload
systemctl enable wings
echo "* Installed systemd service!"
}
####################
## MAIN FUNCTIONS ##
####################
function perform_install {
echo "* Installing pterodactyl daemon.."
install_dep
install_docker
install_nodejs
ptdl_dl
systemd_file
}
function main {
print_brake 42
echo "* Pterodactyl daemon installation script "
echo "* Detecting operating system."
OS=$(detect_distro);
OS_VERSION=$(detect_os_version);
echo "* Running $OS version $OS_VERSION."
print_brake 42
# checks if the system is compatible with this installation script
check_os_comp
echo "* The installer will install Docker, required dependencies for the daemon"
echo "* as well as the daemon itself. But it is till required to create the node"
echo "* on the panel and then place the configuration on the node after the"
echo "* installation finishes. Read more here:"
echo "* https://pterodactyl.io/daemon/installing.html#configure-daemon"
print_brake 42
echo -n "* Proceed with installation? (y/n): "
read CONFIRM
if [ "$CONFIRM" == "y" ]; then
perform_install
elif [ "$CONFIRM" == "n" ]; then
exit 0
else
print_error "Invalid input"
exit 1
fi
}
function goodbye {
echo ""
print_brake 70
echo "* Installation finished."
echo ""
echo "* Make sure you create the node within the panel and then "
echo "* copy the config to the node. You may then start the daemon using "
echo "* systemctl start wings"
echo "* NOTE: It is recommended to also enable swap."
print_brake 70
echo ""
}
# run main
main
goodbye