The resolvconf script now works with the busybox, BSD and dash shells.
authorRoy Marples <uberlord@gentoo.org>
Tue, 10 Apr 2007 15:11:03 +0000 (15:11 +0000)
committerRoy Marples <uberlord@gentoo.org>
Tue, 10 Apr 2007 15:11:03 +0000 (15:11 +0000)
It also configures the domain specific servers using DBus provided both
dnsmasq and dbus are running.
Package-Manager: portage-2.1.2.3

net-dns/dnsmasq/ChangeLog
net-dns/dnsmasq/Manifest
net-dns/dnsmasq/files/resolvconf.dnsmasq

index 6442c49a9e54ea4cbc151a9befa2cf5a86cad927..6882fc995733192b6f8896c445a86515ff970ff6 100644 (file)
@@ -1,6 +1,11 @@
 # ChangeLog for net-dns/dnsmasq
 # Copyright 2002-2007 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/net-dns/dnsmasq/ChangeLog,v 1.120 2007/04/06 10:26:22 dertobi123 Exp $
+# $Header: /var/cvsroot/gentoo-x86/net-dns/dnsmasq/ChangeLog,v 1.121 2007/04/10 15:11:03 uberlord Exp $
+
+  10 Apr 2007; Roy Marples <uberlord@gentoo.org> files/resolvconf.dnsmasq:
+  The resolvconf script now works with the busybox, BSD and dash shells.
+  It also configures the domain specific servers using DBus provided both
+  dnsmasq and dbus are running.
 
   06 Apr 2007; Tobias Scherbaum <dertobi123@gentoo.org>
   dnsmasq-2.38-r1.ebuild:
index dbe6b707ff22c4c932a5d5b94cedf4b1b9ce28ea..eef3a94d1c2db949fed0edde4a1869cc50669212 100644 (file)
@@ -10,10 +10,10 @@ AUX dnsmasq.confd 140 RMD160 33f6370377b38bf33acab72d8de86cba5e197d79 SHA1 83461
 MD5 5990c2d2cb92209feacf8f3a5a7d0831 files/dnsmasq.confd 140
 RMD160 33f6370377b38bf33acab72d8de86cba5e197d79 files/dnsmasq.confd 140
 SHA256 8bbc2634ab537ed3a17ee98be9c2667013a2b048f6981138017414e54fe90746 files/dnsmasq.confd 140
-AUX resolvconf.dnsmasq 2693 RMD160 ae2243cf5b68aa4fcb2f482115c6d4e49889de6a SHA1 a7082a24bde8ae2bdd4919e2079134b45c761160 SHA256 ff3518048270e1635126d630a27ec88873cc559327341d1f0b786f5c127f1575
-MD5 5454b4f7e8df3dafa5fecb6d016b0fb2 files/resolvconf.dnsmasq 2693
-RMD160 ae2243cf5b68aa4fcb2f482115c6d4e49889de6a files/resolvconf.dnsmasq 2693
-SHA256 ff3518048270e1635126d630a27ec88873cc559327341d1f0b786f5c127f1575 files/resolvconf.dnsmasq 2693
+AUX resolvconf.dnsmasq 4103 RMD160 e875abb38441398d5edcd9e5aa7fbd42d47f2ee0 SHA1 0b4d78656345420430591fef6a15d8e96631d68b SHA256 b1adb0003e173f58402b681ea5ce4c311183a8c0f73cb93741abe9990c2cd408
+MD5 71ca1c3e84693524fa5b28724bfc6023 files/resolvconf.dnsmasq 4103
+RMD160 e875abb38441398d5edcd9e5aa7fbd42d47f2ee0 files/resolvconf.dnsmasq 4103
+SHA256 b1adb0003e173f58402b681ea5ce4c311183a8c0f73cb93741abe9990c2cd408 files/resolvconf.dnsmasq 4103
 DIST dnsmasq-2.31.tar.gz 204338 RMD160 7f45c52a76a1edabb868c42069bc4e7710d414e5 SHA1 0dbd561f7e82f3a8a9892347c75d747e816b3b14 SHA256 bb2ec35de2392307587a213bca93fdade6b5d65168b529fc5a95b2edd134edee
 DIST dnsmasq-2.34.tar.gz 255744 RMD160 36061107fa62c433df6a02a5fffdb30acc4bf893 SHA1 81c445433d95725c23a27ad06cd6a51665d14138 SHA256 8b9d6a277abecff19ae835c7f2e66e21cc9a4d37ceb35716aa655fd899287bc0
 DIST dnsmasq-2.38.tar.gz 272953 RMD160 bfa7ca4a5ededa2aedd708991b8177274b1db8b7 SHA1 267ac7b78e9f48b0d8d65f30fc0faa2a6552ae8c SHA256 54f3e9ac2bd9f622b28ab0d5149e9bc13d62d8826be085c32abc929bc30dda6a
