Release openresolv-3.5.4
[openresolv] / pdns_recursor.in
old mode 100755 (executable)
new mode 100644 (file)
index b968084..04ee607
@@ -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}
-[ -z "$NAMESERVERS" -a -z "$DOMAINS" ] && eval "$("$RESOLVCONF" -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/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,16 +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"
-       if [ "$(command -v service)" = service ]; then
-               service pdns_recursor restart
-       else
-               $RESOLVCONF -s pdns_recursor restart
-       fi
+       printf %s "$newzones" >"$pdns_zones"
+       eval $pdns_restart
 fi