forked from ajsuhaus/peri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-wings.sh
801 lines (660 loc) · 24.1 KB
/
install-wings.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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
#!/bin/bash
set -e
#############################################################################
# #
# Project 'pterodactyl-installer' for wings #
# #
# Copyright (C) 2018 - 2022, Vilhelm Prytz, <[email protected]> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
# 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 #
# #
#############################################################################
# versioning
GITHUB_SOURCE="v0.11.0"
SCRIPT_RELEASE="v0.11.0"
#################################
######## General checks #########
#################################
# 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
if ! [ -x "$(command -v curl)" ]; 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
#################################
########## Variables ############
#################################
# download URLs
WINGS_DL_BASE_URL="https://github.com/pterodactyl/wings/releases/latest/download/wings_linux_"
GITHUB_BASE_URL="https://raw.githubusercontent.com/vilhelmprytz/pterodactyl-installer/$GITHUB_SOURCE"
COLOR_RED='\033[0;31m'
COLOR_NC='\033[0m'
INSTALL_MARIADB=false
# firewall
CONFIGURE_FIREWALL=false
CONFIGURE_UFW=false
CONFIGURE_FIREWALL_CMD=false
# SSL (Let's Encrypt)
CONFIGURE_LETSENCRYPT=false
FQDN=""
EMAIL=""
# Database host
CONFIGURE_DBHOST=false
CONFIGURE_DBEXTERNAL=false
CONFIGURE_DBEXTERNAL_HOST="%"
CONFIGURE_DB_FIREWALL=false
MYSQL_DBHOST_USER="pterodactyluser"
MYSQL_DBHOST_PASSWORD="password"
# regex for email input
regex="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
#################################
####### Version checking ########
#################################
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.."
WINGS_VERSION="$(get_latest_release "pterodactyl/wings")"
####### Other library functions ########
valid_email() {
[[ $1 =~ ${regex} ]]
}
required_input() {
local __resultvar=$1
local result=''
while [ -z "$result" ]; do
echo -n "* ${2}"
read -r result
if [ -z "${3}" ]; then
[ -z "$result" ] && result="${4}"
else
[ -z "$result" ] && print_error "${3}"
fi
done
eval "$__resultvar="'$result'""
}
password_input() {
local __resultvar=$1
local result=''
local default="$4"
while [ -z "$result" ]; do
echo -n "* ${2}"
# modified from https://stackoverflow.com/a/22940001
while IFS= read -r -s -n1 char; do
[[ -z $char ]] && {
printf '\n'
break
} # ENTER pressed; output \n and break.
if [[ $char == $'\x7f' ]]; then # backspace was pressed
# Only if variable is not empty
if [ -n "$result" ]; then
# Remove last char from output variable.
[[ -n $result ]] && result=${result%?}
# Erase '*' to the left.
printf '\b \b'
fi
else
# Add typed char to output variable.
result+=$char
# Print '*' in its stead.
printf '*'
fi
done
[ -z "$result" ] && [ -n "$default" ] && result="$default"
[ -z "$result" ] && print_error "${3}"
done
eval "$__resultvar="'$result'""
}
#################################
####### Visual functions ########
#################################
print_error() {
echo ""
echo -e "* ${COLOR_RED}ERROR${COLOR_NC}: $1"
echo ""
}
print_warning() {
COLOR_YELLOW='\033[1;33m'
COLOR_NC='\033[0m'
echo ""
echo -e "* ${COLOR_YELLOW}WARNING${COLOR_NC}: $1"
echo ""
}
print_brake() {
for ((n = 0; n < $1; n++)); do
echo -n "#"
done
echo ""
}
hyperlink() {
echo -e "\e]8;;${1}\a${1}\e]8;;\a"
}
#################################
####### OS check funtions #######
#################################
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)
}
check_os_comp() {
SUPPORTED=false
MACHINE_TYPE=$(uname -m)
case "$MACHINE_TYPE" in
x86_64)
ARCH=amd64
;;
arm64) ;&
# fallthrough
aarch64)
print_warning "Detected architecture arm64"
print_warning "You will need to use Docker images made specifically for arm64"
echo -e -n "* Are you sure you want to proceed? (y/N):"
read -r choice
if [[ ! "$choice" =~ [Yy] ]]; then
print_error "Installation aborted!"
exit 1
fi
ARCH=arm64
;;
*)
print_error "Only x86_64 and arm64 are supported for Wings"
exit 1
;;
esac
case "$OS" in
ubuntu)
[ "$OS_VER_MAJOR" == "18" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "20" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "22" ] && SUPPORTED=true
;;
debian)
[ "$OS_VER_MAJOR" == "9" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "10" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "11" ] && SUPPORTED=true
;;
centos)
[ "$OS_VER_MAJOR" == "7" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "8" ] && SUPPORTED=true
;;
*)
SUPPORTED=false
;;
esac
# 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
# check virtualization
echo -e "* Installing virt-what..."
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
# silence dpkg output
export DEBIAN_FRONTEND=noninteractive
# install virt-what
apt-get -y update -qq
apt-get install -y virt-what -qq
# unsilence
unset DEBIAN_FRONTEND
elif [ "$OS" == "centos" ]; then
if [ "$OS_VER_MAJOR" == "7" ]; then
yum -q -y update
# install virt-what
yum -q -y install virt-what
elif [ "$OS_VER_MAJOR" == "8" ]; then
dnf -y -q update
# install virt-what
dnf install -y -q virt-what
fi
else
print_error "Invalid OS."
exit 1
fi
export PATH="$PATH:/sbin:/usr/sbin"
virt_serv=$(virt-what)
case "$virt_serv" in
*openvz* | *lxc*)
print_warning "Unsupported type of virtualization detected. Please consult with your hosting provider whether your server can run Docker or not. Proceed at your own risk."
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
;;
*)
[ "$virt_serv" != "" ] && print_warning "Virtualization: $virt_serv detected."
;;
esac
if uname -r | grep -q "xxxx"; then
print_error "Unsupported kernel detected."
exit 1
fi
}
############################
## INSTALLATION FUNCTIONS ##
############################
apt_update() {
apt update -q -y && apt upgrade -y
}
yum_update() {
yum -y update
}
dnf_update() {
dnf -y upgrade
}
enable_docker() {
systemctl start docker
systemctl enable docker
}
install_docker() {
echo "* Installing docker .."
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
# Install dependencies
apt-get -y install \
apt-transport-https \
ca-certificates \
gnupg2 \
software-properties-common
# Add docker gpg key
curl -fsSL https://download.docker.com/linux/"$OS"/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add docker repo
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$OS \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
# Install docker
apt_update
apt-get -y install docker-ce docker-ce-cli containerd.io
# Make sure docker is enabled
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 docker-ce-cli containerd.io
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 docker-ce-cli containerd.io --nobest
fi
enable_docker
fi
echo "* Docker has now been installed."
}
ptdl_dl() {
echo "* Installing Pterodactyl Wings .. "
mkdir -p /etc/pterodactyl
curl -L -o /usr/local/bin/wings "$WINGS_DL_BASE_URL$ARCH"
chmod u+x /usr/local/bin/wings
echo "* Done."
}
systemd_file() {
echo "* Installing systemd service.."
curl -o /etc/systemd/system/wings.service $GITHUB_BASE_URL/configs/wings.service
systemctl daemon-reload
systemctl enable wings
echo "* Installed systemd service!"
}
install_mariadb() {
MARIADB_URL="https://downloads.mariadb.com/MariaDB/mariadb_repo_setup"
case "$OS" in
debian)
if [ "$ARCH" == "aarch64" ]; then
print_warning "MariaDB doesn't support Debian on arm64"
return
fi
[ "$OS_VER_MAJOR" == "9" ] && curl -sS $MARIADB_URL | sudo bash
apt install -y mariadb-server
;;
ubuntu)
[ "$OS_VER_MAJOR" == "18" ] && curl -sS $MARIADB_URL | sudo bash
apt install -y mariadb-server
;;
centos)
[ "$OS_VER_MAJOR" == "7" ] && curl -sS $MARIADB_URL | bash
[ "$OS_VER_MAJOR" == "7" ] && yum -y install mariadb-server
[ "$OS_VER_MAJOR" == "8" ] && dnf install -y mariadb mariadb-server
;;
esac
systemctl enable mariadb
systemctl start mariadb
}
ask_database_user() {
echo -n "* Do you want to automatically configure a user for database hosts? (y/N): "
read -r CONFIRM_DBHOST
if [[ "$CONFIRM_DBHOST" =~ [Yy] ]]; then
ask_database_external
CONFIGURE_DBHOST=true
fi
}
ask_database_external() {
echo -n "* Do you want to configure MySQL to be accessed externally? (y/N): "
read -r CONFIRM_DBEXTERNAL
if [[ "$CONFIRM_DBEXTERNAL" =~ [Yy] ]]; then
echo -n "* Enter the panel address (blank for any address): "
read -r CONFIRM_DBEXTERNAL_HOST
if [ "$CONFIRM_DBEXTERNAL_HOST" != "" ]; then
CONFIGURE_DBEXTERNAL_HOST="$CONFIRM_DBEXTERNAL_HOST"
fi
[ "$CONFIGURE_FIREWALL" == true ] && ask_database_firewall
CONFIGURE_DBEXTERNAL=true
fi
}
ask_database_firewall() {
print_warning "Allow incoming traffic to port 3306 (MySQL) can potentially be a security risk, unless you know what you are doing!"
echo -n "* Would you like to allow incoming traffic to port 3306? (y/N): "
read -r CONFIRM_DB_FIREWALL
if [[ "$CONFIRM_DB_FIREWALL" =~ [Yy] ]]; then
CONFIGURE_DB_FIREWALL=true
fi
}
configure_mysql() {
echo "* Performing MySQL queries.."
if [ "$CONFIGURE_DBEXTERNAL" == true ]; then
echo "* Creating MySQL user..."
mysql -u root -e "CREATE USER '${MYSQL_DBHOST_USER}'@'${CONFIGURE_DBEXTERNAL_HOST}' IDENTIFIED BY '${MYSQL_DBHOST_PASSWORD}';"
echo "* Granting privileges.."
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_DBHOST_USER}'@'${CONFIGURE_DBEXTERNAL_HOST}' WITH GRANT OPTION;"
else
echo "* Creating MySQL user..."
mysql -u root -e "CREATE USER '${MYSQL_DBHOST_USER}'@'127.0.0.1' IDENTIFIED BY '${MYSQL_DBHOST_PASSWORD}';"
echo "* Granting privileges.."
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_DBHOST_USER}'@'127.0.0.1' WITH GRANT OPTION;"
fi
echo "* Flushing privileges.."
mysql -u root -e "FLUSH PRIVILEGES;"
echo "* Changing MySQL bind address.."
if [ "$CONFIGURE_DBEXTERNAL" == true ]; then
case "$OS" in
debian | ubuntu)
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/mariadb.conf.d/50-server.cnf
;;
centos)
sed -ne 's/^#bind-address=0.0.0.0$/bind-address=0.0.0.0/' /etc/my.cnf.d/mariadb-server.cnf
;;
esac
systemctl restart mysqld
fi
echo "* MySQL configured!"
}
#################################
##### OS SPECIFIC FUNCTIONS #####
#################################
ask_letsencrypt() {
if [ "$CONFIGURE_UFW" == false ] && [ "$CONFIGURE_FIREWALL_CMD" == false ]; then
print_warning "Let's Encrypt requires port 80/443 to be opened! You have opted out of the automatic firewall configuration; use this at your own risk (if port 80/443 is closed, the script will fail)!"
fi
print_warning "You cannot use Let's Encrypt with your hostname as an IP address! It must be a FQDN (e.g. node.example.org)."
echo -e -n "* Do you want to automatically configure HTTPS using Let's Encrypt? (y/N): "
read -r CONFIRM_SSL
if [[ "$CONFIRM_SSL" =~ [Yy] ]]; then
CONFIGURE_LETSENCRYPT=true
fi
}
firewall_ufw() {
apt install ufw -y
echo -e "\n* Enabling Uncomplicated Firewall (UFW)"
echo "* Opening port 22 (SSH), 8080 (Wings Port), 2022 (Wings SFTP Port)"
# pointing to /dev/null silences the command output
ufw allow ssh >/dev/null
ufw allow 8080 >/dev/null
ufw allow 2022 >/dev/null
[ "$CONFIGURE_LETSENCRYPT" == true ] && ufw allow http >/dev/null
[ "$CONFIGURE_LETSENCRYPT" == true ] && ufw allow https >/dev/null
[ "$CONFIGURE_DB_FIREWALL" == true ] && ufw allow 3306 >/dev/null
ufw --force enable
ufw --force reload
ufw status numbered | sed '/v6/d'
}
firewall_firewalld() {
echo -e "\n* Enabling firewall_cmd (firewalld)"
echo "* Opening port 22 (SSH), 8080 (Wings Port), 2022 (Wings SFTP Port)"
# Install
[ "$OS_VER_MAJOR" == "7" ] && yum -y -q install firewalld >/dev/null
[ "$OS_VER_MAJOR" == "8" ] && dnf -y -q install firewalld >/dev/null
# Enable
systemctl --now enable firewalld >/dev/null # Enable and start
# Configure
firewall-cmd --add-service=ssh --permanent -q # Port 22
firewall-cmd --add-port 8080/tcp --permanent -q # Port 8080
firewall-cmd --add-port 2022/tcp --permanent -q # Port 2022
[ "$CONFIGURE_LETSENCRYPT" == true ] && firewall-cmd --add-service=http --permanent -q # Port 80
[ "$CONFIGURE_LETSENCRYPT" == true ] && firewall-cmd --add-service=https --permanent -q # Port 443
[ "$CONFIGURE_DB_FIREWALL" == true ] && firewall-cmd --add-service=mysql --permanent -q # Port 3306
firewall-cmd --permanent --zone=trusted --change-interface=pterodactyl0 -q
firewall-cmd --zone=trusted --add-masquerade --permanent
firewall-cmd --reload -q # Enable firewall
echo "* Firewall-cmd installed"
print_brake 70
}
letsencrypt() {
FAILED=false
# Install certbot
case "$OS" in
debian | ubuntu)
apt-get -y install certbot python3-certbot-nginx
;;
centos)
[ "$OS_VER_MAJOR" == "7" ] && yum -y -q install epel-release
[ "$OS_VER_MAJOR" == "7" ] && yum -y -q install certbot python-certbot-nginx
[ "$OS_VER_MAJOR" == "8" ] && dnf -y -q install epel-release
[ "$OS_VER_MAJOR" == "8" ] && dnf -y -q install certbot python3-certbot-nginx
;;
esac
# If user has nginx
systemctl stop nginx || true
# Obtain certificate
certbot certonly --no-eff-email --email "$EMAIL" --standalone -d "$FQDN" || FAILED=true
systemctl start nginx || true
# Check if it succeded
if [ ! -d "/etc/letsencrypt/live/$FQDN/" ] || [ "$FAILED" == true ]; then
print_warning "The process of obtaining a Let's Encrypt certificate failed!"
fi
}
####################
## MAIN FUNCTIONS ##
####################
perform_install() {
echo "* Installing pterodactyl wings.."
[ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ] && apt_update
[ "$OS" == "centos" ] && [ "$OS_VER_MAJOR" == "7" ] && yum_update
[ "$OS" == "centos" ] && [ "$OS_VER_MAJOR" == "8" ] && dnf_update
[ "$CONFIGURE_UFW" == true ] && firewall_ufw
[ "$CONFIGURE_FIREWALL_CMD" == true ] && firewall_firewalld
install_docker
ptdl_dl
systemd_file
[ "$INSTALL_MARIADB" == true ] && install_mariadb
[ "$CONFIGURE_DBHOST" == true ] && configure_mysql
[ "$CONFIGURE_LETSENCRYPT" == true ] && letsencrypt
# return true if script has made it this far
return 0
}
main() {
# check if we can detect an already existing installation
if [ -d "/etc/pterodactyl" ]; then
print_warning "The script has detected that you already have Pterodactyl wings 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 Wings installation script @ $SCRIPT_RELEASE"
echo "*"
echo "* Copyright (C) 2018 - 2022, Vilhelm Prytz, <[email protected]>"
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."
echo "* Latest pterodactyl/wings is $WINGS_VERSION"
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 Wings"
echo "* as well as Wings 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: $(hyperlink 'https://pterodactyl.io/wings/1.0/installing.html#configure')"
echo "* "
echo -e "* ${COLOR_RED}Note${COLOR_NC}: this script will not start Wings 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
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
echo -e -n "* Do you want to automatically configure UFW (firewall)? (y/N): "
read -r CONFIRM_UFW
if [[ "$CONFIRM_UFW" =~ [Yy] ]]; then
CONFIGURE_UFW=true
CONFIGURE_FIREWALL=true
fi
fi
if [ "$OS" == "centos" ]; then
echo -e -n "* Do you want to automatically configure firewall-cmd (firewall)? (y/N): "
read -r CONFIRM_FIREWALL_CMD
if [[ "$CONFIRM_FIREWALL_CMD" =~ [Yy] ]]; then
CONFIGURE_FIREWALL_CMD=true
CONFIGURE_FIREWALL=true
fi
fi
ask_database_user
if [ "$CONFIGURE_DBHOST" == true ]; then
type mysql >/dev/null 2>&1 && HAS_MYSQL=true || HAS_MYSQL=false
if [ "$HAS_MYSQL" == false ]; then
INSTALL_MARIADB=true
fi
MYSQL_DBHOST_USER="-"
while [[ "$MYSQL_DBHOST_USER" == *"-"* ]]; do
required_input MYSQL_DBHOST_USER "Database host username (pterodactyluser): " "" "pterodactyluser"
[[ "$MYSQL_DBHOST_USER" == *"-"* ]] && print_error "Database user cannot contain hyphens"
done
password_input MYSQL_DBHOST_PASSWORD "Database host password: " "Password cannot be empty"
fi
ask_letsencrypt
if [ "$CONFIGURE_LETSENCRYPT" == true ]; then
while [ -z "$FQDN" ]; do
echo -n "* Set the FQDN to use for Let's Encrypt (node.example.com): "
read -r FQDN
ASK=false
[ -z "$FQDN" ] && print_error "FQDN cannot be empty" # check if FQDN is empty
bash <(curl -s $GITHUB_BASE_URL/lib/verify-fqdn.sh) "$FQDN" "$OS" || ASK=true # check if FQDN is valid
[ -d "/etc/letsencrypt/live/$FQDN/" ] && print_error "A certificate with this FQDN already exists!" && ASK=true # check if cert exists
[ "$ASK" == true ] && FQDN=""
[ "$ASK" == true ] && echo -e -n "* Do you still want to automatically configure HTTPS using Let's Encrypt? (y/N): "
[ "$ASK" == true ] && read -r CONFIRM_SSL
if [[ ! "$CONFIRM_SSL" =~ [Yy] ]] && [ "$ASK" == true ]; then
CONFIGURE_LETSENCRYPT=false
FQDN="none"
fi
done
fi
if [ "$CONFIGURE_LETSENCRYPT" == true ]; then
# set EMAIL
while ! valid_email "$EMAIL"; do
echo -n "* Enter email address for Let's Encrypt: "
read -r EMAIL
valid_email "$EMAIL" || print_error "Email cannot be empty or invalid"
done
fi
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 "* Wings installation completed"
echo "*"
echo "* To continue, you need to configure Wings to run with your panel"
echo "* Please refer to the official guide, $(hyperlink 'https://pterodactyl.io/wings/1.0/installing.html#configure')"
echo "* "
echo "* You can either copy the configuration file from the panel manually to /etc/pterodactyl/config.yml"
echo "* or, you can use the \"auto deploy\" button from the panel and simply paste the command in this terminal"
echo "* "
echo "* You can then start Wings manually to verify that it's working"
echo "*"
echo "* sudo wings"
echo "*"
echo "* Once you have verified that it is working, use CTRL+C and then start Wings as a service (runs in the background)"
echo "*"
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)."
[ "$CONFIGURE_FIREWALL" == false ] && echo -e "* ${COLOR_RED}Note${COLOR_NC}: If you haven't configured your firewall, ports 8080 and 2022 needs to be open."
print_brake 70
echo ""
}
# run script
main
goodbye