1
0
Fork 0
mirror of https://github.com/Horhik/dotfiles.git synced 2024-11-08 09:53:13 +00:00
Dotfiles/.config/polybar/themes/monolit-dracula/polybar-scripts/vpn-wireguard-wg/vpn-wireguard-wg.sh
2020-09-05 14:43:37 +03:00

38 lines
789 B
Bash

#!/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