#!/usr/bin/env bash
# Bring the WireGuard tunnel $1 down (stop its service, which takes the peer
# units with it) or up (start its target, which pulls service and peers).
# Needs the polkit rule from modules/nixos/system/network/wireguard.
name=$1
[[ -n $name ]] || exit 64
detach_self "$@"
if [[ -d /sys/class/net/$name ]]; then
  systemctl stop "wireguard-$name.service"
else
  systemctl start "wireguard-$name.target"
fi
