#!/usr/bin/env bash
# Toggle VPN mode (all traffic through the tunnel) of WireGuard interface $1,
# independently of the tunnel itself.  Starting it brings the tunnel up.
# Needs the polkit rule from modules/nixos/system/network/wireguard.
name=$1
[[ -n $name ]] || exit 64
detach_self "$@"
unit=wireguard-$name-vpn.service
if systemctl is-active --quiet "$unit"; then
  systemctl stop "$unit"
else
  systemctl start "$unit"
fi
