#!/bin/bash set -e # Remove unattended-upgrades apt remove --purge -y unattended-upgrades # Update and upgrade apt update && apt upgrade -y # Install basic tools and WireGuard apt install -y git curl wget tmux nano net-tools unzip zip gnupg tzdata qrencode wireguard # Setup WireGuard directory WG_DIR="/etc/wireguard" mkdir -p "$WG_DIR/self" cd "$WG_DIR/self" # Generate server keys wg genkey | tee private | wg pubkey > public # Enable IP forwarding echo "net.ipv4.ip_forward=1" | tee -a /etc/sysctl.conf echo "net.ipv6.conf.all.forwarding=1" | tee -a /etc/sysctl.conf sysctl -p # Create basic wg0.conf if it doesn't exist WG_CONF="$WG_DIR/wg0.conf" if [ ! -f "$WG_CONF" ]; then SERVER_PRIVATE_KEY=$(cat private) SERVER_PUBLIC_KEY=$(cat public) SERVER_PORT=51820 SERVER_INTERFACE=$(ip route get 8.8.8.8 | awk '{print $5; exit}') # Detect network interface (e.g., eth0, ens3, etc.) cat > "$WG_CONF" < public MOBILE_PRIVATE_KEY=$(cat private) MOBILE_PUBLIC_KEY=$(cat public) # Create peer config for mobile cat > mobile.conf <> "$WG_CONF" <