#!/bin/bash

#Загружаем модули ядра и включаем log в dmesg (GUI)
#if [[ -z $(lsmod | grep wireguard) ]]; then modprobe wireguard; fi
#echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control

sysctl -w net.ipv4.ip_forward=1; #sysctl -w net.ipv6.conf.all.disable_ipv6=0
sysctl -w net.ipv6.conf.all.forwarding=1

[[ $(ip -br a | grep wg0) ]] && wg-quick down /etc/luntikwg/wg0.conf

/etc/luntikwg/update-resolv-conf up

sleep 1

#Закрываем DNS Leak в конфиге
if [[ -z $(cat /etc/luntikwg/wg0.conf | grep PostDown) ]]; then
    sed -i '/Interface/a \PostDown = /etc/luntikwg/update-resolv-conf down' /etc/luntikwg/wg0.conf
    sed -i '/Interface/a \PostUp = /etc/luntikwg/update-resolv-conf up' /etc/luntikwg/wg0.conf
    chmod 600 /etc/luntikwg/wg0.conf
fi;

#Запуск WireGuard
wg-quick up /etc/luntikwg/wg0.conf

exit 0;
