forked from pterodactyl-installer/pterodactyl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-panel.sh
executable file
·1048 lines (826 loc) · 31.1 KB
/
install-panel.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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -e
#############################################################################
# #
# Project 'pterodactyl-installer' for panel #
# #
# Copyright (C) 2018 - 2021, Vilhelm Prytz, <vilhelm@prytznet.se> #
# #
# 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 #
# #
#############################################################################
######## 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 ############
# versioning
GITHUB_SOURCE="master"
SCRIPT_RELEASE="canary"
FQDN=""
# Default MySQL credentials
MYSQL_DB="pterodactyl"
MYSQL_USER="pterodactyl"
MYSQL_PASSWORD=""
# Environment
email=""
# Initial admin account
user_email=""
user_username=""
user_firstname=""
user_lastname=""
user_password=""
# Assume SSL, will fetch different config if true
ASSUME_SSL=false
CONFIGURE_LETSENCRYPT=false
# download URLs
PANEL_DL_URL="https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz"
GITHUB_BASE_URL="https://raw.githubusercontent.com/vilhelmprytz/pterodactyl-installer/$GITHUB_SOURCE"
# ufw firewall
CONFIGURE_UFW=false
# firewall_cmd
CONFIGURE_FIREWALL_CMD=false
# firewall status
CONFIGURE_FIREWALL=false
# 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 ########
# 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
}
# pterodactyl version
echo "* Retrieving release information.."
PTERODACTYL_VERSION="$(get_latest_release "pterodactyl/panel")"
####### lib func #######
array_contains_element() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
valid_email() {
[[ $1 =~ ${regex} ]]
}
####### Visual functions ########
print_error() {
COLOR_RED='\033[0;31m'
COLOR_NC='\033[0m'
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"
}
##### User input functions ######
required_input() {
local __resultvar=$1
local result=''
while [ -z "$result" ]; do
echo -n "* ${2}"
read -r result
[ -z "$result" ] && print_error "${3}"
done
eval "$__resultvar="'$result'""
}
email_input() {
local __resultvar=$1
local result=''
while ! valid_email "$result"; do
echo -n "* ${2}"
read -r result
valid_email "$result" || print_error "${3}"
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'""
}
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. panel.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
ASSUME_SSL=false
fi
}
ask_assume_ssl() {
echo "* Let's Encrypt is not going to be automatically configured by this script (user opted out)."
echo "* You can 'assume' Let's Encrypt, which means the script will download a nginx configuration that is configured to use a Let's Encrypt certificate but the script won't obtain the certificate for you."
echo "* If you assume SSL and do not obtain the certificate, your installation will not work."
echo -n "* Assume SSL or not? (y/N): "
read -r ASSUME_SSL_INPUT
[[ "$ASSUME_SSL_INPUT" =~ [Yy] ]] && ASSUME_SSL=true
true
}
ask_firewall() {
case "$OS" in
ubuntu | debian)
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
;;
centos)
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
;;
esac
}
####### 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() {
CPU_ARCHITECTURE=$(uname -m)
if [ "${CPU_ARCHITECTURE}" != "x86_64" ]; then # check the architecture
print_warning "Detected CPU architecture $CPU_ARCHITECTURE"
print_warning "Using any other architecture than 64 bit (x86_64) will cause problems."
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
fi
case "$OS" in
ubuntu)
PHP_SOCKET="/run/php/php8.0-fpm.sock"
[ "$OS_VER_MAJOR" == "18" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "20" ] && SUPPORTED=true
;;
debian)
PHP_SOCKET="/run/php/php8.0-fpm.sock"
[ "$OS_VER_MAJOR" == "9" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "10" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "11" ] && SUPPORTED=true
;;
centos)
PHP_SOCKET="/var/run/php-fpm/pterodactyl.sock"
[ "$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
}
##### Main installation functions #####
# Install composer
install_composer() {
echo "* Installing composer.."
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
echo "* Composer installed!"
}
# Download pterodactyl files
ptdl_dl() {
echo "* Downloading pterodactyl panel files .. "
mkdir -p /var/www/pterodactyl
cd /var/www/pterodactyl || exit
curl -Lo panel.tar.gz "$PANEL_DL_URL"
tar -xzvf panel.tar.gz
chmod -R 755 storage/* bootstrap/cache/
cp .env.example .env
[ "$OS" == "centos" ] && export PATH=/usr/local/bin:$PATH
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
php artisan key:generate --force
echo "* Downloaded pterodactyl panel files & installed composer dependencies!"
}
# Create a databse with user
create_database() {
if [ "$OS" == "centos" ]; then
# secure MariaDB
echo "* MariaDB secure installation. The following are safe defaults."
echo "* Set root password? [Y/n] Y"
echo "* Remove anonymous users? [Y/n] Y"
echo "* Disallow root login remotely? [Y/n] Y"
echo "* Remove test database and access to it? [Y/n] Y"
echo "* Reload privilege tables now? [Y/n] Y"
echo "*"
[ "$OS_VER_MAJOR" == "7" ] && mariadb-secure-installation
[ "$OS_VER_MAJOR" == "8" ] && mysql_secure_installation
echo "* The script should have asked you to set the MySQL root password earlier (not to be confused with the pterodactyl database user password)"
echo "* MySQL will now ask you to enter the password before each command."
echo "* Create MySQL user."
mysql -u root -p -e "CREATE USER '${MYSQL_USER}'@'127.0.0.1' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "* Create database."
mysql -u root -p -e "CREATE DATABASE ${MYSQL_DB};"
echo "* Grant privileges."
mysql -u root -p -e "GRANT ALL PRIVILEGES ON ${MYSQL_DB}.* TO '${MYSQL_USER}'@'127.0.0.1' WITH GRANT OPTION;"
echo "* Flush privileges."
mysql -u root -p -e "FLUSH PRIVILEGES;"
else
echo "* Performing MySQL queries.."
echo "* Creating MySQL user.."
mysql -u root -e "CREATE USER '${MYSQL_USER}'@'127.0.0.1' IDENTIFIED BY '${MYSQL_PASSWORD}';"
echo "* Creating database.."
mysql -u root -e "CREATE DATABASE ${MYSQL_DB};"
echo "* Granting privileges.."
mysql -u root -e "GRANT ALL PRIVILEGES ON ${MYSQL_DB}.* TO '${MYSQL_USER}'@'127.0.0.1' WITH GRANT OPTION;"
echo "* Flushing privileges.."
mysql -u root -e "FLUSH PRIVILEGES;"
echo "* MySQL database created & configured!"
fi
}
# Configure environment
configure() {
app_url="http://$FQDN"
[ "$ASSUME_SSL" == true ] && app_url="https://$FQDN"
[ "$CONFIGURE_LETSENCRYPT" == true ] && app_url="https://$FQDN"
# Fill in environment:setup automatically
php artisan p:environment:setup \
--author="$email" \
--url="$app_url" \
--timezone="$timezone" \
--cache="redis" \
--session="redis" \
--queue="redis" \
--redis-host="localhost" \
--redis-pass="null" \
--redis-port="6379" \
--settings-ui=true
# Fill in environment:database credentials automatically
php artisan p:environment:database \
--host="127.0.0.1" \
--port="3306" \
--database="$MYSQL_DB" \
--username="$MYSQL_USER" \
--password="$MYSQL_PASSWORD"
# configures database
php artisan migrate --seed --force
# Create user account
php artisan p:user:make \
--email="$user_email" \
--username="$user_username" \
--name-first="$user_firstname" \
--name-last="$user_lastname" \
--password="$user_password" \
--admin=1
}
# set the correct folder permissions depending on OS and webserver
set_folder_permissions() {
# if os is ubuntu or debian, we do this
case "$OS" in
debian | ubuntu)
chown -R www-data:www-data ./*
;;
centos)
chown -R nginx:nginx ./*
;;
esac
}
# insert cronjob
insert_cronjob() {
echo "* Installing cronjob.. "
crontab -l | {
cat
echo "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1"
} | crontab -
echo "* Cronjob installed!"
}
install_pteroq() {
echo "* Installing pteroq service.."
curl -o /etc/systemd/system/pteroq.service $GITHUB_BASE_URL/configs/pteroq.service
case "$OS" in
debian | ubuntu)
sed -i -e "s@<user>@www-data@g" /etc/systemd/system/pteroq.service
;;
centos)
sed -i -e "s@<user>@nginx@g" /etc/systemd/system/pteroq.service
;;
esac
systemctl enable pteroq.service
systemctl start pteroq
echo "* Installed pteroq!"
}
##### OS specific install functions #####
apt_update() {
apt update -q -y && apt upgrade -y
}
yum_update() {
yum -y update
}
dnf_update() {
dnf -y upgrade
}
enable_services_debian_based() {
systemctl enable mariadb
systemctl enable redis-server
systemctl start mariadb
systemctl start redis-server
}
enable_services_centos_based() {
systemctl enable mariadb
systemctl enable nginx
systemctl enable redis
systemctl start mariadb
systemctl start redis
}
selinux_allow() {
setsebool -P httpd_can_network_connect 1 || true # these commands can fail OK
setsebool -P httpd_execmem 1 || true
setsebool -P httpd_unified 1 || true
}
ubuntu20_dep() {
echo "* Installing dependencies for Ubuntu 20.."
# Add "add-apt-repository" command
apt -y install software-properties-common curl apt-transport-https ca-certificates gnupg
# Ubuntu universe repo
add-apt-repository universe
# Add PPA for PHP (we need 8.0 and focal only has 7.4)
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
# Update repositories list
apt_update
# Install Dependencies
apt -y install php8.0 php8.0-{cli,gd,mysql,pdo,mbstring,tokenizer,bcmath,xml,fpm,curl,zip} mariadb-server nginx tar unzip git redis-server redis cron
# Enable services
enable_services_debian_based
echo "* Dependencies for Ubuntu installed!"
}
ubuntu18_dep() {
echo "* Installing dependencies for Ubuntu 18.."
# Add "add-apt-repository" command
apt -y install software-properties-common curl apt-transport-https ca-certificates gnupg
# Ubuntu universe repo
add-apt-repository universe
# Add PPA for PHP (we need 8.0 and bionic only has 7.2)
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
# Add the MariaDB repo (bionic has mariadb version 10.1 and we need newer than that)
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
# Update repositories list
apt_update
# Install Dependencies
apt -y install php8.0 php8.0-{cli,gd,mysql,pdo,mbstring,tokenizer,bcmath,xml,fpm,curl,zip} mariadb-server nginx tar unzip git redis-server redis cron
# Enable services
enable_services_debian_based
echo "* Dependencies for Ubuntu installed!"
}
debian_stretch_dep() {
echo "* Installing dependencies for Debian 8/9.."
# MariaDB need dirmngr
apt -y install dirmngr
# install PHP 8.0 using sury's repo instead of PPA
apt install ca-certificates apt-transport-https lsb-release -y
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
# Add the MariaDB repo (oldstable has mariadb version 10.1 and we need newer than that)
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
# Update repositories list
apt_update
# Install Dependencies
apt -y install php8.0 php8.0-{cli,gd,mysql,pdo,mbstring,tokenizer,bcmath,xml,fpm,curl,zip} mariadb-server nginx curl tar unzip git redis-server cron
# Enable services
enable_services_debian_based
echo "* Dependencies for Debian 8/9 installed!"
}
debian_buster_dep() {
echo "* Installing dependencies for Debian 10.."
# MariaDB need dirmngr
apt -y install dirmngr
# install PHP 8.0 using sury's repo instead of default 7.2 package (in buster repo)
# this guide shows how: https://vilhelmprytz.se/2018/08/22/install-php72-on-Debian-8-and-9.html
apt install ca-certificates apt-transport-https lsb-release -y
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
# Update repositories list
apt_update
# install dependencies
apt -y install php8.0 php8.0-{cli,gd,mysql,pdo,mbstring,tokenizer,bcmath,xml,fpm,curl,zip} mariadb-server nginx curl tar unzip git redis-server cron
# Enable services
enable_services_debian_based
echo "* Dependencies for Debian 10 installed!"
}
debian_dep() {
echo "* Installing dependencies for Debian 11.."
# MariaDB need dirmngr
apt -y install dirmngr
# install PHP 8.0 using sury's repo instead of default 7.2 package (in buster repo)
# this guide shows how: https://vilhelmprytz.se/2018/08/22/install-php72-on-Debian-8-and-9.html
apt install ca-certificates apt-transport-https lsb-release -y
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
# Update repositories list
apt_update
# install dependencies
apt -y install php8.0 php8.0-{cli,gd,mysql,pdo,mbstring,tokenizer,bcmath,xml,fpm,curl,zip} mariadb-server nginx curl tar unzip git redis-server cron
# Enable services
enable_services_debian_based
echo "* Dependencies for Debian 11 installed!"
}
centos7_dep() {
echo "* Installing dependencies for CentOS 7.."
# SELinux tools
yum install -y policycoreutils policycoreutils-python selinux-policy selinux-policy-targeted libselinux-utils setroubleshoot-server setools setools-console mcstrans
# Add remi repo (php8.0)
yum install -y epel-release http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager -y --disable remi-php54
yum-config-manager -y --enable remi-php80
yum_update
# Install MariaDB
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
# Install dependencies
yum -y install php php-common php-tokenizer php-curl php-fpm php-cli php-json php-mysqlnd php-mcrypt php-gd php-mbstring php-pdo php-zip php-bcmath php-dom php-opcache mariadb-server nginx curl tar zip unzip git redis
# Enable services
enable_services_centos_based
# SELinux (allow nginx and redis)
selinux_allow
echo "* Dependencies for CentOS installed!"
}
centos8_dep() {
echo "* Installing dependencies for CentOS 8.."
# SELinux tools
dnf install -y policycoreutils selinux-policy selinux-policy-targeted setroubleshoot-server setools setools-console mcstrans
# add remi repo (php8.0)
dnf install -y epel-release http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module enable -y php:remi-8.0
dnf_update
dnf install -y php php-common php-fpm php-cli php-json php-mysqlnd php-gd php-mbstring php-pdo php-zip php-bcmath php-dom php-opcache
# MariaDB (use from official repo)
dnf install -y mariadb mariadb-server
# Other dependencies
dnf install -y nginx curl tar zip unzip git redis
# Enable services
enable_services_centos_based
# SELinux (allow nginx and redis)
selinux_allow
echo "* Dependencies for CentOS installed!"
}
##### OTHER OS SPECIFIC FUNCTIONS #####
centos_php() {
curl -o /etc/php-fpm.d/www-pterodactyl.conf $GITHUB_BASE_URL/configs/www-pterodactyl.conf
systemctl enable php-fpm
systemctl start php-fpm
}
firewall_ufw() {
apt install -y ufw
echo -e "\n* Enabling Uncomplicated Firewall (UFW)"
echo "* Opening port 22 (SSH), 80 (HTTP) and 443 (HTTPS)"
# pointing to /dev/null silences the command output
ufw allow ssh >/dev/null
ufw allow http >/dev/null
ufw allow https >/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), 80 (HTTP) and 443 (HTTPS)"
# 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=http --permanent -q # Port 80
firewall-cmd --add-service=https --permanent -q # Port 443
firewall-cmd --add-service=ssh --permanent -q # Port 22
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 certbot python-certbot-nginx
[ "$OS_VER_MAJOR" == "8" ] && dnf -y -q install certbot python3-certbot-nginx
;;
esac
# Obtain certificate
certbot --nginx --redirect --no-eff-email --email "$email" -d "$FQDN" || FAILED=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!"
echo -n "* Still assume SSL? (y/N): "
read -r CONFIGURE_SSL
if [[ "$CONFIGURE_SSL" =~ [Yy] ]]; then
ASSUME_SSL=true
CONFIGURE_LETSENCRYPT=false
configure_nginx
else
ASSUME_SSL=false
CONFIGURE_LETSENCRYPT=false
fi
fi
}
##### WEBSERVER CONFIGURATION FUNCTIONS #####
configure_nginx() {
echo "* Configuring nginx .."
if [ $ASSUME_SSL == true ] && [ $CONFIGURE_LETSENCRYPT == false ]; then
DL_FILE="nginx_ssl.conf"
else
DL_FILE="nginx.conf"
fi
if [ "$OS" == "centos" ]; then
# remove default config
rm -rf /etc/nginx/conf.d/default
# download new config
curl -o /etc/nginx/conf.d/pterodactyl.conf $GITHUB_BASE_URL/configs/$DL_FILE
# replace all <domain> places with the correct domain
sed -i -e "s@<domain>@${FQDN}@g" /etc/nginx/conf.d/pterodactyl.conf
# replace all <php_socket> places with correct socket "path"
sed -i -e "s@<php_socket>@${PHP_SOCKET}@g" /etc/nginx/conf.d/pterodactyl.conf
else
# remove default config
rm -rf /etc/nginx/sites-enabled/default
# download new config
curl -o /etc/nginx/sites-available/pterodactyl.conf $GITHUB_BASE_URL/configs/$DL_FILE
# replace all <domain> places with the correct domain
sed -i -e "s@<domain>@${FQDN}@g" /etc/nginx/sites-available/pterodactyl.conf
# replace all <php_socket> places with correct socket "path"
sed -i -e "s@<php_socket>@${PHP_SOCKET}@g" /etc/nginx/sites-available/pterodactyl.conf
# on debian 9, TLS v1.3 is not supported (see #76)
[ "$OS" == "debian" ] && [ "$OS_VER_MAJOR" == "9" ] && sed -i 's/ TLSv1.3//' /etc/nginx/sites-available/pterodactyl.conf
# enable pterodactyl
ln -sf /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
fi
if [ "$ASSUME_SSL" == false ] && [ "$CONFIGURE_LETSENCRYPT" == false ]; then
systemctl restart nginx
fi
echo "* nginx configured!"
}
##### MAIN FUNCTIONS #####
perform_install() {
echo "* Starting installation.. this might take a while!"
case "$OS" in
debian | ubuntu)
apt_update
[ "$CONFIGURE_UFW" == true ] && firewall_ufw
if [ "$OS" == "ubuntu" ]; then
[ "$OS_VER_MAJOR" == "20" ] && ubuntu20_dep
[ "$OS_VER_MAJOR" == "18" ] && ubuntu18_dep
elif [ "$OS" == "debian" ]; then
[ "$OS_VER_MAJOR" == "9" ] && debian_stretch_dep
[ "$OS_VER_MAJOR" == "10" ] && debian_buster_dep
[ "$OS_VER_MAJOR" == "11" ] && debian_dep
fi
;;
centos)
[ "$OS_VER_MAJOR" == "7" ] && yum_update
[ "$OS_VER_MAJOR" == "8" ] && dnf_update
[ "$CONFIGURE_FIREWALL_CMD" == true ] && firewall_firewalld
[ "$OS_VER_MAJOR" == "7" ] && centos7_dep
[ "$OS_VER_MAJOR" == "8" ] && centos8_dep
;;
esac
[ "$OS" == "centos" ] && centos_php
install_composer
ptdl_dl
create_database
configure
set_folder_permissions
insert_cronjob
install_pteroq
configure_nginx
[ "$CONFIGURE_LETSENCRYPT" == true ] && letsencrypt
true
}
main() {
# check if we can detect an already existing installation
if [ -d "/var/www/pterodactyl" ]; then
print_warning "The script has detected that you already have Pterodactyl panel 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 panel installation script @ $SCRIPT_RELEASE"
echo "*"
echo "* Copyright (C) 2018 - 2021, Vilhelm Prytz, <vilhelm@prytznet.se>"
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/panel is $PTERODACTYL_VERSION"
print_brake 70
# checks if the system is compatible with this installation script
check_os_comp
# set database credentials
print_brake 72
echo "* Database configuration."
echo ""
echo "* This will be the credentials used for communication between the MySQL"
echo "* database and the panel. You do not need to create the database"
echo "* before running this script, the script will do that for you."
echo ""
echo -n "* Database name (panel): "
read -r MYSQL_DB_INPUT
[ -z "$MYSQL_DB_INPUT" ] && MYSQL_DB="panel" || MYSQL_DB=$MYSQL_DB_INPUT
echo -n "* Username (pterodactyl): "
read -r MYSQL_USER_INPUT
[ -z "$MYSQL_USER_INPUT" ] && MYSQL_USER="pterodactyl" || MYSQL_USER=$MYSQL_USER_INPUT
# MySQL password input
rand_pw=$(
tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 64
echo
)
password_input MYSQL_PASSWORD "Password (press enter to use randomly generated password): " "MySQL password cannot be empty" "$rand_pw"
readarray -t valid_timezones <<<"$(curl -s $GITHUB_BASE_URL/configs/valid_timezones.txt)"
echo "* List of valid timezones here $(hyperlink "https://www.php.net/manual/en/timezones.php")"
while [ -z "$timezone" ]; do
echo -n "* Select timezone [Europe/Stockholm]: "
read -r timezone_input
array_contains_element "$timezone_input" "${valid_timezones[@]}" && timezone="$timezone_input"
[ -z "$timezone_input" ] && timezone="Europe/Stockholm" # because köttbullar!
done
email_input email "Provide the email address that will be used to configure Let's Encrypt and Pterodactyl: " "Email cannot be empty or invalid"
# Initial admin account
email_input user_email "Email address for the initial admin account: " "Email cannot be empty or invalid"
required_input user_username "Username for the initial admin account: " "Username cannot be empty"
required_input user_firstname "First name for the initial admin account: " "Name cannot be empty"
required_input user_lastname "Last name for the initial admin account: " "Name cannot be empty"
password_input user_password "Password for the initial admin account: " "Password cannot be empty"
print_brake 72
# set FQDN
while [ -z "$FQDN" ]; do
echo -n "* Set the FQDN of this panel (panel.example.com): "
read -r FQDN
[ -z "$FQDN" ] && print_error "FQDN cannot be empty"
done
# Ask if firewall is needed
ask_firewall
# Ask if letsencrypt is needed
ask_letsencrypt
# If it's already true, this should be a no-brainer
[ "$CONFIGURE_LETSENCRYPT" == false ] && ask_assume_ssl
# verify FQDN if user has selected to assume SSL or configure Let's Encrypt
[ "$CONFIGURE_LETSENCRYPT" == true ] || [ "$ASSUME_SSL" == true ] && bash <(curl -s $GITHUB_BASE_URL/lib/verify-fqdn.sh) "$FQDN" "$OS"
# summary
summary
# confirm installation
echo -e -n "\n* Initial configuration completed. Continue with installation? (y/N): "
read -r CONFIRM