We need to process dynamic interfaces without metrics before ones
[openresolv] / named.in
index 0a3f8f197ca6531df1453e2fdf5f4f7583c9afd0..6e9cfa0d0d5294629ee319900c9318136fc584d6 100644 (file)
--- a/named.in
+++ b/named.in
@@ -1,8 +1,8 @@
 #!/bin/sh
-# Copyright 2007 Roy Marples <roy@marples.name>
+# Copyright 2007-2009 Roy Marples <roy@marples.name>
 # All rights reserved
 
-# named updater for resolvconf
+# named subscriber for resolvconf
 
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-# This is very important!
-# We assume that we are a local dns cache - after all, why would a server
-# use resolvconf?
-# Now that we have assumed this, we also assume that generic DHCP clients
-# will enter their domains and search domains ONLY in the "search" field
-# in their resolv.confs and VPN clients will put the domain they are for
-# into the domain field only.
-# This allows bind to forward domains for a specific VPN domain to the
-# VPN nameserver and everything else to the standard name servers.
-
-# The bind config needs to be setup to include our file
-#options {
-#   include "resolvconf-options.conf";
-#};
-#include "resolvconf-zones.conf";
-
-# The last step is to configure dns configuration for /etc/resolv.conf
-#echo "nameserver 127.0.0.1" > /etc/resolvconf/resolv.conf.d/base
-# On some platforms, like FreeBSD, resolvconf is in /usr/local so it becomes
-#echo "nameserver 127.0.0.1" > /usr/local/etc/resolvconf/resolv.conf.d/base
-
-# Load our variables from resolvconf
-eval "$(resolvconf -v)"
-
-# If our dir doesn't exist then don't do anything
-NAMEDB=/etc/namedb
-[ -d "${NAMEDB}" ] || NAMEDB="/etc/bind"
-[ -d "${NAMEDB}" ] || exit 0
-
-NAMEDOPTIONS="${NAMEDB}/resolvconf-options.conf"
-NAMEDZONES="${NAMEDB}/resolvconf-zones.conf"
+[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
+. "@SYSCONFDIR@/resolvconf.conf" || exit 1
+[ -z "${named_zones}" -o -z "${named_options}" ] && exit 0
+eval "$("${RESOLVCONF:-resolvconf}" -v)"
 
 NEWOPTIONS="# Generated by resolvconf\n"
 NEWZONES="${NEWOPTIONS}"
 FORWARD=
 for N in ${NAMESERVERS}; do
        case "${FORWARD}" in
-               *"\n\t${N};"*);;
-               *) FORWARD="${FORWARD}\n\t${N};";;
+       *"\n\t${N};"*);;
+       *) FORWARD="${FORWARD}\n\t${N};";;
        esac
 done
 if [ -n "${FORWARD}" ]; then
@@ -73,7 +46,8 @@ fi
 
 for D in ${DOMAINS}; do
        NEWZONES="${NEWZONES}zone \"${D%%:*}\" {\n"
-       NEWZONES="${NEWZONES}\ttype forward;\n\tforward first;\n\tforwarders {\n"
+       NEWZONES="${NEWZONES}\ttype forward;\n"
+       NEWZONES="${NEWZONES}\tforward first;\n\tforwarders {\n"
        NS="${D#*:}"
        while [ -n "${NS}" ]; do
                NEWZONES="${NEWZONES}\t\t${NS%%,*};\n"
@@ -86,25 +60,24 @@ done
 # No point in changing files or reloading bind if the end result has not
 # changed
 RELOAD="no"
-if [ -e "${NAMEDOPTIONS}" ]; then 
-       if [ "$(cat "${NAMEDOPTIONS}")" != "$(printf "${NEWOPTIONS}")" ]; then
-               printf "${NEWOPTIONS}" > "${NAMEDOPTIONS}"
+if [ -f "${named_options}" ]; then 
+       if [ "$(cat "${named_options}")" != "$(printf "${NEWOPTIONS}")" ]; then
+               printf "${NEWOPTIONS}" > "${named_options}"
                RELOAD="yes"
        fi
 else
-       printf "${NEWOPTIONS}" > "${NAMEDOPTIONS}"
+       printf "${NEWOPTIONS}" > "${named_options}"
        RELOAD="yes"
 fi
-if [ -e "${NAMEDZONES}" ]; then
-       if [ "$(cat "${NAMEDZONES}")" != "$(printf "${NEWZONES}")" ]; then
-               printf "${NEWZONES}" > "${NAMEDZONES}"
+if [ -f "${named_zones}" ]; then
+       if [ "$(cat "${named_zones}")" != "$(printf "${NEWZONES}")" ]; then
+               printf "${NEWZONES}" > "${named_zones}"
                RELOAD="yes"
        fi
 else
-       printf "${NEWZONES}" > "${NAMEDZONES}"
+       printf "${NEWZONES}" > "${named_zones}"
        RELOAD="yes"
 fi
 
 [ "${RELOAD}" = "yes" ] && resolvconf -s named restart
-
 exit 0