Morales Digital Technologies Morales CodeHub
172 lines · 7.4 KB
1#!/bin/bash
2
3set -e
4
5RED='\033[0;31m'
6YELLOW='\033[1;33m'
7GREEN='\033[0;32m'
8LIGHT_BLUE='\033[1;34m'
9NC='\033[0m'
10
11prompt() {
12 local PROMPT_MESSAGE=$1
13 local DEFAULT_VALUE=$2
14 read -p "$PROMPT_MESSAGE [$DEFAULT_VALUE]: " INPUT
15 echo "${INPUT:-$DEFAULT_VALUE}"
16}
17
18confirm_clean_install() {
19 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
20 echo -e ${LIGHT_BLUE}" Pterodactyl Wings Installer for Debian 12 by VS-Shop ${NC}"
21 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
22 echo -e "${YELLOW}This installation script requires a clean installation of Debian 12 (Bookworm).${NC}"
23 echo -e "${YELLOW}Please confirm you are running it on a fresh system.${NC}"
24 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
25
26 while true; do
27 read -p "Is this a clean installation of Debian 12? (Y/N): " response
28 case $response in
29 [Yy]* ) break;;
30 [Nn]* ) echo -e "${RED}Please reinstall Debian 12 and run the script again.${NC}"; exit;;
31 * ) echo -e "${RED}Please answer with 'Y' (Yes) or 'N' (No).${NC}";;
32 esac
33 done
34}
35
36confirm_clean_install
37
38WINGS_DOMAIN=$(prompt "Enter the domain name you want to use for Wings (e.g., wings.example.com). Leave blank if not using a public domain for Wings." "")
39if [ -n "$WINGS_DOMAIN" ]; then
40 ADMIN_EMAIL=$(prompt "Enter an email address for Certbot to use for Wings (for urgent renewal notices and security advisories)" "me@anthony-morales.online") # Corrected default email
41fi
42
43echo -e "${GREEN}Updating system and installing dependencies...${NC}"
44apt update && apt upgrade -y
45apt install -y curl sudo gnupg lsb-release ca-certificates
46
47echo -e "${GREEN}Installing Docker (from official source)...${NC}"
48if ! command -v docker &> /dev/null; then
49 curl -fsSL https://get.docker.com | bash
50else
51 echo -e "${YELLOW}Docker appears to be already installed. Skipping Docker installation.${NC}"
52fi
53
54echo -e "${GREEN}Enabling Docker...${NC}"
55systemctl enable --now docker
56
57echo -e "${GREEN}Installing Wings...${NC}"
58mkdir -p /etc/pterodactyl
59ARCH=$(uname -m)
60ARCH_TYPE=$([[ "$ARCH" == "x86_64" ]] && echo "amd64" || echo "arm64")
61
62curl -L -o /usr/local/bin/wings "https://github.com/pterodactyl/wings/releases/latest/download/wings_linux_${ARCH_TYPE}"
63chmod +x /usr/local/bin/wings
64
65echo -e "${GREEN}Creating systemd service file for Wings...${NC}"
66cat > /etc/systemd/system/wings.service <<EOF
67[Unit]
68Description=Pterodactyl Wings Daemon
69After=docker.service
70Requires=docker.service
71
72[Service]
73User=root
74WorkingDirectory=/etc/pterodactyl
75LimitNOFILE=4096
76ExecStart=/usr/local/bin/wings
77Restart=on-failure
78StartLimitInterval=180
79StartLimitBurst=30
80RestartSec=5s
81
82[Install]
83WantedBy=multi-user.target
84EOF
85
86echo -e "${GREEN}Enabling Wings service...${NC}"
87systemctl enable --now wings
88
89if [ -n "$WINGS_DOMAIN" ]; then
90 echo -e "${GREEN}Installing Certbot...${NC}"
91 apt install -y certbot
92
93 WEB_SERVICE=""
94 if systemctl is-active --quiet nginx; then
95 WEB_SERVICE="nginx"
96 elif systemctl is-active --quiet apache2; then
97 WEB_SERVICE="apache2"
98 fi
99
100 if [ -n "$WEB_SERVICE" ]; then
101 echo -e "${YELLOW}Stopping $WEB_SERVICE temporarily to free up port 80 for Certbot...${NC}"
102 systemctl stop "$WEB_SERVICE"
103 else
104 echo -e "${YELLOW}No common web server (Nginx/Apache) found running on port 80. Proceeding with Certbot standalone.${NC}"
105 fi
106
107 echo -e "${GREEN}Stopping Wings temporarily for Certbot standalone validation...${NC}"
108 systemctl stop wings || true
109
110 echo -e "${GREEN}Obtaining SSL certificate for Wings domain using Certbot's standalone authenticator...${NC}"
111 certbot certonly --standalone --agree-tos --email "$ADMIN_EMAIL" -d "$WINGS_DOMAIN" --force-renewal
112
113 CERTBOT_STATUS=$?
114
115 if [ -n "$WEB_SERVICE" ]; then
116 echo -e "${YELLOW}Starting $WEB_SERVICE back up...${NC}"
117 systemctl start "$WEB_SERVICE"
118 fi
119
120 echo -e "${GREEN}Restarting Wings service...${NC}"
121 systemctl start wings
122
123 if [ $CERTBOT_STATUS -eq 0 ]; then
124 echo -e "${GREEN}SSL certificate for Wings domain obtained successfully!${NC}"
125 echo -e "${YELLOW}IMPORTANT: You must manually update your /etc/pterodactyl/config.yml to use these SSL certificates.${NC}"
126 echo -e "${YELLOW} Certificate Path: /etc/letsencrypt/live/$WINGS_DOMAIN/fullchain.pem${NC}"
127 echo -e "${YELLOW} Key Path: /etc/letsencrypt/live/$WINGS_DOMAIN/privkey.pem${NC}"
128 echo -e "${YELLOW} Ensure 'api.listen_address' is set to use HTTPS (e.g., 0.0.0.0:8443) in config.yml.${NC}"
129 echo -e "${YELLOW} After updating config.yml, restart Wings: systemctl restart wings${NC}"
130 else
131 echo -e "${RED}Failed to obtain SSL certificate for Wings domain (Certbot exit code: $CERTBOT_STATUS). Please check your DNS and ensure port 80 is open and not in use by any unexpected process.${NC}"
132 echo -e "${RED}Wings will proceed without a Let's Encrypt certificate for the domain. You will need to configure SSL manually later if desired.${NC}"
133 fi
134else
135 echo -e "${YELLOW}No domain provided for Wings. Skipping Certbot installation for Wings.${NC}"
136fi
137
138confirm_wings_configuration() {
139 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
140 echo -e ${LIGHT_BLUE}" Pterodactyl Wings Configuration Reminder ${NC}"
141 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
142 echo -e "${YELLOW}1. Open a new terminal and connect to this server.${NC}"
143 echo -e "${YELLOW}2. Log in to your Pterodactyl Panel and create a Location and a Node.${NC}"
144 echo -e "${YELLOW}3. Navigate to Nodes > Your Node > Configuration tab.${NC}"
145 echo -e "${YELLOW}4. Download or copy the config and paste it to: /etc/pterodactyl/config.yml${NC}"
146 if [ -n "$WINGS_DOMAIN" ]; then
147 echo -e "${YELLOW}5. IMPORTANT: Since you obtained a Let's Encrypt SSL certificate for Wings,${NC}"
148 echo -e "${YELLOW} you MUST edit the /etc/pterodactyl/config.yml file. Find the 'api' section${NC}"
149 echo -e "${YELLOW} and update 'certificate' and 'key' paths to point to the Let's Encrypt certificates:${NC}"
150 echo -e "${YELLOW} certificate: /etc/letsencrypt/live/$WINGS_DOMAIN/fullchain.pem${NC}"
151 echo -e "${YELLOW} key: /etc/letsencrypt/live/$WINGS_DOMAIN/privkey.pem${NC}"
152 echo -e "${YELLOW}6. Save the config.yml file. Then, run 'systemctl restart wings'.${NC}"
153 echo -e "${YELLOW}7. Come back to this window to continue.${NC}"
154 else
155 echo -e "${YELLOW}5. Save and come back to this window to continue.${NC}"
156 fi
157 echo -e ${LIGHT_BLUE}"=================================================================${NC}"
158
159 while true; do
160 read -p "Have you completed the Node Configuration and any necessary SSL updates for Wings? (Y/N): " response
161 case $response in
162 [Yy]* ) break;;
163 [Nn]* ) echo -e "${RED}Please complete the Node Configuration and run the script again.${NC}"; exit;;
164 * ) echo -e "${RED}Please answer with 'Y' (Yes) or 'N' (No).${NC}";;
165 esac
166 done
167}
168
169confirm_wings_configuration
170
171echo -e "${GREEN}Pterodactyl Wings Configuration completed successfully!${NC}"
172echo -e "${GREEN}Pterodactyl Wings is now installed and running on Debian 12.${NC}"