-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwireguard-manager.sh
More file actions
executable file
·32 lines (27 loc) · 945 Bytes
/
Copy pathwireguard-manager.sh
File metadata and controls
executable file
·32 lines (27 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
SERVICE_NAME="wg-quick@wg0"
STATUS_CONNECTED_STR='{"text":"Connected","class":"connected","alt":"connected"}'
STATUS_DISCONNECTED_STR='{"text":"Disconnected","class":"disconnected","alt":"disconnected"}'
function askpass() {
rofi -dmenu -password -no-fixed-num-lines -p "Sudo password : " -theme ~/.config/waybar/wireguard-manager/rofi.rasi
}
function status_wireguard() {
systemctl is-active $SERVICE_NAME >/dev/null 2>&1
return $?
}
function toggle_wireguard() {
status_wireguard && \
SUDO_ASKPASS=~/.config/waybar/wireguard-manager/wireguard-manager.sh sudo -A systemctl stop $SERVICE_NAME || \
SUDO_ASKPASS=~/.config/waybar/wireguard-manager/wireguard-manager.sh sudo -A systemctl start $SERVICE_NAME
}
case $1 in
-s | --status)
status_wireguard && echo $STATUS_CONNECTED_STR || echo $STATUS_DISCONNECTED_STR
;;
-t | --toggle)
toggle_wireguard
;;
*)
askpass
;;
esac