#!/usr/bin/env bash set -euo pipefail prev_endpoint="" while true; do if ! wg show wg-clerie endpoints &>/dev/null; then if [[ "${prev_endpoint}" != "" ]]; then echo "Interface wg-clerie unavailable, doing nothing" prev_endpoint="" fi sleep 5 continue fi if ip route get 2a01:4f8:c0c:15f1::1 ipproto udp dport 51820 &>/dev/null; then new_endpoint="[2a01:4f8:c0c:15f1::1]:51820" else new_endpoint="78.47.183.82:51820" fi if [[ "${new_endpoint}" != "${prev_endpoint}" ]]; then echo "Switching endpoint for wg-clerie to ${new_endpoint}" wg set wg-clerie peer "2p1Jqs3bkXbXHFWE6vp1yxHIFoUaZQEARS2nJzbkuBA=" endpoint "${new_endpoint}" prev_endpoint="${new_endpoint}" fi sleep 5 done