File suse.patch of Package amneziawg-tools

diff -uNr old/amneziawg-tools-1.0.20240201/src/wg-quick/linux.bash new/amneziawg-tools-1.0.20240201/src/wg-quick/linux.bash
--- /src/wg-quick/linux.bash	2024-02-01 18:52:10.000000000 +0300
+++ /src/wg-quick/linux.bash	2024-10-01 15:57:11.834226283 +0300
@@ -362,6 +362,60 @@
 }
 
 # ~~ function override insertion point ~~
+set_dns() {
+    [[ ${#DNS[@]} -gt 0 ]] || return 0
+
+    if [[ $(resolvconf --version 2>/dev/null) == openresolv\ * ]]; then
+	{ printf 'nameserver %s\n' "${DNS[@]}"
+	  [[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
+	} | cmd resolvconf -a "$INTERFACE" -m 0 -x
+    # Don't ruin a proper split dns setup
+    elif [[ "$(readlink /etc/resolv.conf)" != "/run/systemd/resolve/stub-resolv.conf" ]] ; then
+	echo "[#] mount \`${DNS[*]}' /etc/resolv.conf" >&2
+	[[ -e /etc/resolv.conf ]] || touch /etc/resolv.conf
+	{ cat <<-_EOF
+	    # This file was generated by awg-quick(8) for use with
+	    # the WireGuard interface $INTERFACE. It cannot be
+	    # removed or altered directly. You may remove this file
+	    # by running \`awg-quick down $INTERFACE', or if that
+	    # poses problems, run \`umount /etc/resolv.conf'.
+
+	_EOF
+	printf 'nameserver %s\n' "${DNS[@]}"
+	[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
+	} | unshare -m --propagation shared bash -c "$(cat <<-_EOF
+	    set -e
+	    context="\$(stat -c %C /etc/resolv.conf 2>/dev/null)" || unset context
+	    mount --make-private /dev/shm
+	    mount -t tmpfs none /dev/shm
+	    cat > /dev/shm/resolv.conf
+	    [[ -z \$context || \$context == "?" ]] || chcon "\$context" /dev/shm/resolv.conf 2>/dev/null || true
+	    mount -o remount,ro /dev/shm
+	    mount -o bind,ro /dev/shm/resolv.conf /etc/resolv.conf
+	_EOF
+	)"
+    fi
+    # If systemd-resolved is installed, set the dns configuration there (as well).
+    # It might be used additionally (eg for containers) or even for the whole system.
+    # A teardown is not really needed as resolvectl detects the interface disappearing.
+    if resolvectl status >/dev/null 2>&1 ; then
+	cmd resolvectl dns "$INTERFACE" "${DNS[@]}"
+	# Prefix each domain with '~' which will tell resolvectl to use that domain
+	# for dns routing but not as a search domain
+	cmd resolvectl domain "$INTERFACE" ${DNS_SEARCH[*]/#/\~}
+    fi
+    HAVE_SET_DNS=1
+}
+
+unset_dns() {
+    [[ ${#DNS[@]} -gt 0 ]] || return 0
+
+    if [[ $(resolvconf --version 2>/dev/null) == openresolv\ * ]]; then
+	cmd resolvconf -d "$INTERFACE"
+    else
+	cmd umount /etc/resolv.conf
+    fi
+}
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
 	cmd_usage
openSUSE Build Service is sponsored by