On 19.09.19 21:19, Adam D. Barratt wrote:
> Sadly not. Instead, you CCed "[email protected],
you are right...

I don't know what's happend to my mail client....

but as Simon told before, there is already a package vor systemd.
I've looked at it and it does some more the mine. As it still uses
that complicated DBUS communication, which was needed before
systemd-resolve --set-XXX was implemented, I give my smaller
patch another try to be attached. Even if I think this bug can
be closed, and the proposed openvpn package should be stronger
emphased.

Regards
   Holger

From a729bf790b032bddcfe515aa0c5a32825eaf931d Mon Sep 17 00:00:00 2001
From: Holger Mueller <[email protected]>
Date: Wed, 18 Sep 2019 17:47:40 +0200
Subject: [PATCH] Added update-systemd-resolve

   added a script to update dns settings of systemd-resolved
   it's derived from the existing update-resolv-conf
---
 debian/README.Debian          |  9 +++++++
 debian/rules                  |  1 +
 debian/update-systemd-resolve | 45 +++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 debian/update-systemd-resolve

diff --git a/debian/README.Debian b/debian/README.Debian
index 29b15fe..a61bf9d 100644
--- a/debian/README.Debian
+++ b/debian/README.Debian
@@ -206,6 +206,15 @@ down /etc/openvpn/update-resolv-conf

 You will need to install resolvconf package.

+Using systemd-resolve
+---------------------
+
+Have a look at the shell script /etc/openvpn/update-systemd-resolve
+It parses DHCP options from openvpn to update systemd-resolved.
+To use set it as 'up' script in your openvpn *.conf:
+
+up /etc/openvpn/update-systemd-resolve
+
 Out of Memory issues
 -------------------

diff --git a/debian/rules b/debian/rules
index 7bec9d2..008cebc 100755
--- a/debian/rules
+++ b/debian/rules
@@ -55,6 +55,7 @@ override_dh_auto_install:
 	$(RM) $(CURDIR)/debian/openvpn/usr/lib/$(DEB_HOST_GNU_TYPE)/openvpn/plugins/*.la
 	# resolvconf script
 	install -m 755 debian/update-resolv-conf $(CURDIR)/debian/openvpn/etc/openvpn/update-resolv-conf
+	install -m 755 debian/update-systemd-resolve $(CURDIR)/debian/openvpn/etc/openvpn/update-systemd-resolve
 	# bash completion
 	install -m 644 debian/openvpn.bash_completion $(CURDIR)/debian/openvpn/usr/share/bash-completion/completions/openvpn
 	# append Debian's tmpfiles conf to upstream's on Linux (systemd)
diff --git a/debian/update-systemd-resolve b/debian/update-systemd-resolve
new file mode 100644
index 0000000..54ea62b
--- /dev/null
+++ b/debian/update-systemd-resolve
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Parses DHCP options from openvpn to update systemd-resolve
+# To use set as 'up' script in your openvpn *.conf:
+# script-security 2
+# up /etc/openvpn/update-resolv-conf
+#
+# Used snippets of resolvconf script by Thomas Hood and Chris Hanson.
+# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
+#
+# Example envs set from openvpn:
+#
+#     foreign_option_1='dhcp-option DNS 193.43.27.132'
+#     foreign_option_2='dhcp-option DNS 193.43.27.133'
+#     foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
+#
+set -x
+
+RESOLVE=/usr/bin/systemd-resolve
+[ -x $RESOLVE ] || exit 0
+[ "$script_type" ] || exit 0
+[ "$dev" ] || exit 0
+
+split_into_parts()
+{
+	part1="$1"
+	part2="$2"
+	part3="$3"
+}
+
+DNSOPTS=""
+for optionvarname in ${!foreign_option_*} ; do
+	option="${!optionvarname}"
+	echo "$option"
+	split_into_parts $option
+	if [ "$part1" = "dhcp-option" ] ; then
+		if [ "$part2" = "DNS" ] ; then
+			DNSOPTS="${DNSOPTS+$DNSOPTS }--set-dns=$part3"
+		elif [ "$part2" = "DOMAIN" ] ; then
+			DNSOPTS="${DNSOPTS+$DNSOPTS }--set-domain=$part3"
+		fi
+	fi
+done
+[ "$DNSOPTS" ] && $RESOLVE -i $dev $DNSOPTS
+
--
2.17.1


Reply via email to