Advertisement
miraip0ts

Ptero-Setup

Dec 29th, 2019
1,750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 36.21 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. output(){
  4.     echo -e '\e[36m'$1'\e[0m';
  5. }
  6.  
  7. copyright(){
  8.     output "Pterodactyl Installation & Upgrade script v24.3."
  9.     output "Copyright © 2018 Thien Tran <thientran@securesrv.io>."
  10.     output "This script is for royalehosting and sharing is strictly forbidden."
  11.     output ""
  12. }
  13.  
  14. get_distribution(){
  15.     output "Thank you for your purchase. Please note that this script is meant to be installed on a fresh OS. Installing it on a non-fresh OS may cause problems."
  16.     output "Automatic Operating System Detection initialized."
  17.     if [ -r /etc/os-release ]; then
  18.         lsb_dist="$(. /etc/os-release && echo "$ID")"
  19.         dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  20.     else
  21.         exit 0
  22.     fi
  23.     output "OS: $lsb_dist $dist_version detected."
  24.     output ""
  25.  
  26.    
  27. }
  28.  
  29. check_root(){
  30.     if [ "$EUID" -ne 0 ]; then
  31.         output "Please run as root"
  32.         exit 0
  33.     fi
  34. }
  35.  
  36. get_architecture(){
  37.     output "Automatic Architecture Detection initialized."
  38. }
  39.  
  40. get_virtualization(){
  41.     output "Automatic Virtualization Detection initialized."
  42.     if [ "$lsb_dist" =  "ubuntu" ]; then
  43.         apt-get update --fix-missing
  44.         apt-get -y install software-properties-common
  45.         add-apt-repository -y universe
  46.         apt-get -y install virt-what
  47.     elif [ "$lsb_dist" =  "debian" ]; then
  48.         apt update --fix-missing
  49.         apt-get -y install software-properties-common
  50.         apt-get -y install virt-what
  51.     elif [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  52.         yum -y install virt-what
  53.     fi
  54.     virt_serv=$(virt-what)
  55.     if [ "$virt_serv" = "" ]; then
  56.         output "Virtualization: Bare Metal detected."
  57.     else
  58.         output "Virtualization: $virt_serv detected."
  59.     fi
  60.     output ""
  61.    
  62. }
  63.  
  64. server_options() {
  65.     output "Please select what you would like to install:\n[1] Install the panel.\n[2] Install the daemon.\n[3] Install the panel and daemon.\n[4] Install the standalone SFTP server (Only use this after you have installed and configured the daemon. Ubuntu 14.04 is NOT supported.)\n[5] Upgrade 0.7.x panel to 0.7.14.\n[6] Upgrade 0.6.x daemon to 0.6.12.\n[7] Upgrade the standalone SFTP server to 1.0.4.\n[8] Change Pterodactyl theme.\n[9] Emergency MariaDB root password reset."
  66.     read choice
  67.     case $choice in
  68.         1 ) installoption=1
  69.             output "You have selected panel installation only."
  70.             ;;
  71.         2 ) installoption=2
  72.             output "You have selected daemon installation only."
  73.             ;;
  74.         3 ) installoption=3
  75.             output "You have selected panel and daemon installation."
  76.             ;;
  77.         4 ) installoption=4
  78.             output "You have selected to install the standalone SFTP server."
  79.             ;;
  80.         5 ) installoption=5
  81.             output "You have selected to upgrade the panel."
  82.             ;;
  83.         6 ) installoption=6
  84.             output "You have selected to upgrade the daemon."
  85.             ;;
  86.         7 ) installoption=7
  87.             output "You have selected to upgrade the standalone SFTP."
  88.             ;;
  89.         8 ) installoption=8
  90.             output "You have selected to change Pterodactyl's theme."
  91.             ;;
  92.         9 ) installoption=9
  93.             output "You have selected MariaDB root password reset."
  94.             ;;
  95.         * ) output "You did not enter a a valid selection."
  96.             server_options
  97.     esac
  98. }  
  99.  
  100. webserver_options() {
  101.     output "Please select which web server you would like to use:\n[1] Nginx (Recommended).\n[2] Apache2/Httpd."
  102.     read choice
  103.     case $choice in
  104.         1 ) webserver=1
  105.             output "You have selected Nginx."
  106.             ;;
  107.         2 ) webserver=2
  108.             output "You have selected Apache2 / Httpd."
  109.             ;;
  110.         * ) output "You did not enter a valid selection."
  111.             webserver_options
  112.     esac
  113. }
  114.  
  115. theme_options() {
  116.     output "Would you like to install Fonix's themes? :\n[1] No.\n[2] Graphite theme.\n[3] Midnight theme."
  117.     output "You can find out about Fonix's themes here: https://github.com/TheFonix/Pterodactyl-Themes"
  118.     read choice
  119.     case $choice in
  120.         1 ) themeoption=1
  121.             output "You have selected to install vanilla Pterodactyl theme."
  122.             ;;
  123.         2 ) themeoption=2a
  124.             output "You have selected to install Fonix's Graphite theme."
  125.             ;;
  126.         3 ) themeoption=3
  127.             output "You have selected panel and Fonix's Midnight theme."
  128.             ;;
  129.         * ) output "You did not enter a a valid selection"
  130.             theme_options
  131.     esac
  132. }  
  133.  
  134. required_infos() {
  135.     output "Please enter your FQDN (panel.yourdomain.com):"
  136.     read FQDN
  137.  
  138.     output "Please enter the desired user email address:"
  139.     read email
  140. }
  141.  
  142. theme() {
  143.     output "Theme installation initialized."
  144.     cd /var/www/pterodactyl
  145.     if [ "$themeoption" = "1" ]; then
  146.         output "Keeping Pterodactyl's vanilla theme."
  147.     elif [ "$themeoption" = "2" ]; then
  148.         curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/Pterodactyl-7/Graphite/build.sh | sh    
  149.     elif [ "$themeoption" = "3" ]; then
  150.         curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/Pterodactyl-7/Midnight/build.sh | sh
  151.     fi
  152. }
  153.  
  154. repositories_setup(){
  155.     output "Configuring your repositories."
  156.     if [ "$lsb_dist" =  "ubuntu" ] || [ "$lsb_dist" =  "debian" ]; then
  157.         apt-get -y install sudo
  158.         echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
  159.         apt-get -y update
  160.         if [ "$lsb_dist" =  "ubuntu" ]; then
  161.             LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
  162.             add-apt-repository -y ppa:chris-lea/redis-server
  163.             add-apt-repository -y ppa:certbot/certbot
  164.             if [ "$dist_version" = "18.10" ]; then
  165.                 apt-get install software-properties-common
  166.                 apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  167.                 add-apt-repository 'deb [arch=amd64] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu cosmic main'
  168.             elif [ "$dist_version" = "18.04" ]; then
  169.                 add-apt-repository -y ppa:nginx/stable
  170.                 apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  171.                 add-apt-repository -y 'deb [arch=amd64,arm64,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main'
  172.             elif [ "$dist_version" = "16.04" ]; then
  173.                 add-apt-repository -y ppa:nginx/stable
  174.                 apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  175.                 add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu xenial main'
  176.             elif [ "$dist_version" = "14.04" ]; then
  177.                 add-apt-repository -y ppa:ondrej/nginx
  178.                 apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
  179.                 add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu trusty main'            
  180.             fi
  181.         elif [ "$lsb_dist" =  "debian" ]; then
  182.             apt-get -y install ca-certificates apt-transport-https
  183.             if [ "$dist_version" = "9" ]; then
  184.                 apt-get -y install software-properties-common dirmngr
  185.                 wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  186.                 sudo echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
  187.                 sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
  188.                 sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/debian stretch main'
  189.             elif [ "$dist_version" = "8" ]; then
  190.                 apt-get -y install software-properties-common
  191.                 wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  192.                 echo "deb https://packages.sury.org/php/ jessie main" | sudo tee /etc/apt/sources.list.d/php.list
  193.                 apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
  194.                 add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/debian jessie main'
  195.             fi
  196.         fi
  197.         apt-get -y update
  198.         apt-get -y upgrade
  199.         apt-get -y autoremove
  200.         apt-get -y autoclean  
  201.     elif  [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  202.         if  [ "$lsb_dist" =  "fedora" ] && [ "$dist_version" = "28" ]; then
  203.  
  204.             bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  205. [mariadb]
  206. name = MariaDB
  207. baseurl = http://yum.mariadb.org/10.3/fedora28-amd64
  208. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  209. gpgcheck=1
  210. EOF
  211.  
  212. bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  213. [heffer-nginx-mainline]
  214. name=Copr repo for nginx-mainline owned by heffer
  215. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/fedora-$releasever-$basearch/
  216. type=rpm-md
  217. skip_if_unavailable=True
  218. gpgcheck=1
  219. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  220. repo_gpgcheck=0
  221. enabled=1
  222. enabled_metadata=1
  223. EOF
  224.  
  225.         elif  [ "$lsb_dist" =  "centos" ] && [ "$dist_version" = "7" ]; then
  226.  
  227.             bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  228. [mariadb]
  229. name = MariaDB
  230. baseurl = http://yum.mariadb.org/10.3/centos7-amd64
  231. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  232. gpgcheck=1
  233. EOF
  234.  
  235.             bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  236. [heffer-nginx-mainline]
  237. name=Copr repo for nginx-mainline owned by heffer
  238. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/epel-7-$basearch/
  239. type=rpm-md
  240. skip_if_unavailable=True
  241. gpgcheck=1
  242. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  243. repo_gpgcheck=0
  244. enabled=1
  245. enabled_metadata=1
  246. EOF
  247.  
  248.             yum -y install epel-release
  249.             yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  250.         elif  [ "$lsb_dist" =  "rhel" ]; then
  251.            
  252.             bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'        
  253. [mariadb]
  254. name = MariaDB
  255. baseurl = http://yum.mariadb.org/10.3/rhel7-amd64
  256. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  257. gpgcheck=1
  258. EOF
  259.  
  260.             bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  261. [heffer-nginx-mainline]
  262. name=Copr repo for nginx-mainline owned by heffer
  263. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/epel-7-$basearch/
  264. type=rpm-md
  265. skip_if_unavailable=True
  266. gpgcheck=1
  267. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  268. repo_gpgcheck=0
  269. enabled=1
  270. enabled_metadata=1
  271. EOF
  272.             yum -y install epel-release
  273.             yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  274.         fi
  275.         yum -y install yum-utils
  276.         yum-config-manager --enable remi-php72
  277.         yum -y upgrade
  278.         yum -y autoremove
  279.         yum -y clean packages
  280.     fi
  281. }
  282.  
  283. install_dependencies(){
  284.     output "Installing dependencies."
  285.     if  [ "$lsb_dist" =  "ubuntu" ] ||  [ "$lsb_dist" =  "debian" ]; then
  286.         if [ "$webserver" = "1" ]; then
  287.             apt-get -y install php7.2 php7.2-cli php7.2-gd php7.2-mysql php7.2-pdo php7.2-mbstring php7.2-tokenizer php7.2-bcmath php7.2-xml php7.2-fpm php7.2-curl php7.2-zip curl tar unzip git redis-server nginx git wget
  288.         elif [ "$webserver" = "2" ]; then
  289.             apt-get -y install php7.2 php7.2-cli php7.2-gd php7.2-mysql php7.2-pdo php7.2-mbstring php7.2-tokenizer php7.2-bcmath php7.2-xml php7.2-fpm php7.2-curl php7.2-zip curl tar unzip git redis-server apache2 libapache2-mod-php7.2 redis-server git wget
  290.         fi
  291.         sh -c "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server"
  292.     elif [ "$lsb_dist" =  "fedora" ] ||  [ "$lsb_dist" =  "centos" ] ||  [ "$lsb_dist" =  "rhel" ]; then
  293.         if [ "$webserver" = "1" ]; then
  294.             yum -y install php php-common 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 redis cronie nginx git policycoreutils-python-utils libsemanage-devel unzip wget
  295.         elif [ "$webserver" = "2" ]; then
  296.             yum -y install php php-common 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 redis cronie httpd git policycoreutils-python-utils libsemanage-devel mod_ssl unzip wget
  297.         fi
  298.     fi
  299.  
  300.     output "Enabling Services."
  301.     systemctl enable php-fpm
  302.     systemctl enable php7.2-fpm
  303.     if [ "$webserver" = "1" ]; then
  304.         systemctl enable nginx
  305.     elif [ "$webserver" = "2" ]; then
  306.         systemctl enable apache2
  307.         systemctl enable httpd
  308.     fi
  309.  
  310.     if [ "$lsb_dist" =  "ubuntu" ] || [ "$lsb_dist" =  "debian" ]; then
  311.         systemctl enable redis-server
  312.         service redis-server start
  313.     elif [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  314.         systemctl enable redis
  315.         service redis start
  316.     fi
  317.    
  318.     systemctl enable cron
  319.     systemctl enable mariadb
  320.     service php-fpm start
  321.     service php7.2-fpm start
  322.     if [ "$webserver" = "1" ]; then
  323.         service nginx start
  324.     elif [ "$webserver" = "2" ]; then
  325.         if [ "$lsb_dist" =  "ubuntu" ] || [ "$lsb_dist" =  "debian" ]; then
  326.             service apache2 start
  327.         elif [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  328.             service httpd start
  329.         fi
  330.     fi
  331.     service cron start
  332.     service mariadb start
  333. }
  334.  
  335. pterodactyl_queue(){
  336.     if [ "$lsb_dist" =  "ubuntu" ] && [ "$dist_version" = "14.04" ]; then
  337.         apt -y install supervisor
  338.         service supervisor start
  339.         sudo bash -c 'cat > /etc/supervisor/conf.d/pterodactyl-worker.conf' <<-'EOF'
  340. [program:pterodactyl-worker]
  341. process_name=%(program_name)s_%(process_num)02d
  342. command=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  343. autostart=true
  344. autorestart=true
  345. user=www-data
  346. numprocs=2
  347. redirect_stderr=true
  348. stdout_logfile=/var/www/pterodactyl/storage/logs/queue-worker.log
  349. EOF
  350.         output "Updating Supervisor"
  351.         supervisorctl reread
  352.         supervisorctl update
  353.         supervisorctl start pterodactyl-worker:*
  354.         sed -i -e '$i \service supervisor start\n' /etc/rc.local    
  355.     elif  [ "$lsb_dist" =  "ubuntu" ] ||  [ "$lsb_dist" =  "debian" ]; then
  356.         cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  357. [Unit]
  358. Description=Pterodactyl Queue Worker
  359. After=redis-server.service
  360.  
  361. [Service]
  362. User=www-data
  363. Group=www-data
  364. Restart=always
  365. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  366.  
  367. [Install]
  368. WantedBy=multi-user.target
  369. EOF
  370.     elif  [ "$lsb_dist" =  "fedora" ] ||  [ "$lsb_dist" =  "centos" ] ||  [ "$lsb_dist" =  "rhel" ]; then
  371.         if [ "$webserver" = "1" ]; then
  372.             cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  373. Description=Pterodactyl Queue Worker
  374. After=redis-server.service
  375.  
  376. [Service]
  377. User=nginx
  378. Group=nginx
  379. Restart=always
  380. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  381.  
  382. [Install]
  383. WantedBy=multi-user.target
  384. EOF
  385.         elif [ "$webserver" = "2" ]; then
  386.             cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  387. [Unit]
  388. Description=Pterodactyl Queue Worker
  389. After=redis-server.service
  390.  
  391. [Service]
  392. User=apache
  393. Group=apache
  394. Restart=always
  395. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  396.  
  397. [Install]
  398. WantedBy=multi-user.target
  399. EOF
  400.         fi
  401.     fi
  402.     sudo systemctl daemon-reload
  403.     systemctl enable pteroq.service
  404.     systemctl start pteroq
  405. }
  406.  
  407. install_pterodactyl() {
  408.     output "Creating the databases and setting root password"
  409.     password=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  410.     rootpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  411.     Q1="CREATE DATABASE IF NOT EXISTS panel;"
  412.     Q2="GRANT ALL ON panel.* TO 'pterodactyl'@'127.0.0.1' IDENTIFIED BY '$password';"
  413.     Q3="SET PASSWORD FOR 'root'@'localhost' = PASSWORD('$rootpassword');"
  414.     Q4="SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('$rootpassword');"
  415.     Q5="SET PASSWORD FOR 'root'@'::1' = PASSWORD('$rootpassword');"
  416.     Q6="DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  417.     Q7="DELETE FROM mysql.user WHERE User='';"
  418.     Q8="DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';"
  419.     Q9="FLUSH PRIVILEGES;"
  420.     SQL="${Q1}${Q2}${Q3}${Q4}${Q5}${Q6}${Q7}${Q8}${Q9}"
  421.     mysql -u root -e "$SQL"
  422.  
  423.     output "Downloading Pterodactyl."
  424.     mkdir -p /var/www/pterodactyl
  425.     cd /var/www/pterodactyl
  426.     curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/download/v0.7.14/panel.tar.gz
  427.     tar --strip-components=1 -xzvf panel.tar.gz
  428.     chmod -R 755 storage/* bootstrap/cache/
  429.  
  430.     output "Installing Pterodactyl."
  431.     curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
  432.     cp .env.example .env
  433.     if [ "$lsb_dist" =  "rhel" ]; then
  434.         yum -y install composer
  435.         php /usr/local/bin/composer update
  436.     else
  437.         php /usr/local/bin/composer install --no-dev --optimize-autoloader
  438.     fi
  439.     php artisan key:generate --force
  440.     php artisan p:environment:setup -n --author=$email --url=https://$FQDN --timezone=America/New_York --cache=redis --session=database --queue=redis --redis-host=127.0.0.1 --redis-pass= --redis-port=6379
  441.     php artisan p:environment:database --host=127.0.0.1 --port=3306 --database=panel --username=pterodactyl --password=$password
  442.     output "To use PHP's internal mail sending, select [mail]. To use a custom SMTP server, select [smtp]. TLS Encryption is recommended."
  443.     php artisan p:environment:mail
  444.     php artisan migrate --seed --force
  445.     php artisan p:user:make --email=$email --admin=1
  446.     if  [ "$lsb_dist" =  "ubuntu" ] || [ "$lsb_dist" =  "debian" ]; then
  447.         chown -R www-data:www-data *
  448.     elif  [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  449.         if [ "$webserver" = "1" ]; then
  450.             chown -R nginx:nginx *
  451.         elif [ "$webserver" = "2" ]; then
  452.             chown -R apache:apache *
  453.         fi
  454.     fi
  455.     output "Creating panel queue listeners"
  456.     (crontab -l ; echo "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1")| crontab -
  457.     service cron restart
  458. }
  459.  
  460. upgrade_pterodactyl(){
  461.     cd /var/www/pterodactyl
  462.     php artisan down
  463.     curl -L https://github.com/pterodactyl/panel/releases/download/v0.7.14/panel.tar.gz | tar --strip-components=1 -xzv
  464.     unzip panel
  465.     chmod -R 755 storage/* bootstrap/cache
  466.     php /usr/local/bin/composer install --no-dev --optimize-autoloader
  467.     php artisan view:clear
  468.     php artisan migrate --force
  469.     php artisan db:seed --force
  470.     chown -R www-data:www-data *
  471.     if [ "$lsb_dist" =  "fedora" ] || [ "$lsb_dist" =  "centos" ] || [ "$lsb_dist" =  "rhel" ]; then
  472.         if [ "$webserver" = "1" ]; then
  473.             chown -R nginx:nginx $(pwd)
  474.         elif [ "$webserver" = "2" ]; then
  475.             chown -R apache:apache $(pwd)
  476.         fi
  477.         semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  478.         restorecon -R /var/www/pterodactyl
  479.     fi
  480.     output "Your panel has been updated to version 0.7.14."
  481.     php artisan up
  482.     php artisan queue:restart
  483. }
  484.  
  485. webserver_config(){
  486.     if  [ "$lsb_dist" =  "ubuntu" ] || [ "$lsb_dist" =  "debian" ]; then
  487.         if [ "$webserver" = "1" ]; then
  488.             nginx_config
  489.         elif [ "$webserver" = "2" ]; then
  490.             apache_config
  491.         fi
  492.     elif  [ "$lsb_dist" =  "fedora" ] ||  [ "$lsb_dist" =  "centos" ] ||  [ "$lsb_dist" =  "rhel" ]; then
  493.         if [ "$webserver" = "1" ]; then
  494.             php_config
  495.             nginx_config_redhat
  496.         elif [ "$webserver" = "2" ]; then
  497.             apache_config_redhat
  498.         fi
  499.     fi
  500. }
  501.  
  502. nginx_config() {
  503.     output "Disabling default configuration"
  504.     rm -rf /etc/nginx/sites-enabled/default
  505.     output "Configuring Nginx Webserver"
  506.    
  507. echo '
  508. server_tokens off;
  509.  
  510. server {
  511.    listen 80;
  512.    server_name '"$FQDN"';
  513.    return 301 https://$server_name$request_uri;
  514. }
  515.  
  516. server {
  517.    listen 443 ssl http2;
  518.    server_name '"$FQDN"';
  519.  
  520.    root /var/www/pterodactyl/public;
  521.    index index.php;
  522.  
  523.    access_log /var/log/nginx/pterodactyl.app-access.log;
  524.    error_log  /var/log/nginx/pterodactyl.app-error.log error;
  525.  
  526.    # allow larger file uploads and longer script runtimes
  527.    client_max_body_size 100m;
  528.    client_body_timeout 120s;
  529.  
  530.    sendfile off;
  531.  
  532.    # SSL Configuration
  533.    ssl_certificate /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem;
  534.    ssl_certificate_key /etc/letsencrypt/live/'"$FQDN"'/privkey.pem;
  535.    ssl_session_cache shared:SSL:10m;
  536.    ssl_protocols TLSv1.2;
  537.    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
  538.    ssl_prefer_server_ciphers on;
  539.  
  540.    # See https://hstspreload.org/ before uncommenting the line below.
  541.    # add_header Strict-Transport-Security "max-age=15768000; preload;";
  542.    add_header X-Content-Type-Options nosniff;
  543.    add_header X-XSS-Protection "1; mode=block";
  544.    add_header X-Robots-Tag none;
  545.    add_header Content-Security-Policy "frame-ancestors 'self'";
  546.    add_header X-Frame-Options DENY;
  547.    add_header Referrer-Policy same-origin;
  548.  
  549.    location / {
  550.        try_files $uri $uri/ /index.php?$query_string;
  551.    }
  552.  
  553.    location ~ \.php$ {
  554.        fastcgi_split_path_info ^(.+\.php)(/.+)$;
  555.        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  556.        fastcgi_index index.php;
  557.        include fastcgi_params;
  558.        fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  559.        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  560.        fastcgi_param HTTP_PROXY "";
  561.        fastcgi_intercept_errors off;
  562.        fastcgi_buffer_size 16k;
  563.        fastcgi_buffers 4 16k;
  564.        fastcgi_connect_timeout 300;
  565.        fastcgi_send_timeout 300;
  566.        fastcgi_read_timeout 300;
  567.        include /etc/nginx/fastcgi_params;
  568.    }
  569.  
  570.    location ~ /\.ht {
  571.        deny all;
  572.    }
  573. }
  574. ' | sudo -E tee /etc/nginx/sites-available/pterodactyl.conf >/dev/null 2>&1
  575.  
  576.     ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
  577.     service nginx restart
  578. }
  579.  
  580. apache_config() {
  581.     output "Disabling default configuration"
  582.     rm -rf /etc/nginx/sites-enabled/default
  583.     output "Configuring Apache2"
  584. echo '
  585. <VirtualHost *:80>
  586. ServerName '"$FQDN"'
  587. RewriteEngine On
  588. RewriteCond %{HTTPS} !=on
  589. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  590. </VirtualHost>
  591.  
  592. <VirtualHost *:443>
  593.  DocumentRoot "/var/www/pterodactyl/public"
  594.  AllowEncodedSlashes On
  595.  php_value upload_max_filesize 100M
  596.  php_value post_max_size 100M
  597.  <Directory "/var/www/pterodactyl/public">
  598.    AllowOverride all
  599.  </Directory>
  600.  
  601. SSLEngine on
  602. SSLCertificateFile /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem
  603. SSLCertificateKeyFile /etc/letsencrypt/live/'"$FQDN"'/privkey.pem
  604. ServerName '"$FQDN"'
  605. </VirtualHost>
  606.  
  607. ' | sudo -E tee /etc/apache2/sites-available/pterodactyl.conf >/dev/null 2>&1
  608.    
  609.     ln -s /etc/apache2/sites-available/pterodactyl.conf /etc/apache2/sites-enabled/pterodactyl.conf
  610.     a2enmod ssl
  611.     a2enmod rewrite
  612.     service apache2 restart
  613. }
  614.  
  615. nginx_config_redhat(){
  616.     output "Configuring Nginx Webserver"
  617.    
  618. echo '
  619. server {
  620.    listen 80;
  621.    server_name '"$FQDN"';
  622.    return 301 https://$server_name$request_uri;
  623. }
  624.  
  625. server {
  626.    listen 443 ssl http2;
  627.    server_name '"$FQDN"';
  628.  
  629.    root /var/www/pterodactyl/public;
  630.    index index.php;
  631.  
  632.    access_log /var/log/nginx/pterodactyl.app-access.log;
  633.    error_log  /var/log/nginx/pterodactyl.app-error.log error;
  634.  
  635.    # allow larger file uploads and longer script runtimes
  636.    client_max_body_size 100m;
  637.    client_body_timeout 120s;
  638.    
  639.    sendfile off;
  640.  
  641.    # strengthen ssl security
  642.    ssl_certificate /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem;
  643.    ssl_certificate_key /etc/letsencrypt/live/'"$FQDN"'/privkey.pem;
  644.    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  645.    ssl_prefer_server_ciphers on;
  646.    ssl_session_cache shared:SSL:10m;
  647.    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
  648.    
  649.    # See the link below for more SSL information:
  650.    #     https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
  651.    #
  652.    # ssl_dhparam /etc/ssl/certs/dhparam.pem;
  653.  
  654.    # Add headers to serve security related headers
  655.    add_header Strict-Transport-Security "max-age=15768000; preload;";
  656.    add_header X-Content-Type-Options nosniff;
  657.    add_header X-XSS-Protection "1; mode=block";
  658.    add_header X-Robots-Tag none;
  659.    add_header Content-Security-Policy "frame-ancestors 'self'";
  660.  
  661.    location / {
  662.        try_files $uri $uri/ /index.php?$query_string;
  663.    }
  664.  
  665.    location ~ \.php$ {
  666.        fastcgi_split_path_info ^(.+\.php)(/.+)$;
  667.        fastcgi_pass unix:/var/run/php-fpm/pterodactyl.sock;
  668.        fastcgi_index index.php;
  669.        include fastcgi_params;
  670.        fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  671.        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  672.        fastcgi_param HTTP_PROXY "";
  673.        fastcgi_intercept_errors off;
  674.        fastcgi_buffer_size 16k;
  675.        fastcgi_buffers 4 16k;
  676.        fastcgi_connect_timeout 300;
  677.        fastcgi_send_timeout 300;
  678.        fastcgi_read_timeout 300;
  679.        include /etc/nginx/fastcgi_params;
  680.    }
  681.  
  682.    location ~ /\.ht {
  683.        deny all;
  684.    }
  685. }
  686. ' | sudo -E tee /etc/nginx/conf.d/pterodactyl.conf >/dev/null 2>&1
  687.  
  688.     service nginx restart
  689.     chown -R nginx:nginx $(pwd)
  690.     semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  691.     restorecon -R /var/www/pterodactyl
  692. }
  693.  
  694. apache_config_redhat() {
  695.     output "Configuring Apache2"
  696. echo '
  697. <VirtualHost *:80>
  698. ServerName '"$FQDN"'
  699. RewriteEngine On
  700. RewriteCond %{HTTPS} !=on
  701. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  702. </VirtualHost>
  703.  
  704. <VirtualHost *:443>
  705.  DocumentRoot "/var/www/pterodactyl/public"
  706.  AllowEncodedSlashes On
  707.  <Directory "/var/www/pterodactyl/public">
  708.    AllowOverride all
  709.  </Directory>
  710.  
  711. SSLEngine on
  712. SSLCertificateFile /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem
  713. SSLCertificateKeyFile /etc/letsencrypt/live/'"$FQDN"'/privkey.pem
  714. ServerName '"$FQDN"'
  715. </VirtualHost>
  716.  
  717. ' | sudo -E tee /etc/httpd/conf.d/pterodactyl.conf >/dev/null 2>&1
  718.     service httpd restart
  719. }
  720.  
  721. php_config(){
  722.     output "Configuring PHP socket."
  723.     bash -c 'cat > /etc/php-fpm.d/www-pterodactyl.conf' <<-'EOF'
  724. [pterodactyl]
  725.  
  726. user = nginx
  727. group = nginx
  728.  
  729. listen = /var/run/php-fpm/pterodactyl.sock
  730. listen.owner = nginx
  731. listen.group = nginx
  732. listen.mode = 0750
  733.  
  734. pm = ondemand
  735. pm.max_children = 9
  736. pm.process_idle_timeout = 10s
  737. pm.max_requests = 200
  738. EOF
  739.     systemctl restart php-fpm
  740. }
  741.  
  742. install_daemon() {
  743.     cd /root
  744.     output "Installing Pterodactyl Daemon dependencies."
  745.     if  [ "$lsb_dist" =  "ubuntu" ] ||  [ "$lsb_dist" =  "debian" ]; then
  746.         apt-get -y install curl tar unzip
  747.     elif  [ "$lsb_dist" =  "fedora" ] ||  [ "$lsb_dist" =  "centos" ] ||  [ "$lsb_dist" =  "rhel" ]; then
  748.         yum -y install curl tar unzip
  749.     fi
  750.     output "Installing Docker"
  751.     curl -sSL https://get.docker.com/ | CHANNEL=stable bash
  752.     systemctl enable docker
  753.     systemctl start docker
  754.     output "Enabling Swap support for Docker & Installing NodeJS."
  755.     sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& swapaccount=1/' /etc/default/grub
  756.     if  [ "$lsb_dist" =  "ubuntu" ] ||  [ "$lsb_dist" =  "debian" ]; then
  757.         sudo update-grub
  758.         curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
  759.         apt -y install nodejs make gcc g++ node-gyp
  760.         apt-get -y update
  761.         apt-get -y upgrade
  762.         apt-get -y autoremove
  763.         apt-get -y autoclean
  764.     elif  [ "$lsb_dist" =  "fedora" ] ||  [ "$lsb_dist" =  "centos" ] ||  [ "$lsb_dist" =  "rhel" ]; then
  765.         grub2-mkconfig -o "$(readlink /etc/grub2.conf)"
  766.         curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
  767.         yum -y install nodejs gcc-c++ make
  768.         yum -y upgrade
  769.         yum -y autoremove
  770.         yum -y clean packages
  771.     fi
  772.     output "Installing the Pterodactyl Daemon."
  773.     mkdir -p /srv/daemon /srv/daemon-data
  774.     cd /srv/daemon
  775.     curl -L https://github.com/pterodactyl/daemon/releases/download/v0.6.12/daemon.tar.gz | tar --strip-components=1 -xzv
  776.     npm install --only=production
  777.     if [ "$lsb_dist" =  "ubuntu" ] && [ "$dist_version" = "14.04" ]; then
  778.         npm install -g forever
  779.     else
  780.         bash -c 'cat > /etc/systemd/system/wings.service' <<-'EOF'
  781. [Unit]
  782. Description=Pterodactyl Wings Daemon
  783. After=docker.service
  784.  
  785. [Service]
  786. User=root
  787. #Group=some_group
  788. WorkingDirectory=/srv/daemon
  789. LimitNOFILE=4096
  790. PIDFile=/var/run/wings/daemon.pid
  791. ExecStart=/usr/bin/node /srv/daemon/src/index.js
  792. Restart=on-failure
  793. StartLimitInterval=600
  794.  
  795. [Install]
  796. WantedBy=multi-user.target
  797. EOF
  798.  
  799.         systemctl daemon-reload
  800.         systemctl enable wings
  801.     fi
  802.     if [ "$lsb_dist" =  "debian" ] && [ "$dist_version" = "8" ]; then
  803.         kernel_modifications_d8
  804.     fi
  805. }
  806.  
  807. upgrade_daemon(){
  808.     cd /srv/daemon
  809.     if [ "$lsb_dist" =  "ubuntu" ] && [ "$dist_version" = "14.04" ]; then
  810.         forever stop src/index.js
  811.     else
  812.     service wings stop
  813.     fi
  814.     curl -L https://github.com/pterodactyl/daemon/releases/download/v0.6.12/daemon.tar.gz | tar --strip-components=1 -xzv
  815.     npm install --only=production
  816.     if [ "$lsb_dist" =  "ubuntu" ] && [ "$dist_version" = "14.04" ]; then
  817.         forever start src/index.js
  818.     else
  819.     service wings restart
  820.     fi
  821.     output "Your daemon has been updated to version 0.6.12."
  822. }
  823.  
  824. install_standalone_sftp(){
  825.     cd /srv/daemon
  826.     output "Disabling default SFTP server."
  827.     $text="\ \ \"enabled\": false,"
  828.     sed -i '/"port": 2022,/a\\        "enabled": false,' /srv/daemon/config/core.json
  829.     service wings restart
  830.     output "Installing standalone SFTP server."
  831.     curl -Lo sftp-server https://github.com/pterodactyl/sftp-server/releases/download/v1.0.4/sftp-server
  832.     chmod +x sftp-server
  833.     bash -c 'cat > /etc/systemd/system/pterosftp.service' <<-'EOF'
  834. [Unit]
  835. Description=Pterodactyl Standalone SFTP Server
  836. After=wings.service
  837.  
  838. [Service]
  839. User=root
  840. WorkingDirectory=/srv/daemon
  841. LimitNOFILE=4096
  842. PIDFile=/var/run/wings/sftp.pid
  843. ExecStart=/srv/daemon/sftp-server
  844. Restart=on-failure
  845. StartLimitInterval=600
  846.  
  847. [Install]
  848. WantedBy=multi-user.target
  849. EOF
  850.     systemctl enable --now pterosftp
  851.     service pterosftp restart
  852. }
  853.  
  854. upgrade_standalone_sftp(){
  855.     output "Turning off the standalone SFTP server."
  856.     service pterosftp stop
  857.     curl -Lo sftp-server https://github.com/pterodactyl/sftp-server/releases/download/v1.0.4/sftp-server
  858.     chmod +x sftp-server
  859.     service pterosftp start
  860.     output "Your standalone SFTP server has been updated to v1.0.4"
  861. }
  862.  
  863. kernel_modifications_d8(){
  864.     output "Modifying Grub."
  865.     sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& cgroup_enable=memory/' /etc/default/grub  
  866.     output "Adding backport repositories."
  867.     echo deb http://http.debian.net/debian jessie-backports main > /etc/apt/sources.list.d/jessie-backports.list
  868.     echo deb http://http.debian.net/debian jessie-backports main contrib non-free > /etc/apt/sources.list.d/jessie-backports.list
  869.     output "Updating Server Packages."
  870.     apt-get -y update
  871.     apt-get -y upgrade
  872.     apt-get -y autoremove
  873.     apt-get -y autoclean
  874.     output"Installing new kernel"
  875.     apt install -t jessie-backports linux-image-4.9.0-0.bpo.7-amd64
  876.     output "Modifying Docker."
  877.     sed -i 's,/usr/bin/dockerd,/usr/bin/dockerd --storage-driver=overlay2,g' /lib/systemd/system/docker.service
  878.     systemctl daemon-reload
  879.     service docker start
  880. }
  881.  
  882. ssl_certs(){
  883.     output "Installing LetsEncrypt and creating an SSL certificate."
  884.         apt-get -y install certbot
  885.  
  886.     if [ "$webserver" = "1" ]; then
  887.         service nginx stop
  888.     elif [ "$webserver" = "2" ]; then
  889.             service apache2 stop
  890.  
  891.     fi
  892.     certbot certonly --standalone --email "$email" --agree-tos -d "$FQDN" --non-interactive
  893.     service nginx restart
  894.     service apache2 restart
  895. }
  896.  
  897. firewall(){
  898.     rm -rf /etc/rc.local
  899.     printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
  900.     chmod +x /etc/rc.local
  901.  
  902.  
  903.     output "Configuring your firewall."
  904.    
  905. }
  906.  
  907. mariadb_root_reset(){
  908.     service mariadb stop
  909.     mysqld_safe --skip-grant-tables >res 2>&1 &
  910.     sleep 5
  911.     rootpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  912.     Q1="UPDATE user SET plugin='';"
  913.     Q2="UPDATE user SET password=PASSWORD('$rootpassword') WHERE user='root';"
  914.     Q3="FLUSH PRIVILEGES;"
  915.     SQL="${Q1}${Q2}${Q3}"
  916.     mysql mysql -e "$SQL"
  917.     pkill mysqld
  918.     service mariadb restart
  919.     output "Your MariaDB root password is $rootpassword"
  920. }
  921.  
  922. broadcast(){
  923.     if [ "$installoption" = "1" ] || [ "$installoption" = "3" ]; then
  924.         output "Your MariaDB root password is $rootpassword"
  925.     fi
  926. }
  927.  
  928. broadcast_daemon(){
  929.     output "Installation completed. Please configure the daemon. "
  930.     output "The guide for daemon configuration can be founded here: https://pterodactyl.io/daemon/installing.html#configure-daemon"  
  931.     if [ "$lsb_dist" =  "ubuntu" ] && [ "$dist_version" = "14.04" ]; then
  932.         output "Please run 'forever start src/index.js' after the configuration process is finished."
  933.     else
  934.         output "Please run 'service wings restart' after the configuration."  
  935.         if [ "$lsb_dist" =  "debian" ] && [ "$dist_version" = "8" ]; then
  936.             output "Please restart the server after you have configured the daemon to apply the necessary kernel changes on Debian 8."
  937.         fi
  938.     fi
  939.                          
  940. }
  941.  
  942. #Execution
  943. copyright
  944. get_distribution
  945. check_root
  946. get_architecture
  947. server_options
  948. case $installoption in
  949.     1)  webserver_options
  950.         theme_options
  951.         required_infos
  952.         repositories_setup
  953.         firewall
  954.         install_dependencies
  955.         install_pterodactyl
  956.         pterodactyl_queue
  957.         ssl_certs
  958.         webserver_config
  959.         theme
  960.         broadcast
  961.         ;;
  962.     2)  get_virtualization
  963.         required_infos
  964.         repositories_setup
  965.         firewall
  966.         ssl_certs
  967.         install_daemon
  968.         broadcast
  969.         broadcast_daemon
  970.         ;;
  971.     3)  get_virtualization
  972.         webserver_options
  973.         theme_options
  974.         required_infos
  975.         repositories_setup
  976.         firewall
  977.         install_dependencies
  978.         install_pterodactyl
  979.         pterodactyl_queue
  980.         ssl_certs
  981.         webserver_config
  982.         theme
  983.         install_daemon
  984.         broadcast
  985.         broadcast_daemon
  986.         ;;
  987.     4)  install_standalone_sftp
  988.         ;;
  989.     5)  theme_options
  990.         upgrade_pterodactyl
  991.         theme
  992.         ;;
  993.     6)  upgrade_daemon
  994.         ;;
  995.     7)  upgrade_standalone_sftp
  996.         ;;
  997.     8)  theme_options
  998.         theme
  999.         if [ "$themeoption" = "1" ]; then
  1000.             upgrade_pterodactyl
  1001.         fi
  1002.         ;;
  1003.     9)  mariadb_root_reset
  1004.         ;;
  1005. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement