Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM debian:buster
FROM debian:bullseye-slim

# Add debian backports repo for wireguard packages
RUN echo "deb http://deb.debian.org/debian/ buster-backports main" > /etc/apt/sources.list.d/buster-backports.list
RUN echo "deb http://deb.debian.org/debian/ bullseye-backports main" > /etc/apt/sources.list.d/buster-backports.list

# Install wireguard packges
RUN apt-get update && \
apt-get install -y --no-install-recommends wireguard-tools iptables nano net-tools procps openresolv docker.io jq dnsmasq curl dnsutils && \
apt-get install -y --no-install-recommends wireguard-tools iproute2 iptables nano net-tools procps openresolv docker.io jq dnsmasq curl dnsutils && \
apt-get clean

# Add main work dir to PATH
Expand Down
26 changes: 12 additions & 14 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ else
ip route add to $LOCAL_NETWORK via $gw dev eth0
fi


# Get the expected VPN IP address from the interface config file
expected_ips=()
for interface in $interfaces; do
expected_ip=$(grep -Po '^Endpoint\s?=\s?\K[0-9\.]{7,}' $interface)
expected_ips+=($expected_ip)
done

# Handle shutdown behavior
function finish {
echo "$(date): ---INFO--- Shutting down Wireguard"
Expand All @@ -121,8 +113,14 @@ function finish {
exit 0
}

# Fill get the actual IP as reported by wireguard
function fill_actual_ip {
# Fill the expected and actual ips
function fill_ips {
expected_ips=()
for interface in $interfaces; do
expected_ip=$(grep -Po '^Endpoint\s?=\s?\K[0-9\.]{7,}' $interface)
expected_ips+=($expected_ip)
done

actual_ips=()
actual_ip=$(wg | grep -Po 'endpoint:\s\K[^:]*')
actual_ips+=($actual_ip)
Expand All @@ -144,19 +142,19 @@ function write_service_hosts {
fi
}

fill_actual_ip
fill_ips
echo "$(date): ---INFO--- Endpoint in config: $expected_ips"
echo "$(date): ---INFO--- Active EndPoint : $actual_ips"

write_service_hosts

# Check IP address every 10 seconds
Check IP address every 10 seconds
retry=true
while $retry
do
sleep 10;

fill_actual_ip
fill_ips
if [[ $expected_ips != $actual_ips ]];
then
# Make one attempt to restart the wireguard interface if the IP is incorrect
Expand All @@ -165,7 +163,7 @@ do
wg-quick down $interface; wg-quick up $interface
done

fill_actual_ip
fill_ips
if [[ $expected_ips != $actual_ips ]];
then
# Exit the container if the IP is still incorrect after wireguard restart
Expand Down