setup for vpns

This commit is contained in:
pika 2025-06-22 21:08:35 +02:00
parent 927ad87cf9
commit 002ff2ea0c
2 changed files with 37 additions and 0 deletions

35
scripts/wireguard-setup Executable file
View file

@ -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 "$@"