1
0
Fork 0
mirror of https://github.com/Horhik/dotfiles.git synced 2024-12-02 03:16:50 +00:00
Dotfiles/.config/polybar/polybar-scripts/vpn-wireguard-wg/vpn-wireguard-wg.sh

38 lines
789 B
Bash
Raw Normal View History

2020-07-27 04:59:00 +00:00
#!/bin/sh
connection_status() {
if [ -f "$config" ]; then
connection=$(sudo wg show "$config_name" 2>/dev/null | head -n 1 | awk '{print $NF }')
if [ "$connection" = "$config_name" ]; then
echo "1"
else
echo "2"
fi
else
echo "3"
fi
}
config="$HOME/wg/wireguard.conf"
config_name=$(basename "${config%.*}")
case "$1" in
--toggle)
if [ "$(connection_status)" = "1" ]; then
sudo wg-quick down "$config" 2>/dev/null
else
sudo wg-quick up "$config" 2>/dev/null
fi
;;
*)
if [ "$(connection_status)" = "1" ]; then
echo "#1 $config_name"
elif [ "$(connection_status)" = "3" ]; then
echo "#3 Config not found!"
else
echo "#2 down"
fi
;;
esac