@@ -33,10 +33,10 @@ EBUILD dnsmasq-2.38.ebuild 1500 RMD160 cb92783097813525fd470bb54a8c379426eee0b6
 MD5 c0c6aa49db5281bd87dbd24d83f1dc72 dnsmasq-2.38.ebuild 1500
 RMD160 cb92783097813525fd470bb54a8c379426eee0b6 dnsmasq-2.38.ebuild 1500
 SHA256 c6e195455b9167fd296bbe9af5900414fe62a78dd4d6ab05382c2a5b46b06910 dnsmasq-2.38.ebuild 1500
-MISC ChangeLog 14973 RMD160 4a1dee6fa18e4298aa43ae82040eca42c0931440 SHA1 8ee3dfc1867401c8c350e686d986358eeb39745a SHA256 c66a7810bac8c074ef314a9f83d16757fd5e6e2b297855f99ccfca359d47bae0
-MD5 fe19f27e3611449bc1ad51005818802b ChangeLog 14973
-RMD160 4a1dee6fa18e4298aa43ae82040eca42c0931440 ChangeLog 14973
-SHA256 c66a7810bac8c074ef314a9f83d16757fd5e6e2b297855f99ccfca359d47bae0 ChangeLog 14973
+MISC ChangeLog 15226 RMD160 8d0b6f940d87583f0a27c080bba15a9ed449c906 SHA1 718eb1d4600faf687a9e61e8fa872808d941866d SHA256 c2713258a333124b74cd5b046da54e00e09282958c8a448cb291e999343fc86a
+MD5 1ba706f17dc3b759ff90f90c8e3c6caf ChangeLog 15226
+RMD160 8d0b6f940d87583f0a27c080bba15a9ed449c906 ChangeLog 15226
+SHA256 c2713258a333124b74cd5b046da54e00e09282958c8a448cb291e999343fc86a ChangeLog 15226
 MISC metadata.xml 251 RMD160 9f6c5022895c245c7b1fdbaa24ae19cab04502c8 SHA1 4f7b27e3a8043f87fea8d4bc308e4b947f0e8675 SHA256 fd85d2faaf1d0c0eab6a4d2ab9eaa493e087a6108aafd0a5db6436bfc181783b
 MD5 f115572f9475ea98b22ceeb627ba07f0 metadata.xml 251
 RMD160 9f6c5022895c245c7b1fdbaa24ae19cab04502c8 metadata.xml 251
index 423769a0dd5c86a881ff3927d0f8e6e95e20156b..62fc73f4118f2baf73a0a0e2cb03eecd6b59f99e 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 # Copyright 2006 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 # A sample dnsmasq config that works as above is like so
 #domain-needed
 #interface=lo
-#conf-file=/etc/dnsmasq-resolvconf.conf
 #resolv-file=/etc/dnsmasq-resolv.conf
+#conf-file=/etc/dnsmasq-resolvconf.conf
 
 # The last step is to configure dns configuration for /etc/resolv.conf
 # for the lo interface. In Gentoo we set it up like so in /etc/conf.d/net
-#dns_servers_lo=( "127.0.0.1" )
-
-# Load generic Gentoo functions
-source /etc/init.d/functions.sh
+#dns_servers_lo="127.0.0.1"
 
 # Load our variables from resolvconf
 VARS="$(resolvconf -v)"
@@ -38,52 +35,108 @@ DNSMASQCONF="/etc/dnsmasq-resolvconf.conf"
 NEWCONF="# Generated by resolvconf"
 NEWRESOLV="${NEWCONF}\nsearch"
 
+# Using DBUS means that we never have to restart the daemon
+# This is important as it means we should not drop DNS queries
+# whilst changing DNS options around. However, DBUS support is optional
+# so we need to validate a few things first.
+# Check for DBus support in the binary
+DBUS=no
+if dnsmasq --version 2>/dev/null | \
+grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]" \
+; then
+       # Sanity - check that dnsmasq and dbus are running
+       if [ -x /etc/init.d/dbus -a -x /etc/init.d/dnsmasq ] ; then
+               if /etc/init.d/dbus --quiet status && /etc/init.d/dnsmasq --quiet status ; then
+                       DBUS=yes
+                       NEWCONF="${NEWCONF}\n# Domain specific servers will be sent over dbus\n\nenable-dbus"
+               fi
+       fi
+fi
+
+uniqify() {
+    local result=
+    while [ -n "$1" ] ; do
+               case " ${result} " in
+                       *" $1 "*) ;;
+                       *) result="${result} $1" ;;
+               esac
+               shift
+       done
+    echo "${result# *}"
+}
+
 # If we only have domain information then put it in search too
-[[ -z ${NEWSEARCH} && -z ${NEWNS} ]] && NEWSEARCH="${NEWDOMAIN}"
+[ -z "${NEWSEARCH}" -a -z "${NEWNS}" ] && NEWSEARCH="${NEWDOMAIN}"
 
 for N in ${NEWSEARCH} ; do
