Release openresolv-3.7.1
[openresolv] / pdns_recursor.in
index 93bed04d9fd9a04941649c7d6b1dde0087a35a84..2919e7d0ff378f910138be754f50b93cb6024ce8 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2009 Roy Marples
+# Copyright (c) 2009-2011 Roy Marples
 # All rights reserved
 
 # PowerDNS Recursor subscriber for resolvconf
@@ -29,7 +29,9 @@
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$pdns_zones" ] && exit 0
-[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
+NL="
+"
 
 : ${pdns_service:=pdns_recursor}
 : ${pdns_restart:=@RESTARTCMD ${pdns_service}@}
@@ -42,7 +44,7 @@ newzones=
 #for n in $NAMESERVERS; do
 #      newzones="$newzones${newzones:+,}$n"
 #done
-#[ -n "$newzones" ] && newzones=".=$newzones\n"
+#[ -n "$newzones" ] && newzones=".=$newzones$NL"
 
 for d in $DOMAINS; do
        newns=
@@ -52,12 +54,19 @@ for d in $DOMAINS; do
                [ "$ns" = "${ns#*,}" ] && break
                ns="${ns#*,}"
        done
-       [ -n "$newns" ] && newzones="$newzones${d%%:*}=$newns\n"
+       [ -n "$newns" ] && newzones="$newzones${d%%:*}=$newns$NL"
 done
 
+# Try to ensure that config dirs exist
+if type config_mkdirs >/dev/null 2>&1; then
+       config_mkdirs "$pdnsd_zones"
+else
+       @SBINDIR@/resolvconf -D "$pdnsd_zones"
+fi
+
 if [ ! -f "$pdns_zones" ] || \
-       [ "$(cat "$pdns_zones")" != "$(printf "$newzones")" ]
+       [ "$(cat "$pdns_zones")" != "$(printf %s "$newzones")" ]
 then
-       printf "$newzones" >"$pdns_zones"
+       printf %s "$newzones" >"$pdns_zones"
        eval $pdns_restart
 fi