Try to ensure that the directories our config files want to live in exist.
authorRoy Marples <roy@marples.name>
Sun, 24 Jul 2011 14:56:05 +0000 (14:56 +0000)
committerRoy Marples <roy@marples.name>
Sun, 24 Jul 2011 14:56:05 +0000 (14:56 +0000)
dnsmasq.in
named.in
pdns_recursor.in
pdnsd.in
resolvconf.in
unbound.in

index a120189ba99421252d06cfe21623d2d74a911cdf..9c7fdeef96704e9535b187ba75d3fff6fd52fa6e 100644 (file)
@@ -93,6 +93,13 @@ for d in $DOMAINS; do
        done
 done
 
+# Try to ensure that config dirs exist
+if type config_mkdirs >/dev/null 2>&1; then
+       config_mkdirs "$dnsmasq_conf" "$dnsmasq_resolv"
+else
+       @PREFIX@/sbin/resolvconf -D "$dnsmasq_conf" "$dnsmasq_resolv"
+fi
+
 changed=false
 if [ -n "$dnsmasq_conf" ]; then
        if [ ! -f "$dnsmasq_conf" ] || \
index c960866b99853b0764fd50915f8b24cc0f29b848..a89deb2693bcfb080a823cbd32ff6bbb80f290cd 100644 (file)
--- a/named.in
+++ b/named.in
@@ -71,6 +71,13 @@ for d in $DOMAINS; do
        newzones="$newzones     };$NL};$NL"
 done
 
+# Try to ensure that config dirs exist
+if type config_mkdirs >/dev/null 2>&1; then
+       config_mkdirs "$named_options" "$named_zones"
+else
+       @PREFIX@/sbin/resolvconf -D "$named_options" "$named_zones"
+fi
+
 # No point in changing files or reloading bind if the end result has not
 # changed
 changed=false
index e7aa40e1eca171a737e137608caeffa9a4bed10a..04ee6073555ed0dab48c5d3946fa0968f24f88e1 100644 (file)
@@ -57,6 +57,13 @@ for d in $DOMAINS; do
        [ -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 %s "$newzones")" ]
 then
index 5fbe2a076a579c4209a76363a9926f9f0893510a..f474196ef4c9237cea17ccbbdc550a7cd764a38a 100644 (file)
--- a/pdnsd.in
+++ b/pdnsd.in
@@ -85,6 +85,13 @@ change_file()
 newresolv="# Generated by resolvconf\n"
 changed=false
 
+# Try to ensure that config dirs exist
+if type config_mkdirs >/dev/null 2>&1; then
+       config_mkdirs "$pdnsd_resolv" "$pdnsd_conf"
+else
+       @PREFIX@/sbin/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf"
+fi
+
 if [ -n "$pdnsd_resolv" ]; then
        for n in $NAMESERVERS; do
                newresolv="${newresolv}nameserver $n\n"
index 948ab2b3ab85e99f3921d2d62515b9a00ac76c69..e24a90b9cb655907e54b6d4742f45dd7d0dcd3f7 100644 (file)
@@ -187,6 +187,41 @@ uniqify()
        echo "${result# *}"
 }
 
+dirname()
+{
+       local dir= OIFS="$IFS"
+       local IFS=/
+       set -- $@
+       IFS="$OIFS"
+       if [ -n "$1" ]; then
+               printf %s .
+       else
+               shift
+       fi
+       while [ -n "$2" ]; do
+               printf "/%s" "$1"
+               shift
+       done
+       printf "\n"
+}
+
+config_mkdirs()
+{
+       local e=0 f d
+       for f; do
+               [ -n "$f" ] || continue
+               d="$(dirname "$f")"
+               if [ ! -d "$d" ]; then
+                       if type install >/dev/null 2>&1; then
+                               install -d "$d" || e=$?
+                       else
+                               mkdir "$d" || e=$?
+                       fi
+               fi
+       done
+       return $e
+}
+
 list_resolv()
 {
        [ -d "$IFACEDIR" ] || return 0
@@ -274,7 +309,7 @@ make_vars()
 }
 
 force=false
-while getopts a:d:fhIilm:puv OPT; do
+while getopts a:Dd:fhIilm:puv OPT; do
        case "$OPT" in
        f) force=true;;
        h) usage;;
@@ -295,6 +330,12 @@ if [ "$cmd" = I ]; then
        exit $?
 fi
 
+# -D ensures that the listed config file base dirs exist
+if [ "$cmd" = D ]; then
+       config_mkdirs "$@"
+       exit $?
+fi
+
 # -l lists our resolv files, optionally for a specific interface
 if [ "$cmd" = l -o "$cmd" = i ]; then
        list_resolv "$cmd" "$args"
index 839a85944059e6bb5d62578159a7e046b678ac53..4ee0da7202633fac6d14dfa697495c648c274bab 100644 (file)
@@ -56,6 +56,13 @@ if [ -n "$NAMESERVERS" ]; then
        done
 fi
 
+# Try to ensure that config dirs exist
+if type config_mkdirs >/dev/null 2>&1; then
+       config_mkdirs "$unbound_conf"
+else
+       @PREFIX@/sbin/resolvconf -D "$unbound_conf"
+fi
+
 if [ ! -f "$unbound_conf" ] || \
        [ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
 then