Awesome
polybar-wireguard
A simple Polybar script to display and control WireGuard VPNs.
- Displays the currently connected configuration,
- Defines
--connect
,--disconnect
, and--toggle
switches that can be mapped to different mouse clicks.
Dependencies
dmenu
so that you can select a WireGuard config from a menu when connecting. This can be replaced by something like rofi or removed altogether by hard-coding a config in the script. You can find my version ofdmenu
here.networkctl
to query currently connected interface without needing sudo. I used to usewg
for this butwg
needs sudo access and calling it in a loop generated a lot of warnings and logs.- Material design icons for the icon.
Installation
wg-quick
binary needs sudo access to run which isn't great news for scripting. I have therefore added a specific rule to my/etc/sudoers
(viavisudo
) to make them password-less:
INSERT_YOUR_USERNAME ALL = (root) NOPASSWD: /usr/bin/wg-quick
⚠️ You obviously don't want to do this for a user who doesn't already have sudo access! WireGuard let's you to add hooks for various events which could let a non-sudo user run arbitrary code.
-
Edit the
configs_path
variable in the script to point it to where your WireGuard configs live. If they're in/etc/wireguard
you might have to make sure permissions of that directory allows listing the files inside it. I believe by default that directory is only accessible by root. -
If you're keeping the default icon from Material font, make sure the font is configured correctly in Polybar and the script. Note that the Polybar font indexing is off by 1. The unmodified script expects the following in the Polybar:
font-3 = Material Icons:style=Regular:size=15
- Add a module to Polybar. For example:
[module/wireguard]
type = custom/script
exec = /PATH/TO/wireguard_polybar
tail = false
interval = 1
click-left = /PATH/TO/wireguard_polybar --toggle &