#!/bin/sh
-# Copyright (c) 2010 Roy Marples
+# Copyright (c) 2010-2011 Roy Marples
# All rights reserved
# pdnsd subscriber for resolvconf
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+NL="
+"
: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
signature="# Generated by resolvconf"
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;;
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"
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
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%%,*}"
ns="${ns#*,}"
newconf="${newconf},"
done
- newconf="${newconf};\n}\n"
+ newconf="${newconf};$NL}$NL"
done
rm -f "$cf"
remove_markers "$signature" "$signature_end" "$pdnsd_conf" > "$cf"
if [ -n "$newconf" ]; then
echo "$signature" >> "$cf"
- printf "$newconf" >> "$cf"
+ printf %s "$newconf" >> "$cf"
echo "$signature_end" >> "$cf"
fi
if change_file "$pdnsd_conf" "$cf"; then
if [ -n "$pdnsd_resolv" ]; then
if [ ! -f "$pdnsd_resolv" ] || \
- [ "$(cat "$pdnsd_resolv")" != "$(printf "$newresolv")" ]
+ [ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
then
changed=true
- printf "$newresolv" >"$pdnsd_resolv"
+ printf %s "$newresolv" >"$pdnsd_resolv"
fi
fi