-       if [[ " ${NEWSL} " != *" ${N%,*} "* ]] ; then
-               NEWSL="${NEWSL} ${N%,*}"
-       fi
-       if [[ "\n${NEWRESOLV}\n" != *"\nnameserver ${N#*,}\n"* ]] ; then
-               NEWRESOLV="${NEWRESOLV}\nnameserver ${N#*,}"
-       fi
+       case " ${NEWSL} " in
+               *" ${N%,*} "*) ;;
+               *) NEWSL="${NEWSL} ${N%,*}" ;;
+       esac
+       case "\n${NEWRESOLV}\n" in
+               *"\nnameserver ${N#*,}\n"*) ;;
+               *) NEWRESOLV="${NEWRESOLV}\nnameserver ${N#*,}" ;;
+       esac
 done
 for N in ${NEWNS} ; do
-       if [[ "\n${NEWRESOLV}\n" != *"\nnameserver ${N}\n" ]] ; then
-               NEWRESOLV="${NEWRESOLV}\nnameserver ${N}"
-       fi
+       case "\n${NEWRESOLV}\n" in
+               *"\nnameserver ${N}\n") ;;
+               *) NEWRESOLV="${NEWRESOLV}\nnameserver ${N}" ;;
+       esac
 done
-NEWRESOLV="${NEWRESOLV//\\nsearch/${NEWSL:+\nsearch${NEWSL}}}"
+NEWRESOLV="$(echo "${NEWRESOLV}" | sed -e "s/^search/${NEWSL:+search${NEWSL}}/g")"
 
+DBUSDEST=
 for DN in $(uniqify ${NEWDOMAIN}) ; do
-       NEWCONF="${NEWCONF}\nserver=/${DN%,*}/${DN#*,}"
+       if [ "${DBUS}" = "yes" ] ; then
+               IP=${DN#*,}
+               SIFS=${IFS-y} OIFS=$IFS
+               IFS=.
+               set -- ${IP}
+               NUM="0x$(printf "%02x" $1 $2 $3 $4)"
+               if [ "${SIFS}" = "y" ] ; then
+                       IFS=$OIFS
+               else
+                       unset IFS
+               fi
+               DBUSDEST="${DBUSDEST} uint32:$(printf "%d" ${NUM}) string:${DN%,*}"
+       else
+               NEWCONF="${NEWCONF}\nserver=/${DN%,*}/${DN#*,}"
+       fi
 done
 
 RELOAD="no"
-if [[ -e ${DNSMASQCONF} ]] ; then
-       if [[ $(< "${DNSMASQCONF}") != "$(echo -e "${NEWCONF}")" ]] ; then
+if [ -e "${DNSMASQCONF}" ] ; then
+       if [ "$(cat "${DNSMASQCONF}")" != "$(printf "${NEWCONF}")" ] ; then
                RELOAD="yes"
-               echo -e "${NEWCONF}" > "${DNSMASQCONF}"
+               printf "${NEWCONF}" > "${DNSMASQCONF}"
        fi
 else
        RELOAD="yes"
-       echo -e "${NEWCONF}" > "${DNSMASQCONF}"
+       printf "${NEWCONF}" > "${DNSMASQCONF}"
 fi
-if [[ -e ${DNSMASQRESOLV}} ]] ; then
-       if [[ $(< "${DNSMASQRESOLV}") != "$(echo -e "${NEWRESOLV}")" ]] ; then
+if [ -e "${DNSMASQRESOLV}" ] ; then
+       if [ "$(cat "${DNSMASQRESOLV}")" != "$(printf "${NEWRESOLV}")" ] ; then
                RELOAD="yes"
-               echo -e "${NEWRESOLV}" > "${DNSMASQRESOLV}"
+               printf "${NEWRESOLV}" > "${DNSMASQRESOLV}"
        fi
 else
        # dnsmasq polls this file so no need to set RELOAD="yes"
-       echo -e "${NEWRESOLV}" > "${DNSMASQRESOLV}"
+       printf "${NEWRESOLV}" > "${DNSMASQRESOLV}"
+fi
+
+if [ "${RELOAD}" = "yes" -a -x /etc/init.d/dnsmasq ] ; then
+       /etc/init.d/dnsmasq --quiet --nodeps conditionalrestart
 fi
 
-if [[ ${RELOAD} == "yes" && -x /etc/init.d/dnsmasq ]] ; then
-       if /etc/init.d/dnsmasq --quiet status ; then
-               /etc/init.d/dnsmasq --quiet --nodeps restart
+if [ "${DBUS}" = "yes" ] ; then
+       if [ "${RELOAD}" != "yes" -a -x /etc/init.d/dnsmasq ] ; then
+               /etc/init.d/dnsmasq --quiet reload
        fi
+       # Send even if emtpy so old servers are cleared
+       dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
+               /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \
+               ${DBUSDEST}
 fi
 
 # vim: ts=4 :