summaryrefslogtreecommitdiffstats
path: root/contrib/openresolv/pdnsd.in
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/openresolv/pdnsd.in')
-rw-r--r--contrib/openresolv/pdnsd.in44
1 files changed, 27 insertions, 17 deletions
diff --git a/contrib/openresolv/pdnsd.in b/contrib/openresolv/pdnsd.in
index 61dc5e1..59a4755 100644
--- a/contrib/openresolv/pdnsd.in
+++ b/contrib/openresolv/pdnsd.in
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright (c) 2010 Roy Marples
+# Copyright (c) 2010-2013 Roy Marples
# All rights reserved
# pdnsd subscriber for resolvconf
@@ -29,7 +29,9 @@
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
-[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
+NL="
+"
: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
signature="# Generated by resolvconf"
@@ -46,7 +48,7 @@ remove_markers()
sed "/^$m1/,/^$m2/d" $@
else
for x; do
- while read line; do
+ while read -r line; do
case "$line" in
"$m1"*) in_marker=1;;
"$m2"*) in_marker=0;;
@@ -80,24 +82,32 @@ change_file()
return 0
}
-newresolv="# Generated by resolvconf\n"
+newresolv="# Generated by resolvconf$NL"
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
+ @SBINDIR@/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf"
+fi
+
if [ -n "$pdnsd_resolv" ]; then
for n in $NAMESERVERS; do
- newresolv="${newresolv}nameserver $n\n"
+ newresolv="${newresolv}nameserver $n$NL"
done
fi
-if [ -n "$pdnsd_conf" ]; then
+# Only modify the configuration if it exists and we can write to it
+if [ -w "$pdnsd_conf" ]; then
cf="$pdnsd_conf.new"
newconf=
if [ -z "$pdnsd_resolv" ]; then
- newconf="${newconf}server {\n"
- newconf="${newconf}\tlabel=resolvconf;\n"
+ newconf="${newconf}server {$NL"
+ newconf="${newconf} label=resolvconf;$NL"
if [ -n "$NAMESERVERS" ]; then
- newconf="${newconf}\tip="
+ newconf="${newconf} ip="
first=true
for n in $NAMESERVERS; do
if $first; then
@@ -107,16 +117,16 @@ if [ -n "$pdnsd_conf" ]; then
fi
newconf="$newconf$n"
done
- newconf="${newconf};\n"
+ newconf="${newconf};$NL"
fi
- newconf="${newconf}}\n"
+ newconf="${newconf}}$NL"
fi
for d in $DOMAINS; do
- newconf="${newconf}server {\n"
- newconf="${newconf}\tinclude=.${d%%:*}.;\n"
- newconf="${newconf}\tpolicy=excluded;\n"
- newconf="${newconf}\tip="
+ newconf="${newconf}server {$NL"
+ newconf="${newconf} include=.${d%%:*}.;$NL"
+ newconf="${newconf} policy=excluded;$NL"
+ newconf="${newconf} ip="
ns="${d#*:}"
while [ -n "$ns" ]; do
newconf="${newconf}${ns%%,*}"
@@ -124,7 +134,7 @@ if [ -n "$pdnsd_conf" ]; then
ns="${ns#*,}"
newconf="${newconf},"
done
- newconf="${newconf};\n}\n"
+ newconf="${newconf};$NL}$NL"
done
rm -f "$cf"
@@ -136,7 +146,7 @@ if [ -n "$pdnsd_conf" ]; then
fi
if change_file "$pdnsd_conf" "$cf"; then
changed=true
- fi
+ fi
fi
if [ -n "$pdnsd_resolv" ]; then
OpenPOWER on IntegriCloud