Update Start Process
This commit is contained in:
66
wg/start.sh
66
wg/start.sh
@@ -13,11 +13,34 @@ print_stage() {
|
|||||||
|
|
||||||
# Функция для отображения результата
|
# Функция для отображения результата
|
||||||
print_result() {
|
print_result() {
|
||||||
if [ $? -eq 0 ]; then
|
local status=$?
|
||||||
echo "║ ✅ $1"
|
local message=$1
|
||||||
|
local action=$2
|
||||||
|
|
||||||
|
if [ -n "$action" ]; then
|
||||||
|
case "$action" in
|
||||||
|
"created")
|
||||||
|
echo "║ 🆕 $message"
|
||||||
|
;;
|
||||||
|
"exists")
|
||||||
|
echo "║ ✅ $message"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ $status -eq 0 ]; then
|
||||||
|
echo "║ ✅ $message"
|
||||||
|
else
|
||||||
|
echo "║ ❌ $message"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
echo "║ ❌ $1"
|
if [ $status -eq 0 ]; then
|
||||||
|
echo "║ ✅ $message"
|
||||||
|
else
|
||||||
|
echo "║ ❌ $message"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_separator
|
print_separator
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,9 +50,14 @@ if [ ! -f /etc/resolv.conf ]; then
|
|||||||
echo "║ /etc/resolv.conf not found. Creating it..."
|
echo "║ /etc/resolv.conf not found. Creating it..."
|
||||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||||
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
||||||
print_result "/etc/resolv.conf created successfully."
|
if [ $? -eq 0 ]; then
|
||||||
|
print_result "/etc/resolv.conf created successfully." "created"
|
||||||
|
else
|
||||||
|
print_result "Failed to create /etc/resolv.conf"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
print_result "/etc/resolv.conf already exists."
|
print_result "/etc/resolv.conf already exists." "exists"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Проверка наличия конфига WireGuard
|
# Проверка наличия конфига WireGuard
|
||||||
@@ -38,7 +66,12 @@ if [ ! -f /etc/wireguard/wg0.conf ]; then
|
|||||||
echo "║ Error: WireGuard config not found!"
|
echo "║ Error: WireGuard config not found!"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
print_result "WireGuard config found."
|
if [ -r /etc/wireguard/wg0.conf ]; then
|
||||||
|
print_result "WireGuard config found and readable." "exists"
|
||||||
|
else
|
||||||
|
print_result "WireGuard config found but not readable!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Проверка сети ДО включения WireGuard
|
# Проверка сети ДО включения WireGuard
|
||||||
@@ -61,24 +94,37 @@ print_stage "Configuring DNS"
|
|||||||
if [ -n "$WG_DNS" ]; then
|
if [ -n "$WG_DNS" ]; then
|
||||||
echo "║ Using DNS from WireGuard config: $WG_DNS"
|
echo "║ Using DNS from WireGuard config: $WG_DNS"
|
||||||
echo "nameserver $WG_DNS" > /etc/resolv.conf
|
echo "nameserver $WG_DNS" > /etc/resolv.conf
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
print_result "DNS configured using WireGuard settings." "created"
|
||||||
|
else
|
||||||
|
print_result "Failed to configure DNS!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "║ Using fallback DNS: 1.1.1.1, 8.8.8.8"
|
echo "║ Using fallback DNS: 1.1.1.1, 8.8.8.8"
|
||||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||||
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
print_result "DNS configured using fallback settings." "created"
|
||||||
|
else
|
||||||
|
print_result "Failed to configure DNS!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
print_result "DNS configured."
|
|
||||||
|
|
||||||
# Запуск WireGuard
|
# Запуск WireGuard
|
||||||
print_stage "Starting WireGuard"
|
print_stage "Starting WireGuard"
|
||||||
wg-quick up wg0 2>&1 | tee /tmp/wg.log
|
wg-quick up wg0 2>&1 | tee /tmp/wg.log
|
||||||
if [ $? -eq 0 ]; then
|
wg_status=$?
|
||||||
|
if [ $wg_status -eq 0 ]; then
|
||||||
echo "║ WireGuard started successfully."
|
echo "║ WireGuard started successfully."
|
||||||
|
print_result "WireGuard interface activated successfully."
|
||||||
else
|
else
|
||||||
echo "║ WireGuard failed to start. Logs:"
|
echo "║ WireGuard failed to start. Logs:"
|
||||||
cat /tmp/wg.log | sed 's/^/║ /'
|
cat /tmp/wg.log | sed 's/^/║ /'
|
||||||
|
print_result "Failed to start WireGuard interface!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
print_separator
|
|
||||||
|
|
||||||
# Проверка маршрутизации после запуска WireGuard
|
# Проверка маршрутизации после запуска WireGuard
|
||||||
print_stage "Routing table AFTER WireGuard"
|
print_stage "Routing table AFTER WireGuard"
|
||||||
@@ -123,4 +169,4 @@ print_separator
|
|||||||
# Запуск приложения
|
# Запуск приложения
|
||||||
print_stage "Starting application"
|
print_stage "Starting application"
|
||||||
echo "║ Application is starting..."
|
echo "║ Application is starting..."
|
||||||
exec node src/index.js
|
exec node src/index.js
|
||||||
|
|||||||
Reference in New Issue
Block a user