config files
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Unfortunately it's not easy to directly use Polybar colour values in this
|
||||
# script so I have to redefine some of my colours here. See the link below for
|
||||
# more details:
|
||||
# https://github.com/polybar/polybar/wiki/Formatting#format-tags-inside-polybar-config
|
||||
green=#55aa55
|
||||
br=#cfd1cd
|
||||
configs_path="/etc/wireguard/"
|
||||
connected_interface=$(networkctl | grep -P "\d+ .* wireguard routable" -o | cut -d" " -f2)
|
||||
|
||||
connect() {
|
||||
selected_config=$(ls $configs_path/*.conf | xargs basename -a -s .conf | rofi -dmenu -theme ~/.config/bspwm/themes/bspwm_nord/rofi/menu.rasi -p "WG choose")
|
||||
[[ $selected_config ]] && sudo /usr/bin/wg-quick up "$configs_path"/"$selected_config".conf
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
# Normally we should have a single connected interface but technically
|
||||
# there's nothing stopping us from having multiple active intgerfaces so
|
||||
# let's do this in a loop:
|
||||
for connected_config in $(networkctl | grep -P "\d+ .* wireguard routable" -o | cut -d" " -f2)
|
||||
do
|
||||
sudo /usr/bin/wg-quick down $configs_path/"$connected_config".conf
|
||||
done
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if [[ $connected_interface ]]
|
||||
then
|
||||
disconnect
|
||||
else
|
||||
connect
|
||||
fi
|
||||
}
|
||||
|
||||
print() {
|
||||
if [[ $connected_interface ]]
|
||||
then
|
||||
echo %{u"$green"}%{+u}%{T2}%{F"$green"} VPN: "$connected_interface%"{T-}%{F-}
|
||||
else
|
||||
echo %{u"$br"}%{+u}%{T2}%{F"$br"} VPN: off%{T-}%{F-} "$connected_interface"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--connect)
|
||||
connect
|
||||
;;
|
||||
--disconnect)
|
||||
disconnect
|
||||
;;
|
||||
--toggle)
|
||||
toggle
|
||||
;;
|
||||
*)
|
||||
print
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user