2 # Copyright (c) 2010 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 "$(@PREFIX@/sbin/resolvconf -v)"
34 : ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
35 signature="# Generated by resolvconf"
36 signature_end="# End of resolvconf"
38 # We normally use sed to remove markers from a configuration file
39 # but sed may not always be available at the time.
42 local m1="$1" m2="$2" x= line= in_marker=0
45 if type sed >/dev/null 2>&1; then
46 sed "/^$m1/,/^$m2/d" $@
53 *) [ $in_marker = 0 ] && echo "$line";;
61 # If different, replace first with second otherwise remove second
65 if type cmp >/dev/null 2>&1; then
67 elif type diff >/dev/null 2>&1; then
68 diff -q "$1" "$2" >/dev/null
70 # Hopefully we're only working on small text files ...
71 [ "$(cat "$1")" = "$(cat "$2")" ]
83 newresolv="# Generated by resolvconf\n"
86 if [ -n "$pdnsd_resolv" ]; then
87 for n in $NAMESERVERS; do
88 newresolv="${newresolv}nameserver $n\n"
92 if [ -n "$pdnsd_conf" ]; then
96 if [ -z "$pdnsd_resolv" ]; then
97 newconf="${newconf}server {\n"
98 newconf="${newconf}\tlabel=resolvconf;\n"
99 if [ -n "$NAMESERVERS" ]; then
100 newconf="${newconf}\tip="
102 for n in $NAMESERVERS; do
106 newconf="${newconf},"
110 newconf="${newconf};\n"
112 newconf="${newconf}}\n"
115 for d in $DOMAINS; do
116 newconf="${newconf}server {\n"
117 newconf="${newconf}\tinclude=.${d%%:*}.;\n"
118 newconf="${newconf}\tpolicy=excluded;\n"
119 newconf="${newconf}\tip="
121 while [ -n "$ns" ]; do
122 newconf="${newconf}${ns%%,*}"
123 [ "$ns" = "${ns#*,}" ] && break
125 newconf="${newconf},"
127 newconf="${newconf};\n}\n"
131 remove_markers "$signature" "$signature_end" "$pdnsd_conf" > "$cf"
132 if [ -n "$newconf" ]; then
133 echo "$signature" >> "$cf"
134 printf %s "$newconf" >> "$cf"
135 echo "$signature_end" >> "$cf"
137 if change_file "$pdnsd_conf" "$cf"; then
142 if [ -n "$pdnsd_resolv" ]; then
143 if [ ! -f "$pdnsd_resolv" ] || \
144 [ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
147 printf %s "$newresolv" >"$pdnsd_resolv"