Skip to content

Instantly share code, notes, and snippets.

@bplaxco
Created April 19, 2026 15:54
Show Gist options
  • Select an option

  • Save bplaxco/2a963314bd476185e62de404c251da0a to your computer and use it in GitHub Desktop.

Select an option

Save bplaxco/2a963314bd476185e62de404c251da0a to your computer and use it in GitHub Desktop.
Manage first NetworkManager wireguard profile based on first wifi interface actions
#!/usr/bin/env bash
# Place at: /etc/NetworkManager/dispatcher.d/00_vpn.sh
set -euo pipefail
interface="$1"
action="$2"
wifi_interface="$(nmcli device | awk '{ if ($2 == "wifi") { print $1 }}' | head -n 1)"
wireguard_profile="$(nmcli con show | awk '{ if ($3 == "wireguard") { print $2 }}' | head -n 1)"
if [[ "${interface}" == "${wifi_interface}" ]]
then
nmcli con "${action}" "${wireguard_profile}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment