From f3ed9a3452692ed9544303860cb737fe9da3cb39 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 19 Sep 2023 16:09:46 +0000 Subject: [PATCH] sane-vpn: support "vpn-servo" --- hosts/common/vpn.nix | 1 - pkgs/additional/sane-scripts/src/sane-vpn | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hosts/common/vpn.nix b/hosts/common/vpn.nix index 6a91c2abe..4407a2201 100644 --- a/hosts/common/vpn.nix +++ b/hosts/common/vpn.nix @@ -34,7 +34,6 @@ let }; # TODO: this should live in the same file as hosts/modules/wg-home.nix... - # TODO: update sane-vpn script to also allow activating/deactiving this interface def-servo = def-wg-vpn "vpn-servo" { endpoint = config.sane.hosts.by-name."servo".wg-home.endpoint; publicKey = config.sane.hosts.by-name."servo".wg-home.pubkey; diff --git a/pkgs/additional/sane-scripts/src/sane-vpn b/pkgs/additional/sane-scripts/src/sane-vpn index 48ed9df55..0f33f1cbc 100755 --- a/pkgs/additional/sane-scripts/src/sane-vpn +++ b/pkgs/additional/sane-scripts/src/sane-vpn @@ -5,23 +5,28 @@ oper="$1" region="$2" # region should be e.g. `us` or `ukr` -vpns=$(systemctl list-unit-files | grep wg-quick-ovpnd- | cut -f 1 -d ' ' | sed s'/^wg-quick-ovpnd-\([a-zA-Z-]*\)\.service$/\1/g') +vpns=$(systemctl list-unit-files | grep wg-quick- | cut -f 1 -d ' ' | sed s'/^wg-quick-\([a-zA-Z-]*\)\.service$/\1/g') -if ! [ $(echo "$vpns" | grep "^$region$") ] -then +if [ $(echo "$vpns" | grep "^$region$") ]; then + iface="$region" +elif [ $(echo "$vpns" | grep "^vpn-$region$") ]; then + iface="vpn-$region" +elif [ $(echo "$vpns" | grep "^ovpnd-$region$") ]; then + iface="ovpnd-$region" +else echo "invalid vpn name '$region'" echo "choices:" echo "$vpns" exit 1 fi -iface=wg-quick-ovpnd-$region.service +service="wg-quick-$iface.service" echo before: $(sane-ip-check --no-upnp) if [ "$oper" == up ]; then - sudo systemctl start $iface + sudo systemctl start "$service" elif [ "$oper" == down ]; then - sudo systemctl stop $iface + sudo systemctl stop "$service" else echo "invalid operation '$oper'" exit 1