Remove comments that no longer apply.
[openresolv] / named.in
1 #!/bin/sh
2 # Copyright 2007-2009 Roy Marples <roy@marples.name>
3 # All rights reserved
4
5 # named updater for resolvconf
6
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
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.
16 #
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.
28
29 # The bind config needs to be setup to include our file
30 #options {
31 #   include "resolvconf-options.conf";
32 #};
33 #include "resolvconf-zones.conf";
34
35 # The last step is to configure dns configuration for /etc/resolv.conf
36 #echo "nameserver 127.0.0.1" > @SYSCONFDIR@/resolv.conf.d/base
37
38 # Load our variables from resolvconf
39 eval "$(resolvconf -v)"
40
41 # If our dir doesn't exist then don't do anything
42 NAMEDB=/etc/namedb
43 [ -d "${NAMEDB}" ] || NAMEDB="/etc/bind"
44 [ -d "${NAMEDB}" ] || exit 0
45
46 NAMEDOPTIONS="${NAMEDB}/resolvconf-options.conf"
47 NAMEDZONES="${NAMEDB}/resolvconf-zones.conf"
48
49 NEWOPTIONS="# Generated by resolvconf\n"
50 NEWZONES="${NEWOPTIONS}"
51 FORWARD=
52 for N in ${NAMESERVERS}; do
53         case "${FORWARD}" in
54                 *"\n\t${N};"*);;
55                 *) FORWARD="${FORWARD}\n\t${N};";;
56         esac
57 done
58 if [ -n "${FORWARD}" ]; then
59         NEWOPTIONS="${NEWOPTIONS}forward first;\nforwarders {${FORWARD}\n};\n"
60 fi
61
62 for D in ${DOMAINS}; do
63         NEWZONES="${NEWZONES}zone \"${D%%:*}\" {\n"
64         NEWZONES="${NEWZONES}\ttype forward;\n\tforward first;\n\tforwarders {\n"
65         NS="${D#*:}"
66         while [ -n "${NS}" ]; do
67                 NEWZONES="${NEWZONES}\t\t${NS%%,*};\n"
68                 [ "${NS}" = "${NS#*,}" ] && break
69                 NS="${NS#*,}"
70         done
71         NEWZONES="${NEWZONES}\t};\n};\n"
72 done
73
74 # No point in changing files or reloading bind if the end result has not
75 # changed
76 RELOAD="no"
77 if [ -e "${NAMEDOPTIONS}" ]; then 
78         if [ "$(cat "${NAMEDOPTIONS}")" != "$(printf "${NEWOPTIONS}")" ]; then
79                 printf "${NEWOPTIONS}" > "${NAMEDOPTIONS}"
80                 RELOAD="yes"
81         fi
82 else
83         printf "${NEWOPTIONS}" > "${NAMEDOPTIONS}"
84         RELOAD="yes"
85 fi
86 if [ -e "${NAMEDZONES}" ]; then
87         if [ "$(cat "${NAMEDZONES}")" != "$(printf "${NEWZONES}")" ]; then
88                 printf "${NEWZONES}" > "${NAMEDZONES}"
89                 RELOAD="yes"
90         fi
91 else
92         printf "${NEWZONES}" > "${NAMEDZONES}"
93         RELOAD="yes"
94 fi
95
96 [ "${RELOAD}" = "yes" ] && resolvconf -s named restart
97
98 exit 0