Release openresolv-3.5.4
[openresolv] / pdns_recursor.in
index e6227b7786cc873d2e4ca92fd3e06a7760fc90fc..04ee6073555ed0dab48c5d3946fa0968f24f88e1 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright 2009 Roy Marples
+# Copyright (c) 2009-2011 Roy Marples
 # All rights reserved
 
 # PowerDNS Recursor subscriber for resolvconf
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$pdns_zones" ] && exit 0
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
 
-: ${pdns_restart:=@RESTARTCMD pdns_recursor@}
+: ${pdns_service:=pdns_recursor}
+: ${pdns_restart:=@RESTARTCMD ${pdns_service}@}
 
 newzones=
 
@@ -41,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=
@@ -51,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
+       @PREFIX@/sbin/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