feat(setup-pterodactyl-wings): Add network configuration and directory setup (#27)

This commit adds a new script `run.sh` that handles the network configuration and directory setup for Pterodactyl Wings. The key changes include:

- Checks if a UUID argument is provided and exits with an error if not
- Implements functions to check if a subnet is in use, find an available subnet, and get the gateway for a subnet
- Creates the `pterodactyl_nw` Docker network with the available subnet and gateway
- Creates the required directories for Pterodactyl (/var/lib/pterodactyl/volumes, /tmp/pterodactyl, /etc/pterodactyl, /var/log/pterodactyl)
- Sets the appropriate ownership for the created directories
- Restarts the `pterodactyl-wings` container to apply the changes

This script simplifies the setup process for Pterodactyl Wings and helps ensure the network configuration and directory structure are properly set up.
This commit is contained in:
Christopher
2025-01-09 11:59:39 -06:00
committed by GitHub
parent 7ffdd617f4
commit 4d723e08cb
2 changed files with 233 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
# Setup Pterodactyl Wings
This script helps set up the network configuration and directories required for Pterodactyl Wings. It handles network conflict resolution, proper directory permissions, and container management automatically.
## Prerequisites
- Docker installed and running
- Root/sudo access
- wget installed
## Usage
You can run the script directly using wget:
```bash
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/setup-pterodactyl-wings/run.sh)" -- <uuid>
```
Replace `<uuid>` with your server's UUID from the Pterodactyl panel.
Example:
```bash
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/setup-pterodactyl-wings/run.sh)" -- 123e4567-e89b-12d3-a456-426614174000
```
## What the Script Does
1. Creates required Pterodactyl directories with proper permissions
2. Sets up Docker network `pterodactyl_nw` with proper IPv4/IPv6 configuration
3. Automatically resolves network conflicts:
- Detects conflicting Docker networks
- Removes unused conflicting networks
- Provides clear instructions if manual intervention is needed
4. Restarts the pterodactyl-wings container to apply changes
## Network Configuration
The script automatically creates a Docker network with the following specifications:
- Network name: `pterodactyl_nw`
- IPv4 subnet: Automatically selected from available ranges (172.40-47.0.0/16)
- IPv4 gateway: Automatically configured based on selected subnet
- IPv6 subnet: fd00::/64
- IPv6 gateway: fd00::1
- Bridge name: pterodactyl0
The script intelligently:
1. Checks existing Docker networks and system routes for conflicts
2. Automatically selects an available subnet from a predefined list of private ranges
3. Reconfigures the network if conflicts are detected
4. Provides clear status messages during the setup process
## Troubleshooting
If you encounter issues, the script will provide clear error messages and instructions:
1. Network Configuration Issues:
- The script will automatically try different subnet ranges
- Clear messages show which subnet is being used
- Detailed error messages if network creation fails
2. Container Restart Issues:
- If the pterodactyl-wings container fails to restart, you'll get instructions for manual restart
- Use `docker restart pterodactyl-wings` if needed
Common error messages and solutions:
- "Could not find available subnet": All predefined subnets are in use, contact support
- "Failed to create network": Check Docker logs and ensure Docker is running properly
- "Failed to restart pterodactyl-wings container": Ensure the container exists and try restarting manually
## Support
For issues or questions, please open an issue on [BigBearCommunity](https://community.bigbeartechworld.com/).

View File

@@ -0,0 +1,158 @@
#!/bin/bash
# Check if exactly one argument (UUID) is provided to the script
if [ $# -ne 1 ]; then
echo "Error: UUID argument is required"
echo "Usage: $0 <uuid>"
exit 1
fi
UUID=$1
# Function to check if a subnet is in use
is_subnet_in_use() {
local subnet=$1
local network_name=$2
local subnet_base=${subnet%/*}
# Check system routes first
while read -r route; do
if [[ "$route" == *"$subnet_base"* ]]; then
local iface=$(echo "$route" | grep -o "dev [^ ]*" | cut -d' ' -f2)
if [ -n "$iface" ] && [ "$iface" != "pterodactyl0" ]; then
return 0
fi
fi
done < <(ip route show)
# Check Docker networks
while read -r other_network; do
if [ "$other_network" != "$network_name" ]; then
if docker network inspect "$other_network" 2>/dev/null | grep -q "\"Subnet\": \"$subnet\""; then
return 0
fi
fi
done < <(docker network ls --format "{{.Name}}")
return 1
}
# Function to find an available subnet
find_available_subnet() {
local network_name=$1
local subnet_ranges=(
"172.40.0.0/16"
"172.41.0.0/16"
"172.42.0.0/16"
"172.43.0.0/16"
"172.44.0.0/16"
"172.45.0.0/16"
"172.46.0.0/16"
"172.47.0.0/16"
)
for subnet in "${subnet_ranges[@]}"; do
if ! is_subnet_in_use "$subnet" "$network_name"; then
echo "$subnet"
return 0
fi
done
return 1
}
# Function to get gateway for subnet
get_gateway_for_subnet() {
local subnet=$1
echo "${subnet%.*}.1"
}
# Function to create pterodactyl network
create_pterodactyl_network() {
local subnet=$1
local gateway=$2
# Remove existing network if it exists
if docker network ls | grep -q "pterodactyl_nw"; then
docker network rm pterodactyl_nw || true
fi
# Create the network with error checking
if ! docker network create \
--driver=bridge \
--ipv6 \
--subnet="$subnet" \
--gateway="$gateway" \
--subnet=fd00::/64 \
--gateway=fd00::1 \
-o "com.docker.network.bridge.name=pterodactyl0" \
-o "com.docker.network.bridge.enable_ip_masquerade=true" \
-o "com.docker.network.bridge.enable_icc=true" \
pterodactyl_nw; then
return 1
fi
# Verify network was created
if ! docker network ls | grep -q "pterodactyl_nw"; then
return 1
fi
return 0
}
# Main network configuration function
configure_network() {
# Find available subnet
local new_subnet
new_subnet=$(find_available_subnet "pterodactyl_nw")
if [ $? -ne 0 ]; then
echo "ERROR: Could not find available subnet"
return 1
fi
# Get gateway
local new_gateway
new_gateway=$(get_gateway_for_subnet "$new_subnet")
if [ $? -ne 0 ]; then
echo "ERROR: Could not determine gateway"
return 1
fi
echo "Using subnet: $new_subnet with gateway: $new_gateway"
# Create network
if ! create_pterodactyl_network "$new_subnet" "$new_gateway"; then
echo "ERROR: Failed to create network"
return 1
fi
echo "Network created successfully"
return 0
}
# Create required directories
echo "Creating required directories..."
mkdir -p "/var/lib/pterodactyl/volumes/$UUID"
mkdir -p "/tmp/pterodactyl/$UUID"
mkdir -p "/etc/pterodactyl"
mkdir -p "/var/log/pterodactyl"
# Configure network
echo "Configuring network..."
if ! configure_network; then
echo "ERROR: Network configuration failed"
exit 1
fi
# Set ownership
echo "Setting directory permissions..."
chown -R 988:988 /tmp/pterodactyl /etc/pterodactyl /var/log/pterodactyl /var/lib/pterodactyl
# Restart pterodactyl-wings container
echo "Restarting pterodactyl-wings container..."
if ! docker restart pterodactyl-wings; then
echo "WARNING: Failed to restart pterodactyl-wings container"
echo "Please restart it manually using: docker restart pterodactyl-wings"
fi
echo "Setup completed successfully for UUID: $UUID"