Skip to content

Instantly share code, notes, and snippets.

@ochafik
Created December 28, 2021 02:04
Show Gist options
  • Save ochafik/bcea0bdd3c0ea44e638409694543ba9e to your computer and use it in GitHub Desktop.
Save ochafik/bcea0bdd3c0ea44e638409694543ba9e to your computer and use it in GitHub Desktop.
Wrapper around `wg show` that uses pivpn configuration names instead of peer ids
#!/bin/bash
#
# Beautifies output of `wg show` using config names from pivpn
#
wg show | awk "BEGIN { $(
# Map peer to preshared key
wg show all preshared-keys | awk '{ print "key[\"" $2 "\"] = \"" $3 "\";" }'
for f in $( ( . /etc/pivpn/wireguard/setupVars.conf ; echo $install_home ) )/configs/* ; do
# Map preshared key to config name
printf 'name["%s"] = "%s";\n' \
"$( cat $f | grep PresharedKey | sed 's/.*= //' )" \
"$( basename $f | sed 's/.conf$//' )"
done
) } /peer/ { print name[key[\$2]] ; next } { print \$0 }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment