2 # Copyright (c) 2010-2023 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}${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.
49 if command -v sed >/dev
/null
2>&1; then
50 sed "/^$m1/,/^$m2/d" $@
57 *) [ $in_marker = 0 ] && echo "$line";;
65 # If different, replace first with second otherwise remove second
69 if command -v cmp >/dev
/null
2>&1; then
71 elif command -v diff >/dev
/null
2>&1; then
72 diff -q "$1" "$2" >/dev
/null
74 # Hopefully we're only working on small text files ...
75 [ "$(cat "$1")" = "$(cat "$2")" ]
87 newresolv
="# Generated by resolvconf$NL"
90 # Try to ensure that config dirs exist
91 if command -v config_mkdirs
>/dev
/null
2>&1; then
92 config_mkdirs
"$pdnsd_resolv" "$pdnsd_conf"
94 @SBINDIR@
/resolvconf
-D "$pdnsd_resolv" "$pdnsd_conf"
97 if [ -n "$pdnsd_resolv" ]; then
98 for n
in $NAMESERVERS; do
99 newresolv
="${newresolv}nameserver $n$NL"
103 # Only modify the configuration if it exists and we can write to it
104 if [ -w "$pdnsd_conf" ]; then
108 if [ -z "$pdnsd_resolv" ]; then
109 newconf
="${newconf}server {$NL"
110 newconf
="${newconf} label=resolvconf;$NL"
111 if [ -n "$NAMESERVERS" ]; then
112 newconf
="${newconf} ip="
114 for n
in $NAMESERVERS; do
118 newconf
="${newconf},"
122 newconf
="${newconf};$NL"
124 newconf
="${newconf}}$NL"
127 for d
in $DOMAINS; do
128 newconf
="${newconf}server {$NL"
129 newconf
="${newconf} include=.${d%%:*}.;$NL"
130 newconf
="${newconf} policy=excluded;$NL"
131 newconf
="${newconf} ip="
133 while [ -n "$ns" ]; do
134 newconf
="${newconf}${ns%%,*}"
135 [ "$ns" = "${ns#*,}" ] && break
137 newconf
="${newconf},"
139 newconf
="${newconf};$NL}$NL"
143 remove_markers
"$signature" "$signature_end" "$pdnsd_conf" > "$cf"
144 if [ -n "$newconf" ]; then
145 echo "$signature" >> "$cf"
146 printf %s
"$newconf" >> "$cf"
147 echo "$signature_end" >> "$cf"
149 if change_file
"$pdnsd_conf" "$cf"; then
154 if [ -n "$pdnsd_resolv" ]; then
155 if [ ! -f "$pdnsd_resolv" ] || \
156 [ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
159 printf %s
"$newresolv" >"$pdnsd_resolv"