#!/usr/bin/env bash
# wg21-join/remove — stop wg21 and delete the conf this role wrote. The private key is kept
# (so a re-join keeps the same identity); a conf without our marker is never touched.
set -euo pipefail
cat >/dev/null
CONF="${SSR_ETC:-/etc}/wireguard/wg21.conf"
if [ -e "$CONF" ] && ! grep -qxF '# managed-by: silvershell wg21-join' "$CONF"; then
  echo "ERROR: wg21 is managed by another role; not removing" >&2; exit 1
fi
systemctl disable --now wg-quick@wg21 >&2 || true
rm -f "$CONF"
echo '{}' > "$SSR_OUTPUTS"
