2022-03-20 20:56:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
|
2023-05-31 14:35:08 +00:00
|
|
|
# dependencies: cut, getent, ip, ping and wg
|
2023-05-29 10:46:19 +00:00
|
|
|
|
|
|
|
WG_ENDPOINT_DOMAIN="${WG_ENDPOINT%%:*}"
|
|
|
|
WG_ENDPOINT_PORT="${WG_ENDPOINT##*:}"
|
|
|
|
|
|
|
|
if ! ip netns exec "$WG_NAMESPACE" ping -q -c 1 -W "${WG_TIMEOUT:-5}" "$WG_GATEWAY"; then
|
2022-03-20 20:56:45 +00:00
|
|
|
echo 'probe failed, resolving endpoint'
|
2023-05-31 14:35:08 +00:00
|
|
|
ip netns exec "$WG_NAMESPACE" wg set "$WG_INTERFACE" peer "$WG_PEER" endpoint "$(getent hosts -- "$WG_ENDPOINT_DOMAIN" | cut -d ' ' -f 1):$WG_ENDPOINT_PORT"
|
2022-03-20 20:56:45 +00:00
|
|
|
fi
|