#!/bin/sh # Функция для отображения разделителя print_separator() { echo "════════════════════════════════════════════════════════════════════════════════" } # Функция для отображения заголовка этапа print_stage() { echo "║ 🚀 $1" print_separator } # Функция для отображения результата print_result() { if [ $? -eq 0 ]; then echo "║ ✅ $1" else echo "║ ❌ $1" fi print_separator } # Проверка наличия /etc/resolv.conf print_stage "Checking /etc/resolv.conf" if [ ! -f /etc/resolv.conf ]; then echo "║ /etc/resolv.conf not found. Creating it..." echo "nameserver 1.1.1.1" > /etc/resolv.conf echo "nameserver 8.8.8.8" >> /etc/resolv.conf print_result "/etc/resolv.conf created successfully." else print_result "/etc/resolv.conf already exists." fi # Проверка наличия конфига WireGuard print_stage "Checking WireGuard config" if [ ! -f /etc/wireguard/wg0.conf ]; then echo "║ Error: WireGuard config not found!" exit 1 else print_result "WireGuard config found." fi # Проверка сети ДО включения WireGuard print_stage "Testing connectivity BEFORE WireGuard" echo "║ Pinging 1.1.1.1..." ping -c 4 1.1.1.1 > /tmp/ping.log 2>&1 if [ $? -eq 0 ]; then echo "║ Ping successful." cat /tmp/ping.log | sed 's/^/║ /' else echo "║ Ping failed." fi print_separator # Извлекаем DNS из конфига WireGuard WG_DNS=$(awk -F= '/DNS/ {print $2}' /etc/wireguard/wg0.conf | xargs) # Настройка DNS print_stage "Configuring DNS" if [ -n "$WG_DNS" ]; then echo "║ Using DNS from WireGuard config: $WG_DNS" echo "nameserver $WG_DNS" > /etc/resolv.conf else echo "║ Using fallback DNS: 1.1.1.1, 8.8.8.8" echo "nameserver 1.1.1.1" > /etc/resolv.conf echo "nameserver 8.8.8.8" >> /etc/resolv.conf fi print_result "DNS configured." # Запуск WireGuard print_stage "Starting WireGuard" wg-quick up wg0 2>&1 | tee /tmp/wg.log if [ $? -eq 0 ]; then echo "║ WireGuard started successfully." else echo "║ WireGuard failed to start. Logs:" cat /tmp/wg.log | sed 's/^/║ /' exit 1 fi print_separator # Проверка маршрутизации после запуска WireGuard print_stage "Routing table AFTER WireGuard" ip route | sed 's/^/║ /' print_separator # Проверка сети ПОСЛЕ включения WireGuard print_stage "Testing connectivity AFTER WireGuard" echo "║ Pinging 1.1.1.1..." ping -c 4 1.1.1.1 > /tmp/ping.log 2>&1 if [ $? -eq 0 ]; then echo "║ Ping successful." cat /tmp/ping.log | sed 's/^/║ /' else echo "║ Ping failed." fi print_separator # Проверка DNS print_stage "Testing DNS" nslookup api.ipify.org > /tmp/dns.log 2>&1 if [ $? -eq 0 ]; then echo "║ DNS lookup successful." cat /tmp/dns.log | sed 's/^/║ /' else echo "║ DNS lookup failed." fi print_separator # Проверка подключения через icanhazip.com print_stage "Testing external connectivity (icanhazip.com)" echo "║ Fetching external IP..." curl -s https://icanhazip.com > /tmp/curl.log 2>&1 if [ $? -eq 0 ]; then echo "║ Connection successful." echo "║ External IP: $(cat /tmp/curl.log)" else echo "║ Connection failed." fi print_separator # Запуск приложения print_stage "Starting application" echo "║ Application is starting..." exec node src/index.js