2 # Copyright (c) 2010-2013 Roy Marples
5 # pdnsd subscriber for resolvconf
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 [ -f "@SYSCONFDIR@"/resolvconf.conf
] ||
exit 0
30 .
"@SYSCONFDIR@/resolvconf.conf" ||
exit 1
31 [ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
32 [ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
36 : ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
37 signature
="# Generated by resolvconf"
38 signature_end
="# End of resolvconf"
40 # We normally use sed to remove markers from a configuration file
41 # but sed may not always be available at the time.
44 local m1
="$1" m2
="$2" x
= line
= in_marker
=0
47 if type sed >/dev
/null
2>&1; then
48 sed "/^$m1/,/^$m2/d" $@
51 while read -r line
; do
55 *) [ $in_marker = 0 ] && echo "$line";;
63 # If different, replace first with second otherwise remove second
67 if type cmp >/dev
/null
2>&1; then
69 elif type diff >/dev
/null
2>&1; then
70 diff -q "$1" "$2" >/dev
/null
72 # Hopefully we're only working on small text files ...
73 [ "$(cat "$1")" = "$(cat "$2")" ]
85 newresolv
="# Generated by resolvconf$NL"
88 # Try to ensure that config dirs exist
89 if type config_mkdirs
>/dev
/null
2>&1; then
90 config_mkdirs
"$pdnsd_resolv" "$pdnsd_conf"
92 @SBINDIR@
/resolvconf
-D "$pdnsd_resolv" "$pdnsd_conf"
95 if [ -n "$pdnsd_resolv" ]; then
96 for n
in $NAMESERVERS; do
97 newresolv
="${newresolv}nameserver $n$NL"
101 # Only modify the configuration if it exists and we can write to it
102 if [ -w "$pdnsd_conf" ]; then
106 if [ -z "$pdnsd_resolv" ]; then
107 newconf
="${newconf}server {$NL"
108 newconf
="${newconf} label=resolvconf;$NL"
109 if [ -n "$NAMESERVERS" ]; then
110 newconf
="${newconf} ip="
112 for n
in $NAMESERVERS; do
116 newconf
="${newconf},"
120 newconf
="${newconf};$NL"
122 newconf
="${newconf}}$NL"
125 for d
in $DOMAINS; do
126 newconf
="${newconf}server {$NL"
127 newconf
="${newconf} include=.${d%%:*}.;$NL"
128 newconf
="${newconf} policy=excluded;$NL"
129 newconf
="${newconf} ip="
131 while [ -n "$ns" ]; do
132 newconf
="${newconf}${ns%%,*}"
133 [ "$ns" = "${ns#*,}" ] && break
135 newconf
="${newconf},"
137 newconf
="${newconf};$NL}$NL"
141 remove_markers
"$signature" "$signature_end" "$pdnsd_conf" > "$cf"
142 if [ -n "$newconf" ]; then
143 echo "$signature" >> "$cf"
144 printf %s
"$newconf" >> "$cf"
145 echo "$signature_end" >> "$cf"
147 if change_file
"$pdnsd_conf" "$cf"; then
152 if [ -n "$pdnsd_resolv" ]; then
153 if [ ! -f "$pdnsd_resolv" ] || \
154 [ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
157 printf %s
"$newresolv" >"$pdnsd_resolv"