diff --git a/update_wg_dns b/update_wg_dns new file mode 100755 index 0000000..c2bb987 --- /dev/null +++ b/update_wg_dns @@ -0,0 +1,30 @@ +#!/bin/bash + +NETWORKMANAGER_NETCONFIG="/var/run/netconfig/NetworkManager.netconfig" + +dns-update() { + tmpfile=$(mktemp) + sed --regexp-extended "s/(DNSSERVERS=)'(.*?)'/\1'$@ \2'/g" "${NETWORKMANAGER_NETCONFIG}" > "${tmpfile}" + netconfig modify -s NetworkManager -I "${tmpfile}" + rm -f "${tmpfile}" +} + +dns-restore() { + tmpfile=$(mktemp) + sed --regexp-extended "s/$@ //g" "${NETWORKMANAGER_NETCONFIG}" > "${tmpfile}" + netconfig modify -s NetworkManager -I ${tmpfile} + rm -f ${tmpfile} +} + +dns() { + local cmdname=$1; shift + "dns-$cmdname" "$@" +} + +if declare -f "$1" >/dev/null 2>&1; then + # invoke that function, passing arguments through + "$@" # same as "$1" "$2" "$3" ... for full argument list +else + echo "Function $1 not recognized" >&2 + exit 1 +fi