2 # Copyright 2007-2009 Roy Marples <roy@marples.name>
5 # named 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 "${named_zones}" -o -z "${named_options}" ] && exit 0
32 eval "$("${RESOLVCONF:-resolvconf}" -v)"
34 newoptions="# Generated by resolvconf\n"
35 newzones="${newoptions}"
37 for n in ${NAMESERVERS}; do
40 *) forward="${forward}\n\t${n};";;
43 if [ -n "${forward}" ]; then
44 newoptions="${newoptions}forward first;\nforwarders {${forward}\n};\n"
47 for d in ${DOMAINS}; do
48 newzones="${newzones}zone \"${d%%:*}\" {\n"
49 newzones="${newzones}\ttype forward;\n"
50 newzones="${newzones}\tforward first;\n\tforwarders {\n"
52 while [ -n "${ns}" ]; do
53 newzones="${newzones}\t\t${ns%%,*};\n"
54 [ "${ns}" = "${ns#*,}" ] && break
57 newzones="${newzones}\t};\n};\n"
60 # No point in changing files or reloading bind if the end result has not
63 if [ ! -f "${named_options}" ] || \
64 [ "$(cat "${named_options}")" != "$(printf "${newoptions}")" ]
66 printf "${newoptions}" > "${named_options}"
69 if [ ! -f "${named_zones}" ] || \
70 [ "$(cat "${named_zones}")" != "$(printf "${newzones}")" ]
72 printf "${newzones}" > "${named_zones}"
76 ${changed} && resolvconf -s named restart