diff --git a/auto-exec.conf b/auto-exec.conf index b348ee8..58a24d1 100644 --- a/auto-exec.conf +++ b/auto-exec.conf @@ -7,3 +7,5 @@ exec-once = $hypr/scripts/init exec-once = hypridle exec-once = dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP exec-once = copyq --start-server +# exec-once = foot "sudo bash $HOME/.config/hypr/scripts/wireguard-setup" +exec-once = kitty bash -c "echo 'VPN-Setup:' && sudo $HOME/.config/hypr/scripts/wireguard-setup" diff --git a/scripts/wireguard-setup b/scripts/wireguard-setup new file mode 100755 index 0000000..ecd5cf6 --- /dev/null +++ b/scripts/wireguard-setup @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# ─< Check if the given command exists silently >───────────────────────────────────────── +command_exists() { + command -v "$@" >/dev/null 2>&1 +} + +wg-setup() { + shopt -s nullglob + local peers=() + local ip + ip="$(ip ad)" + + for p in /etc/wireguard/*; do + # NOTE: + # get names without .conf + # /etc/wireguard/wg0.conf would convert to `wg0` only + peers+=("$(basename ${p%.conf})") + done + + case "${1:-up}" in + up) + cmd="wg-quick up" + ;; + down) + cmd="wg-quick down" + ;; + esac + + for peer in "${peers[@]}"; do + $cmd $peer + done +} + +wg-setup "$@"