aboutsummaryrefslogtreecommitdiffstats
path: root/roles/jails/16_dl/templates/wg_random_tunnel.j2
diff options
context:
space:
mode:
Diffstat (limited to 'roles/jails/16_dl/templates/wg_random_tunnel.j2')
-rw-r--r--roles/jails/16_dl/templates/wg_random_tunnel.j217
1 files changed, 17 insertions, 0 deletions
diff --git a/roles/jails/16_dl/templates/wg_random_tunnel.j2 b/roles/jails/16_dl/templates/wg_random_tunnel.j2
new file mode 100644
index 0000000..3cc9492
--- /dev/null
+++ b/roles/jails/16_dl/templates/wg_random_tunnel.j2
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -eux
+
+CONF=$(ls /usr/local/etc/wireguard/ | sort -R | head -n1)
+GATEWAY={{ ingress_ip }}
+
+# Shut down current tunnel
+wg-quick down $(wg show interfaces) || true
+
+wg-quick up "/usr/local/etc/wireguard/${CONF}"
+
+TUNNEL_IF=$(wg show interfaces)
+TUNNEL_IP=$(wg show $TUNNEL_IF endpoints | awk '{print $2}' | tr ':' ' ' | awk '{print $1}')
+
+route delete $TUNNEL_IP
+route add $TUNNEL_IP $GATEWAY