Morales Digital Technologies Morales CodeHub
186 lines · 6.4 KB
1#!/bin/bash
2set -e
3
4RED='\033[0;31m'
5YELLOW='\033[1;33m'
6GREEN='\033[0;32m'
7LIGHT_BLUE='\033[1;34m'
8NC='\033[0m'
9
10prompt() {
11 local PROMPT_MESSAGE=$1
12 local DEFAULT_VALUE=$2
13 read -p "$PROMPT_MESSAGE [$DEFAULT_VALUE]: " INPUT
14 echo "${INPUT:-$DEFAULT_VALUE}"
15}
16
17confirm_clean_install() {
18 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
19 echo -e ${LIGHT_BLUE}" Pterodactyl Panel Installer v1.2.0 for Debian 12 by VS-Shop${NC}"
20 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
21 echo -e "${YELLOW}This script is built for a clean installation of Debian 12 (Bookworm).${NC}"
22 echo -e "${YELLOW}Please confirm your system matches this requirement.${NC}"
23 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
24
25 while true; do
26 read -p "Is this a clean installation of Debian 12? (Y/N): " response
27 case $response in
28 [Yy]* ) break;;
29 [Nn]* ) echo -e "${RED}Please reinstall Debian 12 and run the script again.${NC}"; exit;;
30 * ) echo -e "${RED}Please answer with 'Y' (Yes) or 'N' (No).${NC}";;
31 esac
32 done
33}
34
35confirm_clean_install
36
37DOMAIN=$(prompt "Enter the domain name you want to use for the Pterodactyl panel (e.g., panel.example.com)" "panel.example.com")
38ADMIN_EMAIL=$(prompt "Enter an email address for Certbot to use (for urgent renewal notices and security advisories)" "admin@example.com")
39
40echo -e "${GREEN}Updating system and installing base dependencies...${NC}"
41apt update
42apt -y install curl gnupg apt-transport-https ca-certificates lsb-release software-properties-common sudo unzip git tar cron
43
44echo -e "${GREEN}Installing PHP 8.3 and required extensions...${NC}"
45echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/sury-php.list
46curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-php.gpg
47
48apt update
49apt -y install php8.3 php8.3-{cli,common,gd,mysql,mbstring,bcmath,xml,fpm,curl,zip}
50
51echo -e "${GREEN}Installing MariaDB, NGINX, Redis...${NC}"
52apt -y install mariadb-server nginx redis-server
53
54echo -e "${GREEN}Installing Composer...${NC}"
55curl -sS https://getcomposer.org/installer | php
56mv composer.phar /usr/local/bin/composer
57
58echo -e "${GREEN}Creating Pterodactyl installation directory...${NC}"
59mkdir -p /var/www/pterodactyl
60cd /var/www/pterodactyl
61
62echo -e "${GREEN}Downloading Pterodactyl panel...${NC}"
63curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz
64tar -xzvf panel.tar.gz
65chmod -R 755 storage/* bootstrap/cache/
66
67echo -e "${GREEN}Setting up the MySQL database for Pterodactyl...${NC}"
68DB_USER=$(prompt "Enter the MySQL user for Pterodactyl" "pterodactyl")
69DB_PASSWORD=$(prompt "Enter the MySQL password for $DB_USER" "yourPassword")
70DB_NAME=$(prompt "Enter the database name for Pterodactyl" "panel")
71
72mysql -u root <<MYSQL_SCRIPT
73CREATE USER '${DB_USER}'@'127.0.0.1' IDENTIFIED BY '${DB_PASSWORD}';
74CREATE DATABASE ${DB_NAME};
75GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'127.0.0.1' WITH GRANT OPTION;
76FLUSH PRIVILEGES;
77MYSQL_SCRIPT
78
79echo -e "${GREEN}Installing Composer dependencies...${NC}"
80cp .env.example .env
81COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
82
83echo -e "${GREEN}Generating application key...${NC}"
84php artisan key:generate --force
85
86echo -e "${GREEN}Running environment setup...${NC}"
87php artisan p:environment:setup
88
89echo -e "${GREEN}Running database setup...${NC}"
90php artisan p:environment:database
91
92echo -e "${GREEN}Setting up mail environment...${NC}"
93php artisan p:environment:mail
94
95echo -e "${GREEN}Migrating and seeding database...${NC}"
96php artisan migrate --seed --force
97
98echo -e "${GREEN}Creating Pterodactyl admin user...${NC}"
99php artisan p:user:make
100
101echo -e "${GREEN}Setting ownership of Pterodactyl files...${NC}"
102chown -R www-data:www-data /var/www/pterodactyl/*
103
104echo -e "${GREEN}Setting up cron job for schedule...${NC}"
105(crontab -l ; echo "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1") | crontab -
106
107echo -e "${GREEN}Creating systemd service for queue worker...${NC}"
108cat <<EOF | tee /etc/systemd/system/pteroq.service
109[Unit]
110Description=Pterodactyl Queue Worker
111After=redis-server.service
112
113[Service]
114User=www-data
115Group=www-data
116Restart=always
117ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
118StartLimitInterval=180
119StartLimitBurst=30
120RestartSec=5s
121
122[Install]
123WantedBy=multi-user.target
124EOF
125
126systemctl enable --now redis-server
127systemctl enable --now pteroq.service
128
129echo -e "${GREEN}Creating Nginx configuration for Certbot...${NC}"
130cat > /etc/nginx/sites-available/pterodactyl.conf <<EOF
131server {
132 listen 80;
133 server_name $DOMAIN;
134
135 root /var/www/pterodactyl/public;
136 index index.html index.htm index.php;
137 charset utf-8;
138
139 location / {
140 try_files \$uri \$uri/ /index.php?\$query_string;
141 }
142
143 location = /favicon.ico { access_log off; log_not_found off; }
144 location = /robots.txt { access_log off; log_not_found off; }
145
146 access_log off;
147 error_log /var/log/nginx/pterodactyl.app-error.log error;
148
149 client_max_body_size 100m;
150 client_body_timeout 120s;
151
152 sendfile off;
153
154 location ~ \.php\$ {
155 fastcgi_split_path_info ^(.+\.php)(/.+)\$;
156 fastcgi_pass unix:/run/php/php8.3-fpm.sock;
157 fastcgi_index index.php;
158 include fastcgi_params;
159 fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
160 fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
161 fastcgi_param HTTP_PROXY "";
162 fastcgi_intercept_errors off;
163 fastcgi_buffer_size 16k;
164 fastcgi_buffers 4 16k;
165 fastcgi_connect_timeout 300;
166 fastcgi_send_timeout 300;
167 fastcgi_read_timeout 300;
168 }
169
170 location ~ /\.ht {
171 deny all;
172 }
173}
174EOF
175
176ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
177systemctl restart nginx
178
179echo -e "${GREEN}Installing Certbot...${NC}"
180apt -y install certbot python3-certbot-nginx
181
182echo -e "${GREEN}Obtaining SSL certificate using Certbot...${NC}"
183certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email "$ADMIN_EMAIL" -d "$DOMAIN"
184
185echo -e "${GREEN}Pterodactyl Installation complete on Debian!${NC}"
186echo -e "${LIGHT_BLUE}Visit: https://$DOMAIN to begin setup.${NC}"