Hi Nathan,

On 08/04/2018 01:01 AM, Nathan Chancellor wrote:
> I'd argue a better way to check if a command is available is the command
> built-in:
> 
> if command -v resolvconf >/dev/null; then
>     do stuff
> fi

good point, updated patch and added support for systemd-resolve in case
resolvectl is not present.

j
diff --git a/src/tools/wg-quick/linux.bash b/src/tools/wg-quick/linux.bash
index 3f1976b..b8ef60b 100755
--- a/src/tools/wg-quick/linux.bash
+++ b/src/tools/wg-quick/linux.bash
@@ -151,13 +151,23 @@ resolvconf_iface_prefix() {
 HAVE_SET_DNS=0
 set_dns() {
 	[[ ${#DNS[@]} -gt 0 ]] || return 0
-	printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
+	if command -v resolvconf >/dev/null; then
+		printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
+	elif command -v resolvectl >/dev/null; then
+		cmd resolvectl dns $INTERFACE "${DNS[@]}"
+	elif command -v systemd-resolve >/dev/null && systemd-resolve --help | grep -- -set-dns >/dev/null; then
+		cmd systemd-resolve -i $INTERFACE `printf -- ' --set-dns %s' "${DNS[@]}"`
+	else
+		echo "could not configure nameservers" && return 0
+	fi
 	HAVE_SET_DNS=1
 }
 
 unset_dns() {
 	[[ ${#DNS[@]} -gt 0 ]] || return 0
-	cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
+	if [ -x /usr/bin/resolvconf ]; then
+		cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
+	fi
 }
 
 add_route() {

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

Reply via email to