#!/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 "$@"