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