Update unraid-config.sh
This commit is contained in:
parent
696914e1c6
commit
cda00cd35c
1 changed files with 36 additions and 20 deletions
|
@ -15,6 +15,12 @@ WAN_INTERFACE="br0"
|
||||||
VPS_IP="YOUR_VPS_IP" # Replace with your Dallas VPS public IP
|
VPS_IP="YOUR_VPS_IP" # Replace with your Dallas VPS public IP
|
||||||
GAME_SUBNET="172.17.0.0/16" # docker0 network
|
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
|
# Function to check if script is run as root
|
||||||
check_root() {
|
check_root() {
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
@ -31,6 +37,13 @@ check_tailscale() {
|
||||||
fi
|
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
|
# Function to fix routing
|
||||||
fix_routing() {
|
fix_routing() {
|
||||||
echo -e "${YELLOW}Fixing routing table...${NC}"
|
echo -e "${YELLOW}Fixing routing table...${NC}"
|
||||||
|
@ -51,24 +64,23 @@ fix_routing() {
|
||||||
|
|
||||||
# Ensure WireGuard routes are preserved
|
# Ensure WireGuard routes are preserved
|
||||||
if ip link show wg0 >/dev/null 2>&1; then
|
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}')
|
local WG_IP=$(ip -4 addr show wg0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
||||||
if [ ! -z "$WG_IP" ]; then
|
if [ ! -z "$WG_IP" ]; then
|
||||||
ip route add $WG_IP dev wg0 scope link
|
ip route add $WG_IP dev wg0 scope link
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save the routing configuration
|
# Save the routing configuration with proper permissions
|
||||||
echo "#!/bin/bash" > /boot/config/routing.sh
|
echo "#!/bin/bash" > $ROUTING_SCRIPT
|
||||||
echo "ip route del default 2>/dev/null" >> /boot/config/routing.sh
|
echo "ip route del default 2>/dev/null" >> $ROUTING_SCRIPT
|
||||||
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 tailscale1 2>/dev/null" >> $ROUTING_SCRIPT
|
||||||
echo "ip route del 0.0.0.0/0 dev wg0 2>/dev/null" >> /boot/config/routing.sh
|
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" >> /boot/config/routing.sh
|
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" >> /boot/config/routing.sh
|
echo "ip route add $VPS_IP via \$(ip route | grep tailscale1 | awk '{print \$1}') dev tailscale1" >> $ROUTING_SCRIPT
|
||||||
if [ ! -z "$WG_IP" ]; then
|
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
|
fi
|
||||||
chmod +x /boot/config/routing.sh
|
chmod 755 $ROUTING_SCRIPT
|
||||||
|
|
||||||
echo -e "${GREEN}Routing table fixed successfully${NC}"
|
echo -e "${GREEN}Routing table fixed successfully${NC}"
|
||||||
}
|
}
|
||||||
|
@ -113,22 +125,25 @@ make_persistent() {
|
||||||
echo -e "${YELLOW}Making settings persistent...${NC}"
|
echo -e "${YELLOW}Making settings persistent...${NC}"
|
||||||
|
|
||||||
# Save iptables rules
|
# Save iptables rules
|
||||||
mkdir -p /boot/config/iptables
|
iptables-save > $IPTABLES_RULES
|
||||||
iptables-save > /boot/config/iptables/rules.v4
|
chmod 644 $IPTABLES_RULES
|
||||||
|
|
||||||
# Create restore script
|
# Create restore script
|
||||||
echo "#!/bin/bash" > /boot/config/iptables/restore.sh
|
echo "#!/bin/bash" > $IPTABLES_SCRIPT
|
||||||
echo "iptables-restore < /boot/config/iptables/rules.v4" >> /boot/config/iptables/restore.sh
|
echo "iptables-restore < $IPTABLES_RULES" >> $IPTABLES_SCRIPT
|
||||||
chmod +x /boot/config/iptables/restore.sh
|
chmod 755 $IPTABLES_SCRIPT
|
||||||
|
|
||||||
# Add to go script if not already present
|
# Update go script if needed
|
||||||
if ! grep -q "/boot/config/routing.sh" /boot/config/go; then
|
if ! grep -q "$ROUTING_SCRIPT" /boot/config/go; then
|
||||||
echo "/boot/config/routing.sh" >> /boot/config/go
|
echo "$ROUTING_SCRIPT" >> /boot/config/go
|
||||||
fi
|
fi
|
||||||
if ! grep -q "/boot/config/iptables/restore.sh" /boot/config/go; then
|
if ! grep -q "$IPTABLES_SCRIPT" /boot/config/go; then
|
||||||
echo "/boot/config/iptables/restore.sh" >> /boot/config/go
|
echo "$IPTABLES_SCRIPT" >> /boot/config/go
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ensure go script is executable
|
||||||
|
chmod 755 /boot/config/go
|
||||||
|
|
||||||
echo -e "${GREEN}Settings made persistent${NC}"
|
echo -e "${GREEN}Settings made persistent${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +153,7 @@ main() {
|
||||||
|
|
||||||
check_root
|
check_root
|
||||||
check_tailscale
|
check_tailscale
|
||||||
|
create_directories
|
||||||
fix_routing
|
fix_routing
|
||||||
configure_iptables
|
configure_iptables
|
||||||
make_persistent
|
make_persistent
|
||||||
|
|
Loading…
Reference in a new issue