diff --git a/pkgs/sane-scripts/default.nix b/pkgs/sane-scripts/default.nix index 81b9cab0..6aa01ed1 100644 --- a/pkgs/sane-scripts/default.nix +++ b/pkgs/sane-scripts/default.nix @@ -24,6 +24,7 @@ resholve.mkDerivation { file findutils gnugrep + gnused gocryptfs ifuse inetutils @@ -36,6 +37,7 @@ resholve.mkDerivation { ssh-to-age sops sudo + systemd util-linux which ]; @@ -69,6 +71,7 @@ resholve.mkDerivation { "cannot:${rsync}/bin/rsync" "cannot:${sops}/bin/sops" "cannot:${ssh-to-age}/bin/ssh-to-age" + "cannot:${systemd}/bin/systemctl" ]; }; }; diff --git a/pkgs/sane-scripts/src/sane-vpn-down b/pkgs/sane-scripts/src/sane-vpn-down index 437722c1..c25478fb 100755 --- a/pkgs/sane-scripts/src/sane-vpn-down +++ b/pkgs/sane-scripts/src/sane-vpn-down @@ -2,16 +2,17 @@ # first arg should be the region, e.g. `us` or `ukr` -case $1 in -ukr) - iface=wg-quick-ovpnd-ukr;; -us) - iface=wg-quick-ovpnd-us;; -us-atlanta) - iface=wg-quick-ovpnd-us-atlanta;; -*) - echo "invalid vpn name '$1'"; exit 1;; -esac +vpns=$(systemctl list-unit-files | grep wg-quick-ovpnd- | cut -f 1 -d ' ' | sed s'/^wg-quick-ovpnd-\([a-zA-Z-]*\)\.service$/\1/g') + +if ! [ $(echo "$vpns" | grep "^$1$") ] +then + echo "invalid vpn name '$1'" + echo "choices:" + echo "$vpns" + exit 1 +fi + +iface=wg-quick-ovpnd-$1.service echo vpn: $(curl https://ipinfo.io/ip) sudo systemctl stop $iface diff --git a/pkgs/sane-scripts/src/sane-vpn-up b/pkgs/sane-scripts/src/sane-vpn-up index a412b42d..df1e2115 100755 --- a/pkgs/sane-scripts/src/sane-vpn-up +++ b/pkgs/sane-scripts/src/sane-vpn-up @@ -2,16 +2,17 @@ # first arg should be the region, e.g. `us` or `ukr` -case $1 in -ukr) - iface=wg-quick-ovpnd-ukr;; -us) - iface=wg-quick-ovpnd-us;; -us-atlanta) - iface=wg-quick-ovpnd-us-atlanta;; -*) - echo "invalid vpn name '$1'"; exit 1;; -esac +vpns=$(systemctl list-unit-files | grep wg-quick-ovpnd- | cut -f 1 -d ' ' | sed s'/^wg-quick-ovpnd-\([a-zA-Z-]*\)\.service$/\1/g') + +if ! [ $(echo "$vpns" | grep "^$1$") ] +then + echo "invalid vpn name '$1'" + echo "choices:" + echo "$vpns" + exit 1 +fi + +iface=wg-quick-ovpnd-$1.service echo plain: $(curl https://ipinfo.io/ip) sudo systemctl start $iface