aboutsummaryrefslogtreecommitdiff
path: root/private_dot_local/bin/executable_vpn
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
committertwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
commit2140ab51deed88e90eafebf9520fa5f9995dc7c9 (patch)
tree03cf1dcd2900495c1efb79aaa85f3254ecd5fb87 /private_dot_local/bin/executable_vpn
parentff8f50638e4b17a9d7cc88d2f0d9560b7effce39 (diff)
Migrate from stow
Diffstat (limited to 'private_dot_local/bin/executable_vpn')
-rw-r--r--private_dot_local/bin/executable_vpn31
1 files changed, 31 insertions, 0 deletions
diff --git a/private_dot_local/bin/executable_vpn b/private_dot_local/bin/executable_vpn
new file mode 100644
index 0000000..f3dc0b1
--- /dev/null
+++ b/private_dot_local/bin/executable_vpn
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+if [ "$(id -u)" != "0" ]; then
+ echo "Must be run as root"
+ exit 1
+fi
+
+# This script assumes you have some $XDG_RUNTIME_DIR set up.
+# The easiest way is systemd/elogind.
+FNAME="/run/user/1000/vpn"
+
+# Toggle vpn
+if [ -e "$FNAME" ]; then
+ read -r IF < /run/user/1000/vpn
+ echo "Bringing $IF down..."
+ wg-quick down "$IF"
+ rm "$FNAME"
+else
+ IF="$(find /etc/wireguard -type f -name "us-*" | shuf -n 1)"
+ echo "Bringing $IF up..."
+ wg-quick up "$IF"
+ echo "$IF" > $FNAME
+fi
+
+# Shorthand to [s]witch to a new server
+if [ "$1" = "-s" ] ; then
+ vpn
+else
+ true
+fi
+