aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2023-03-08 15:58:37 +0530
committersinanmohd <pcmsinan@gmail.com>2023-03-11 19:05:05 +0530
commite4754a6c8fdbd65ed431aa0e8a50ee556c0213be (patch)
tree90df504ef83ce0e6c8ebca848eb6755af48dab08
parent1489b3dd44cd2e2534a4fa148f8541d9565fd090 (diff)
vpn: rewrite, make wip and notify-send optional, details are printed to stdout
-rw-r--r--README.md4
-rwxr-xr-xvpn47
2 files changed, 27 insertions, 24 deletions
diff --git a/README.md b/README.md
index 08904bd..9e12b66 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,9 @@ as the first argument it'll print the scraped torrent link to stdout otherwise
it will pass the link to pirowatch
## vpn
-dmenu wrapper for wireguard, depends on wip
+dmenu wrapper for wireguard, has an optional dependency on wip. you can pass
+wireguard config name as the first argument otherwise it will use the default
+value which is "wg0"
## wip - what is my ip
wip queries host's ipv4 address using opendns and displays the ip details using
diff --git a/vpn b/vpn
index 061d1f8..0e5998e 100755
--- a/vpn
+++ b/vpn
@@ -1,27 +1,28 @@
#!/bin/sh
-# https://sinanmohd.com
-####################
-## user variables ##
-####################
-# wireguard config name, located at /etc/wireguard/
-conf_name="kay"
-# state file location
-state_file="/tmp/vpn.dmenu"
+note()
+{
+ command -v notify-send > /dev/null &&
+ notify-send "撚 vpn" "$1"
+ printf "\n%s\n" "$1"
+}
-if [ ! -e "$state_file" ]
-then
- if sudo -A -p "撚 initialize vpn: " wg-quick up "$conf_name"
- then
- touch "$state_file" &&
- notify-send "撚 VPN initialized" "Traffic is routing through external server" &&
- wip
- fi
-else
- sudo -A -p "撚 halt vpn: " wg-quick down "$conf_name" &&
- rm "$state_file" &&
- notify-send "撚 VPN Halted" "Connection was dropped" &&
- sleep 3 &&
- wip
-fi
+main()
+{
+ wg_conf="${1:-wg0}"
+
+ if ip -details link show "$wg_conf" 2> /dev/null | grep "wireguard" > /dev/null 2>&1
+ then
+ sudo -A -p "撚 halt vpn: " wg-quick down "$wg_conf" &&
+ note "connection was dropped"
+ else
+ sudo -A -p "撚 initialize vpn: " wg-quick up "$wg_conf" &&
+ note "traffic routed through $wg_conf"
+ fi
+
+ command -v wip > /dev/null &&
+ wip
+}
+
+main "$@"