forked from linuxserver/docker-wireguard
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request linuxserver#302 from linuxserver/multi
Add support for multiple WireGuard interfaces
- Loading branch information
Showing
8 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
#!/usr/bin/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
wg-quick down wg0 | ||
if [[ -f "/app/activeconfs" ]]; then | ||
. /app/activeconfs | ||
for tunnel in $(printf '%s\n' "${WG_CONFS[@]}" | tac | tr '\n' ' '; echo); do | ||
echo "**** Disabling tunnel ${tunnel} ****" | ||
wg-quick down "${tunnel}" || : | ||
done | ||
echo "**** All tunnels are down ****" | ||
rm -rf /app/activeconfs | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,46 @@ | ||
#!/usr/bin/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
wg-quick up wg0 | ||
unset WG_CONFS | ||
rm -rf /app/activeconfs | ||
# Enumerate interfaces | ||
for wgconf in $(ls /config/wg_confs/*.conf); do | ||
if grep -q "\[Interface\]" "${wgconf}"; then | ||
echo "**** Found WG conf ${wgconf}, adding to list ****" | ||
WG_CONFS+=("${wgconf}") | ||
else | ||
echo "**** Found WG conf ${wgconf}, but it doesn't seem to be valid, skipping. ****" | ||
fi | ||
done | ||
|
||
if [[ -z "${WG_CONFS}" ]]; then | ||
echo "**** No valid tunnel config found. Please create a valid config and restart the container ****" | ||
ip route del default | ||
exit 0 | ||
fi | ||
|
||
unset FAILED | ||
for tunnel in ${WG_CONFS[@]}; do | ||
echo "**** Activating tunnel ${tunnel} ****" | ||
if ! wg-quick up "${tunnel}"; then | ||
FAILED="${tunnel}" | ||
break | ||
fi | ||
done | ||
|
||
if [[ -z "${FAILED}" ]]; then | ||
declare -p WG_CONFS > /app/activeconfs | ||
echo "**** All tunnels are now active ****" | ||
else | ||
echo "**** Tunnel ${FAILED} failed, will stop all others! ****" | ||
for tunnel in ${WG_CONFS[@]}; do | ||
if [[ "${tunnel}" = "${FAILED}" ]]; then | ||
break | ||
else | ||
echo "**** Disabling tunnel ${tunnel} ****" | ||
wg-quick down "${tunnel}" || : | ||
fi | ||
done | ||
ip route del default | ||
echo "**** All tunnels are now down. Please fix the tunnel config ${FAILED} and restart the container ****" | ||
fi |