/polybar-wireguard

A simple Polybar script to display and control WireGuard VPNs.

Primary LanguageShell

polybar-wireguard

demo

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 replace by something like rofi or removed altogether by hard-coding a config in the script.
  • Material design icons for the image icon.

Installation

  1. wg and wg-quick binaries need sudo access to run which isn't great news for scripting. I have therefore added a specific rule to my /etc/sudoers (via visudo) to make them password-less:
INSERT_YOUR_USERNAME ALL = (root) NOPASSWD: /usr/bin/wg,/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.

  1. 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.

  2. 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
  1. 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 &