sane-vpn-{up,down}: consolidate

This commit is contained in:
Colin 2023-09-19 15:41:54 +00:00
parent b69424983f
commit 3a30b891be
5 changed files with 32 additions and 49 deletions

View File

@ -44,8 +44,7 @@ in
"sane-scripts.ssl-dump"
"sane-scripts.sudo-redirect"
"sane-scripts.sync-from-servo"
"sane-scripts.vpn-down"
"sane-scripts.vpn-up"
"sane-scripts.vpn"
"sane-scripts.which"
"sane-scripts.wipe-browser"
];

View File

@ -197,13 +197,8 @@ let
pkgs = [ "ffmpeg" "sox" ];
pyPkgs = [ "unidecode" ];
};
vpn-down = static-nix-shell.mkBash {
pname = "sane-vpn-down";
src = ./src;
pkgs = [ "coreutils-full" "gnugrep" "gnused" "sane-scripts.ip-check" "systemd" ];
};
vpn-up = static-nix-shell.mkBash {
pname = "sane-vpn-up";
vpn = static-nix-shell.mkBash {
pname = "sane-vpn";
src = ./src;
pkgs = [ "coreutils-full" "gnugrep" "gnused" "sane-scripts.ip-check" "systemd" ];
};

View File

@ -0,0 +1,29 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils-full -p gnugrep -p gnused -p sane-scripts.ip-check -p systemd
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')
if ! [ $(echo "$vpns" | grep "^$region$") ]
then
echo "invalid vpn name '$region'"
echo "choices:"
echo "$vpns"
exit 1
fi
iface=wg-quick-ovpnd-$region.service
echo before: $(sane-ip-check --no-upnp)
if [ "$oper" == up ]; then
sudo systemctl start $iface
elif [ "$oper" == down ]; then
sudo systemctl stop $iface
else
echo "invalid operation '$oper'"
exit 1
fi
echo after: $(sane-ip-check --no-upnp)

View File

@ -1,20 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils-full -p gnugrep -p gnused -p sane-scripts.ip-check -p systemd
# first arg should be the region, 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')
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: $(sane-ip-check --no-upnp)
sudo systemctl stop $iface
echo plain: $(sane-ip-check --no-upnp)

View File

@ -1,20 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils-full -p gnugrep -p gnused -p sane-scripts.ip-check -p systemd
# first arg should be the region, 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')
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: $(sane-ip-check --no-upnp)
sudo systemctl start $iface
echo vpn: $(sane-ip-check --no-upnp)