diff --git a/unraid-config.sh b/unraid-config.sh index e6d1a64..25e4cd8 100644 --- a/unraid-config.sh +++ b/unraid-config.sh @@ -15,6 +15,12 @@ WAN_INTERFACE="br0" VPS_IP="YOUR_VPS_IP" # Replace with your Dallas VPS public IP GAME_SUBNET="172.17.0.0/16" # docker0 network +# Script paths +SCRIPT_DIR="/boot/config/plugins/game_routing" +ROUTING_SCRIPT="$SCRIPT_DIR/routing.sh" +IPTABLES_SCRIPT="$SCRIPT_DIR/iptables-restore.sh" +IPTABLES_RULES="$SCRIPT_DIR/rules.v4" + # Function to check if script is run as root check_root() { if [ "$EUID" -ne 0 ]; then @@ -31,6 +37,13 @@ check_tailscale() { fi } +# Function to create script directory +create_directories() { + echo -e "${YELLOW}Creating script directories...${NC}" + mkdir -p $SCRIPT_DIR + chmod 755 $SCRIPT_DIR +} + # Function to fix routing fix_routing() { echo -e "${YELLOW}Fixing routing table...${NC}" @@ -51,24 +64,23 @@ fix_routing() { # Ensure WireGuard routes are preserved if ip link show wg0 >/dev/null 2>&1; then - # Get WireGuard IP and add its routes back local WG_IP=$(ip -4 addr show wg0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') if [ ! -z "$WG_IP" ]; then ip route add $WG_IP dev wg0 scope link fi fi - # Save the routing configuration - echo "#!/bin/bash" > /boot/config/routing.sh - echo "ip route del default 2>/dev/null" >> /boot/config/routing.sh - echo "ip route del 0.0.0.0/0 dev tailscale1 2>/dev/null" >> /boot/config/routing.sh - echo "ip route del 0.0.0.0/0 dev wg0 2>/dev/null" >> /boot/config/routing.sh - echo "ip route add default via $DEFAULT_GATEWAY dev br0" >> /boot/config/routing.sh - echo "ip route add $VPS_IP via \$(ip route | grep tailscale1 | awk '{print \$1}') dev tailscale1" >> /boot/config/routing.sh + # Save the routing configuration with proper permissions + echo "#!/bin/bash" > $ROUTING_SCRIPT + echo "ip route del default 2>/dev/null" >> $ROUTING_SCRIPT + echo "ip route del 0.0.0.0/0 dev tailscale1 2>/dev/null" >> $ROUTING_SCRIPT + echo "ip route del 0.0.0.0/0 dev wg0 2>/dev/null" >> $ROUTING_SCRIPT + echo "ip route add default via $DEFAULT_GATEWAY dev br0" >> $ROUTING_SCRIPT + echo "ip route add $VPS_IP via \$(ip route | grep tailscale1 | awk '{print \$1}') dev tailscale1" >> $ROUTING_SCRIPT if [ ! -z "$WG_IP" ]; then - echo "ip route add $WG_IP dev wg0 scope link" >> /boot/config/routing.sh + echo "ip route add $WG_IP dev wg0 scope link" >> $ROUTING_SCRIPT fi - chmod +x /boot/config/routing.sh + chmod 755 $ROUTING_SCRIPT echo -e "${GREEN}Routing table fixed successfully${NC}" } @@ -113,22 +125,25 @@ make_persistent() { echo -e "${YELLOW}Making settings persistent...${NC}" # Save iptables rules - mkdir -p /boot/config/iptables - iptables-save > /boot/config/iptables/rules.v4 + iptables-save > $IPTABLES_RULES + chmod 644 $IPTABLES_RULES # Create restore script - echo "#!/bin/bash" > /boot/config/iptables/restore.sh - echo "iptables-restore < /boot/config/iptables/rules.v4" >> /boot/config/iptables/restore.sh - chmod +x /boot/config/iptables/restore.sh + echo "#!/bin/bash" > $IPTABLES_SCRIPT + echo "iptables-restore < $IPTABLES_RULES" >> $IPTABLES_SCRIPT + chmod 755 $IPTABLES_SCRIPT - # Add to go script if not already present - if ! grep -q "/boot/config/routing.sh" /boot/config/go; then - echo "/boot/config/routing.sh" >> /boot/config/go + # Update go script if needed + if ! grep -q "$ROUTING_SCRIPT" /boot/config/go; then + echo "$ROUTING_SCRIPT" >> /boot/config/go fi - if ! grep -q "/boot/config/iptables/restore.sh" /boot/config/go; then - echo "/boot/config/iptables/restore.sh" >> /boot/config/go + if ! grep -q "$IPTABLES_SCRIPT" /boot/config/go; then + echo "$IPTABLES_SCRIPT" >> /boot/config/go fi + # Ensure go script is executable + chmod 755 /boot/config/go + echo -e "${GREEN}Settings made persistent${NC}" } @@ -138,6 +153,7 @@ main() { check_root check_tailscale + create_directories fix_routing configure_iptables make_persistent