We should use lower case for normal variables.
[openresolv] / named.in
old mode 100755 (executable)
new mode 100644 (file)
index 0a3f8f1..c7b8806
--- 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.
+[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
+. "@SYSCONFDIR@/resolvconf.conf" || exit 1
+[ -z "${named_zones}" -o -z "${named_options}" ] && exit 0
+eval "$("${RESOLVCONF:-resolvconf}" -v)"
 
-# 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"
-
-NEWOPTIONS="# Generated by resolvconf\n"
-NEWZONES="${NEWOPTIONS}"
-FORWARD=
-for N in ${NAMESERVERS}; do
-       case "${FORWARD}" in
-               *"\n\t${N};"*);;
-               *) FORWARD="${FORWARD}\n\t${N};";;
+newoptions="# Generated by resolvconf\n"
+newzones="${newoptions}"
+forward=
+for n in ${NAMESERVERS}; do
+       case "${forward}" in
+       *"\n\t${n};"*);;
+       *) forward="${forward}\n\t${n};";;
        esac
 done
-if [ -n "${FORWARD}" ]; then
-       NEWOPTIONS="${NEWOPTIONS}forward first;\nforwarders {${FORWARD}\n};\n"
+if [ -n "${forward}" ]; then
+       newoptions="${newoptions}forward first;\nforwarders {${forward}\n};\n"
 fi
 
-for D in ${DOMAINS}; do
-       NEWZONES="${NEWZONES}zone \"${D%%:*}\" {\n"
-       NEWZONES="${NEWZONES}\ttype forward;\n\tforward first;\n\tforwarders {\n"
-       NS="${D#*:}"
-       while [ -n "${NS}" ]; do
-               NEWZONES="${NEWZONES}\t\t${NS%%,*};\n"
-               [ "${NS}" = "${NS#*,}" ] && break
-               NS="${NS#*,}"
+for d in ${DOMAINS}; do
+       newzones="${newzones}zone \"${d%%:*}\" {\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"
+               [ "${ns}" = "${ns#*,}" ] && break
+               ns="${ns#*,}"
        done
-       NEWZONES="${NEWZONES}\t};\n};\n"
+       newzones="${newzones}\t};\n};\n"
 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}"
-               RELOAD="yes"
+changed=false
+if [ -f "${named_options}" ]; then 
+       if [ "$(cat "${named_options}")" != "$(printf "${newoptions}")" ]; then
+               printf "${newoptions}" > "${named_options}"
+               changed=true
        fi
 else
-       printf "${NEWOPTIONS}" > "${NAMEDOPTIONS}"
-       RELOAD="yes"
+       printf "${newoptions}" > "${named_options}"
+       changed=true
 fi
-if [ -e "${NAMEDZONES}" ]; then
-       if [ "$(cat "${NAMEDZONES}")" != "$(printf "${NEWZONES}")" ]; then
-               printf "${NEWZONES}" > "${NAMEDZONES}"
-               RELOAD="yes"
+if [ -f "${named_zones}" ]; then
+       if [ "$(cat "${named_zones}")" != "$(printf "${newzones}")" ]; then
+               printf "${newzones}" > "${named_zones}"
+               changed=true
        fi
 else
-       printf "${NEWZONES}" > "${NAMEDZONES}"
-       RELOAD="yes"
+       printf "${newzones}" > "${named_zones}"
+       changed=true
 fi
 
-[ "${RELOAD}" = "yes" ] && resolvconf -s named restart
-
+${changed} && resolvconf -s named restart
 exit 0