Release openresolv-3.3.4
[openresolv] / named.in
index 6e9cfa0d0d5294629ee319900c9318136fc584d6..9d88910a7eed59080a999268cb03608983a07e71 100644 (file)
--- a/named.in
+++ b/named.in
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright 2007-2009 Roy Marples <roy@marples.name>
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
 # All rights reserved
 
 # named subscriber for resolvconf
 
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
-[ -z "${named_zones}" -o -z "${named_options}" ] && exit 0
-eval "$("${RESOLVCONF:-resolvconf}" -v)"
+[ -z "$named_zones" -a -z "$named_options" ] && exit 0
+[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/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};";;
+: ${named_restart:=@RESTARTCMD named@}
+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"
-       NEWZONES="${NEWZONES}\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 [ -f "${named_options}" ]; then 
-       if [ "$(cat "${named_options}")" != "$(printf "${NEWOPTIONS}")" ]; then
-               printf "${NEWOPTIONS}" > "${named_options}"
-               RELOAD="yes"
+changed=false
+if [ -n "$named_options" ]; then
+       if [ ! -f "$named_options" ] || \
+               [ "$(cat "$named_options")" != "$(printf "$newoptions")" ]
+       then
+               printf "$newoptions" >"$named_options"
+               changed=true
        fi
-else
-       printf "${NEWOPTIONS}" > "${named_options}"
-       RELOAD="yes"
 fi
-if [ -f "${named_zones}" ]; then
-       if [ "$(cat "${named_zones}")" != "$(printf "${NEWZONES}")" ]; then
-               printf "${NEWZONES}" > "${named_zones}"
-               RELOAD="yes"
+if [ -n "$named_zones" ]; then
+       if [ ! -f "$named_zones" ] || \
+               [ "$(cat "$named_zones")" != "$(printf "$newzones")" ]
+       then
+               printf "$newzones" >"$named_zones"
+               changed=true
        fi
-else
-       printf "${NEWZONES}" > "${named_zones}"
-       RELOAD="yes"
 fi
 
-[ "${RELOAD}" = "yes" ] && resolvconf -s named restart
-exit 0
+if $changed; then
+       eval $named_restart
+fi