forked from pterodactyl-installer/pterodactyl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-daemon.sh
executable file
·446 lines (376 loc) · 13 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/bin/bash
#############################################################################
# #
# Project 'pterodactyl-installer' for daemon #
# #
# Copyright (C) 2018 - 2020, Vilhelm Prytz, <vilhelm@prytznet.se>, et al. #
# #
# This script is licensed under the terms of the GNU GPL v3.0 license #
# https://github.com/VilhelmPrytz/pterodactyl-installer/blob/master/LICENSE #
# #
# This script is not associated with the official Pterodactyl Project. #
# https://github.com/VilhelmPrytz/pterodactyl-installer #
# #
#############################################################################
# exit with error status code if user is not root
if [[ $EUID -ne 0 ]]; then
echo "* This script must be executed with root privileges (sudo)." 1>&2
exit 1
fi
# check for curl
CURLPATH="$(command -v curl)"
if [ -z "$CURLPATH" ]; then
echo "* curl is required in order for this script to work."
echo "* install using apt (Debian and derivatives) or yum/dnf (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")"
echo "* Latest version is $VERSION"
# download URLs
DL_URL="https://github.com/pterodactyl/daemon/releases/latest/download/daemon.tar.gz"
CONFIGS_URL="https://raw.githubusercontent.com/VilhelmPrytz/pterodactyl-installer/master/configs"
COLOR_RED='\033[0;31m'
COLOR_NC='\033[0m'
INSTALL_STANDALONE_SFTP_SERVER=false
INSTALL_MARIADB=false
# visual functions
function print_error {
echo ""
echo -e "* ${COLOR_RED}ERROR${COLOR_NC}: $1"
echo ""
}
function print_warning {
COLOR_YELLOW='\033[1;33m'
COLOR_NC='\033[0m'
echo ""
echo -e "* ${COLOR_YELLOW}WARNING${COLOR_NC}: $1"
echo ""
}
function print_brake {
for ((n=0;n<$1;n++));
do
echo -n "#"
done
echo ""
}
# other functions
function detect_distro {
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$(echo "$ID" | awk '{print tolower($0)}')
OS_VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si | awk '{print tolower($0)}')
OS_VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$(echo "$DISTRIB_ID" | awk '{print tolower($0)}')
OS_VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS="debian"
OS_VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
OS="SuSE"
OS_VER="?"
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
OS="Red Hat/CentOS"
OS_VER="?"
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
OS_VER=$(uname -r)
fi
OS=$(echo "$OS" | awk '{print tolower($0)}')
OS_VER_MAJOR=$(echo "$OS_VER" | cut -d. -f1)
}
function check_os_comp {
if [ "$OS" == "ubuntu" ]; then
if [ "$OS_VER_MAJOR" == "16" ]; then
SUPPORTED=true
elif [ "$OS_VER_MAJOR" == "18" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
elif [ "$OS" == "zorin" ]; then
if [ "$OS_VER_MAJOR" == "15" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
elif [ "$OS" == "debian" ]; then
if [ "$OS_VER_MAJOR" == "9" ]; then
SUPPORTED=true
elif [ "$OS_VER_MAJOR" == "10" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
elif [ "$OS" == "centos" ]; then
if [ "$OS_VER_MAJOR" == "7" ]; then
SUPPORTED=true
elif [ "$OS_VER_MAJOR" == "8" ]; then
SUPPORTED=true
else
SUPPORTED=false
fi
else
SUPPORTED=false
fi
# exit if not supported
if [ "$SUPPORTED" == true ]; then
echo "* $OS $OS_VER is supported."
else
echo "* $OS $OS_VER is not supported"
print_error "Unsupported OS"
exit 1
fi
}
############################
## INSTALLATION FUNCTIONS ##
############################
function apt_update {
apt update -y
apt upgrade -y
}
function install_dep {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ] || [ "$OS" == "zorin" ]; then
apt_update
# install dependencies
apt -y install tar unzip make gcc g++ python
elif [ "$OS" == "centos" ]; then
if [ "$OS_VER_MAJOR" == "7" ]; then
yum -y update
# install dependencies
yum -y install tar unzip make gcc gcc-c++ python
elif [ "$OS_VER_MAJOR" == "8" ]; then
dnf -y update
# install dependencies
dnf install -y tar unzip make gcc gcc-c++ python2
alternatives --set python /usr/bin/python2
fi
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" ] || [ "$OS" == "zorin" ]; 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
if [ "$OS_VER_MAJOR" == "7" ]; 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
elif [ "$OS_VER_MAJOR" == "8" ]; then
# install dependencies for Docker
dnf install -y dnf-utils device-mapper-persistent-data lvm2
# add repo to dnf
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
# install Docker
dnf install -y docker-ce --nobest
fi
# 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" ]; then
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs
elif [ "$OS" == "ubuntu" ] || [ "$OS" == "zorin" ]; then
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt -y install nodejs
elif [ "$OS" == "centos" ]; then
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
if [ "$OS_VER_MAJOR" == "7" ]; then
yum -y install nodejs
elif [ "$OS_VER_MAJOR" == "8" ]; then
dnf -y install nodejs
fi
fi
}
function ptdl_dl {
echo "* Installing pterodactyl daemon .. "
mkdir -p /srv/daemon /srv/daemon-data
cd /srv/daemon || exit
curl -L "$DL_URL" | tar --strip-components=1 -xzv
npm install --only=production --unsafe-perm
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!"
}
function install_standalone_sftp_server {
echo "* Installing standalone SFTP server.."
INSTALL_PATH="/srv/daemon/sftp-server"
curl -Lo $INSTALL_PATH https://github.com/pterodactyl/sftp-server/releases/download/v1.0.4/sftp-server
chmod +x $INSTALL_PATH
curl -o /etc/systemd/system/pterosftp.service $CONFIGS_URL/pterosftp.service
systemctl daemon-reload
systemctl enable pterosftp
}
function install_mariadb {
if [ "$OS" == "ubuntu" ] || [ "$OS" == "zorin" ] || [ "$OS" == "debian" ]; then
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
apt update && apt install mariadb-server -y
elif [ "$OS" == "centos" ]; then
[ "$OS_VER_MAJOR" == "7" ] && curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
[ "$OS_VER_MAJOR" == "7" ] && yum -y install mariadb-server
[ "$OS_VER_MAJOR" == "8" ] && dnf install -y mariadb mariadb-server
else
print_error "Unsupported OS for MariaDB installations!"
fi
systemctl enable mariadb
systemctl start mariadb
}
####################
## MAIN FUNCTIONS ##
####################
function perform_install {
echo "* Installing pterodactyl daemon.."
install_dep
install_docker
install_nodejs
ptdl_dl
systemd_file
[ "$INSTALL_STANDALONE_SFTP_SERVER" == true ] && install_standalone_sftp_server
[ "$INSTALL_MARIADB" == true ] && install_mariadb
# return true if script has made it this far
return 0
}
function main {
# check if we can detect an already existing installation
if [ -d "/srv/daemon" ]; then
print_warning "The script has detected that you already have Pterodactyl daemon on your system! You cannot run the script multiple times, it will fail!"
echo -e -n "* Are you sure you want to proceed? (y/N): "
read -r CONFIRM_PROCEED
if [[ ! "$CONFIRM_PROCEED" =~ [Yy] ]]; then
print_error "Installation aborted!"
exit 1
fi
fi
# detect distro
detect_distro
print_brake 70
echo "* Pterodactyl daemon installation script"
echo "*"
echo "* Copyright (C) 2018 - 2020, Vilhelm Prytz, <vilhelm@prytznet.se>, et al."
echo "* https://github.com/VilhelmPrytz/pterodactyl-installer"
echo "*"
echo "* This script is not associated with the official Pterodactyl Project."
echo "*"
echo "* Running $OS version $OS_VER."
print_brake 70
# checks if the system is compatible with this installation script
check_os_comp
echo "* "
echo "* The installer will install Docker, required dependencies for the daemon"
echo "* as well as the daemon itself. But it's still required to create the node"
echo "* on the panel and then place the configuration file on the node manually after"
echo "* the installation has finished. Read more about this process on the"
echo "* official documentation: https://pterodactyl.io/daemon/installing.html#configure-daemon"
echo "* "
echo -e "* ${COLOR_RED}Note${COLOR_NC}: this script will not start the daemon automatically (will install systemd service, not start it)."
echo -e "* ${COLOR_RED}Note${COLOR_NC}: this script will not enable swap (for docker)."
print_brake 42
echo -n "* Would you like to install the standalone SFTP server after daemon has installed? (y/N): "
read -r CONFIRM_STANDALONE_SFTP_SERVER
[[ "$CONFIRM_STANDALONE_SFTP_SERVER" =~ [Yy] ]] && INSTALL_STANDALONE_SFTP_SERVER=true
echo -e "* ${COLOR_RED}Note${COLOR_NC}: If you installed the Pterodactyl panel on the same machine, do not use this option or the script will fail!"
echo -n "* Would you like to install MariaDB (MySQL) server on the daemon as well? (y/N): "
read -r CONFIRM_INSTALL_MARIADB
[[ "$CONFIRM_INSTALL_MARIADB" =~ [Yy] ]] && INSTALL_MARIADB=true
echo -n "* Proceed with installation? (y/N): "
read -r CONFIRM
[[ "$CONFIRM" =~ [Yy] ]] && perform_install && return
print_error "Installation aborted"
exit 0
}
function goodbye {
echo ""
print_brake 70
echo "* Installation completed."
echo ""
echo "* Make sure you create the node within the panel and then copy"
echo "* the config to this node. You may then start the daemon using "
echo "* systemctl start wings"
echo "* "
echo -e "* ${COLOR_RED}Note${COLOR_NC}: It is recommended to enable swap (for Docker, read more about it in official documentation)."
echo -e "* ${COLOR_RED}Note${COLOR_NC}: This script does not configure your firewall. Ports 8080 and 2022 needs to be open."
print_brake 70
echo ""
}
# run script
main
goodbye