Created
December 11, 2023 17:09
-
-
Save wernerjoss/a6533c573fb19ecaa808482bd668b5fa to your computer and use it in GitHub Desktop.
toggle wireguard interface status, if connected: disconnect, and vice versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# toggle wireguard interface status, if connected: disconnect, and vice versa | |
# wernerjoss 11.11.23 | |
wgclient="orion" # default | |
while getopts ":c:v:" opt; do | |
case $opt in | |
c) | |
wgclient="$OPTARG" | |
;; | |
v) | |
verbose="$OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
if [ ! -z $verbose ]; then | |
echo $wgclient | |
fi | |
status=$(nmcli -o d | grep $wgclient | awk '{print $1}') | |
if [ ! -z $verbose ]; then | |
echo $status | |
fi | |
if [ $status == $wgclient ]; then | |
echo "$wgclient is up, disconnecting" | |
wg-quick down $wgclient | |
else | |
echo "$wgclient is down, connecting" | |
wg-quick up $wgclient | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment