Release openresolv-3.7.1
[openresolv] / pdns_recursor.in
old mode 100755 (executable)
new mode 100644 (file)
index 5e5f7f4..2919e7d
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright 2009 Roy Marples
+# Copyright (c) 2009-2011 Roy Marples
 # All rights reserved
 
 # PowerDNS Recursor subscriber for resolvconf
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$pdns_zones" ] && exit 0
-: ${RESOLVCONF:=resolvconf}
-eval "$("$RESOLVCONF" -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
+NL="
+"
+
+: ${pdns_service:=pdns_recursor}
+: ${pdns_restart:=@RESTARTCMD ${pdns_service}@}
 
 newzones=
-for n in $NAMESERVERS; do
-       newzones="$newzones${newzones:+,}$n"
-done
-[ -n "$newzones" ] && newzones=".=$newzones\n"
 
-dbusdest=
+# pds_recursor does not present support global forward servers, which
+# does limit it's usefulness somewhat.
+# If it did, the below code can be enabled, or something like it.
+#for n in $NAMESERVERS; do
+#      newzones="$newzones${newzones:+,}$n"
+#done
+#[ -n "$newzones" ] && newzones=".=$newzones$NL"
+
 for d in $DOMAINS; do
        newns=
        ns="${d#*:}"
@@ -47,15 +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
 
-changed=false
+# 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
-       changed=true
-       printf "$newzones" >"$pdns_zones"
+       printf %s "$newzones" >"$pdns_zones"
+       eval $pdns_restart
 fi
-
-$changed && $RESOLVCONF -s pdns_recursor restart
\ No newline at end of file