33 lines
657 B
Bash
Executable File
33 lines
657 B
Bash
Executable File
#!/bin/bash -e
|
|
|
|
DMENU=/usr/local/bin/dmenu
|
|
SUDO=pkexec
|
|
if tty -s; then
|
|
DMENU=fzf
|
|
SUDO=sudo
|
|
fi
|
|
|
|
d="$(mktemp -d)"
|
|
# shellcheck disable=SC2064
|
|
trap "rm -rf '$d'" EXIT
|
|
touch "$d/"{1..2}
|
|
|
|
CMD=()
|
|
while read -r i; do
|
|
CMD+=("wg-quick down '$i'")
|
|
done < <(ip -br link show type wireguard | awk '{print $1}')
|
|
|
|
if [ "$1" != off ]; then
|
|
CMD=(
|
|
"basename -s.conf '/etc/wireguard/$1'*.conf > '$d/1'"
|
|
"inotifywait -e close_write '$d/2'"
|
|
"${CMD[@]}"
|
|
"wg-quick up \"\$(cat '$d/2')\""
|
|
)
|
|
fi
|
|
|
|
(inotifywait -e close_write "$d/1"; "$DMENU" < "$d/1" > "$d/2") &
|
|
"$SUDO" bash -c "${CMD[*]/%/;}"
|
|
|
|
touch "$XDG_RUNTIME_DIR/sbar/vpn"
|