Gentoo Archives: gentoo-commits

From: "Jim Ramsay (lack)" <lack@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-dns/openresolv/files: pdnsd
Date: Wed, 28 Jul 2010 15:05:27
Message-Id: 20100728150523.822F82CE15@corvid.gentoo.org
1 lack 10/07/28 15:05:23
2
3 Modified: pdnsd
4 Log:
5 Update pdnsd script for better posix compliance (Bug #248925)
6 (Portage version: 2.1.8.3/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.2 net-dns/openresolv/files/pdnsd
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/openresolv/files/pdnsd?rev=1.2&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/openresolv/files/pdnsd?rev=1.2&content-type=text/plain
13 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/openresolv/files/pdnsd?r1=1.1&r2=1.2
14
15 Index: pdnsd
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo-x86/net-dns/openresolv/files/pdnsd,v
18 retrieving revision 1.1
19 retrieving revision 1.2
20 diff -u -r1.1 -r1.2
21 --- pdnsd 6 May 2009 15:57:24 -0000 1.1
22 +++ pdnsd 28 Jul 2010 15:05:22 -0000 1.2
23 @@ -1,5 +1,5 @@
24 -#!/bin/bash
25 -# Copyright 2006-2009 Gentoo Foundation
26 +#!/bin/sh
27 +# Copyright 1999-2010 Gentoo Foundation
28 # Distributed under the terms of the GNU General Public License v2
29
30 # /etc/pdnsd/pdnsd.conf updater
31 @@ -85,7 +85,7 @@
32 BACKUPSUFFIX=".backup"
33
34 # Load our variables from resolvconf
35 -eval "$(resolvconf -v)"
36 +eval "$(/sbin/resolvconf -v)"
37
38 COMMENT='
39 # Automatically generated by resolvconf.
40 @@ -148,18 +148,15 @@
41 :server; h;
42 :server_loop; n;
43 /^[[:space:]]*server[[:space:]]*[\{]/ { x; p; b server_loop; };
44 -@MATCH_LABELS@
45 -/^[[:space:]]*label[[:space:]]*=[[:space:]]*"resolvconf"/ { H; b adding; };
46 +@MATCH_LABELS@/^[[:space:]]*label[[:space:]]*=[[:space:]]*"resolvconf"/ { H; b adding; };
47 /^[[:space:]]*[\}]/ { H; x; p; d; };
48 H;
49 -b server_loop;
50 -'
51 +b server_loop;'
52
53 ###
54 # Match for one label with a jump to SED_EDIT_ONE_SERVER
55 SED_MATCH_ONE_LABEL=\
56 -'/^[[:space:]]*label[[:space:]]*=[[:space:]]*"@LABEL@"/ { H; x; b main_@RULE@; };
57 -'
58 +'/^[[:space:]]*label[[:space:]]*=[[:space:]]*"@LABEL@"/ { H; x; b main_@RULE@; };'
59
60 ###
61 # Editing one server. New lines are put into @SETUP@, lines are composed
62 @@ -180,12 +177,12 @@
63 /^[[:space:]]*ip[[:space:]]*=/ b loop_@RULE@;
64 /^[[:space:]]*include[[:space:]]*=/ b loop_@RULE@;
65 /^[[:space:]]*policy[[:space:]]*=/ b loop_@RULE@;
66 -/^[[:space:]]*exclude[[:space:]]*=/ b exclude_logic_@RULE;
67 +/^[[:space:]]*exclude[[:space:]]*=/ b exclude_logic_@RULE@;
68 p;
69 /^[[:space:]]*[\}]/ d;
70 b loop_@RULE@;
71
72 -:exclude_logic_@RULE;
73 +:exclude_logic_@RULE@;
74 @EXCLUDE_LOGIC@
75 b loop_@RULE@;
76 '
77 @@ -242,7 +239,7 @@
78 esac
79 shift
80 done
81 - echo "${result# *}"
82 + printf "%s" "${result# *}"
83 }
84
85 ###
86 @@ -250,23 +247,43 @@
87 #
88 # Translate domain name into pdnsd's label
89 make_pdnsd_label() {
90 - local domain=$1
91 - if [[ -n ${domain} ]] ; then
92 - echo -n "resolvconf-${domain}"
93 + local domain="$1"
94 + if [ -n "${domain}" ] ; then
95 + printf "%s" "resolvconf-${domain}"
96 else
97 - echo -n "resolvconf"
98 + printf "%s" "resolvconf"
99 fi
100 }
101
102 +
103 +###
104 +# char *replace(char *text, char *search, char *replace)
105 +#
106 +# Replaces all the found "search" occurences in the "text" with the "replace".
107 +replace() {
108 + local text="$1" search="$2" replace="$3"
109 + local pre post="${text}" result=""
110 + while [ x"${pre}" != x"${text}" ] ; do
111 + post="${text}"
112 + pre="${text%%$search*}"
113 + post="${text#*$search}"
114 + if [ x"${pre}" != x"${text}" ] ; then
115 + result="${result}${pre}${replace}"
116 + text="${post}"
117 + fi
118 + done
119 + printf "%s" "${result}${post}"
120 +}
121 +
122 ###
123 # char *make_sed_label(char *pdnsd_label)
124 #
125 # Translate pdnsd's label into sed's label
126 make_sed_label() {
127 local label="$1"
128 - label="${label//-/_}"
129 - label="${label//./_}"
130 - echo -n "${label}"
131 + label="$(replace "${label}" "-" "_")"
132 + label="$(replace "${label}" "." "_")"
133 + printf "%s" "${label}"
134 }
135
136 # char *compose_lines(...)
137 @@ -275,9 +292,9 @@
138 compose_lines() {
139 local line result
140 for line in "$@" ; do
141 - result="${result}i\\\\\\n${line// /\\t}\\n"
142 + result="${result}i\\\\\\n$(replace "${line}" " " "\\t")\\n"
143 done
144 - echo "${result}"
145 + printf "%s" "${result}"
146 }
147
148 ###
149 @@ -310,18 +327,18 @@
150 #
151 build_settings() {
152 local ns="$1" domains="$2" directive="$3"
153 - if [[ -n ${ns} ]] ; then
154 + if [ -n "${ns}" ] ; then
155 local x list_ns list_domains
156 for x in ${ns} ; do
157 list_ns="${list_ns},\"${x}\""
158 done
159 list_ns="${list_ns#,}"
160 - if [[ -n ${domains} ]] ; then
161 + if [ -n "${domains}" ] ; then
162 for x in ${domains} ; do
163 list_domains="${list_domains},\".${x}.\""
164 done
165 list_domains="${list_domains#,}"
166 - if [[ $directive == "include" ]]; then
167 + if [ x"$directive" = x"include" ]; then
168 compose_lines \
169 " preset=on;" \
170 " ip=${list_ns};" \
171 @@ -355,11 +372,11 @@
172 for domain in "$@" ; do
173 label="$(make_pdnsd_label "${domain}")"
174 rule="$(make_sed_label "${label}")"
175 - new_match="${SED_MATCH_ONE_LABEL//@LABEL@/${label}}"
176 - new_match="${new_match//@RULE@/${rule}}"
177 - result="${result}${new_match}"
178 + new_match="$(replace "${SED_MATCH_ONE_LABEL}" "@LABEL@" "${label}")"
179 + new_match="$(replace "${new_match}" "@RULE@" "${rule}")"
180 + result="${result}${new_match}\n"
181 done
182 - echo "${result}"
183 + printf "%s" "${result}"
184 }
185
186 ###
187 @@ -374,18 +391,18 @@
188 # Domains should be pipe separated list
189 for x in ${domains}; do
190 x=".${x%.}"
191 - x="${x//./\.}"
192 + x="$(replace "${x}" "." "\\.")"
193 domain_list="${domain_list}|${x}"
194 done
195 domain_list="${domain_list#|}"
196
197 - if [[ -z ${domain_list} ]]; then
198 + if [ -z "${domain_list}" ]; then
199 logic="p;"
200 else
201 - logic="${SED_DOMAIN_LIST_LOGIC//@DOMAINS@/${domain_list}}"
202 - logic="${logic//@DIRECTIVE@/${directive}}"
203 + logic="$(replace "${SED_DOMAIN_LIST_LOGIC}" "@DOMAINS@" "${domain_list}")"
204 + logic="$(replace "${logic}" "@DIRECTIVE@" "${directive}")"
205 fi
206 - echo "${logic}"
207 + printf "%s" "${logic}"
208 }
209
210 ###
211 @@ -405,10 +422,10 @@
212 label="$(make_pdnsd_label "${domain}")"
213 rule="$(make_sed_label "${label}")"
214 logic="$(build_domain_list_logic "${remove_domains}" "${directive}")"
215 - result="${SED_EDIT_ONE_SERVER//@SETUP@/${setup}}"
216 - result="${result//@EXCLUDE_LOGIC@/${logic}}"
217 - result="${result//@RULE@/${rule}}"
218 - echo "${result}"
219 + result="$(replace "${SED_EDIT_ONE_SERVER}" "@SETUP@" "${setup}")"
220 + result="$(replace "${result}" "@EXCLUDE_LOGIC@" "${logic}")"
221 + result="$(replace "${result}" "@RULE@" "${rule}")"
222 + printf "%s\n" "${result}"
223 }
224
225 ###
226 @@ -422,12 +439,12 @@
227 local domain="$1" ns
228 shift
229 for x in "$@" ; do
230 - if [[ ${x%,*} == ${domain} ]] ; then
231 + if [ x"${x%,*}" = x"${domain}" ] ; then
232 ns="${ns} ${x#*,}"
233 fi
234 done
235 ns="$(uniqify ${ns})"
236 - echo -n "${ns}"
237 + printf "%s" "${ns}"
238 }
239
240 ###
241 @@ -463,8 +480,8 @@
242 new_part="${new_part}$(compose_lines "}" "")"
243 add_part="${add_part}${new_part}"
244 done
245 - result="${SED_ADDING//@SETUP@/${add_part}}"
246 - echo "${result}"
247 + result="$(replace "${SED_ADDING}" "@SETUP@" "${add_part}")"
248 + printf "%s" "${result}"
249 }
250
251 ###
252 @@ -494,10 +511,10 @@
253 added="$(build_add_part "${add}" ${domain_config})"
254
255 local full
256 - full="${SED_LOOP//@MATCH_LABELS@/${match_labels}}"
257 - echo -ne "${full}"
258 - echo -ne "${edit_changed}"
259 - echo -ne "${added}"
260 + full="$(replace "${SED_LOOP}" "@MATCH_LABELS@" "${match_labels}")"
261 + printf "%b\n" "${full}"
262 + printf "%b\n" "${edit_changed}"
263 + printf "%b" "${added}"
264 }
265
266 ###
267 @@ -510,7 +527,7 @@
268 result="\
269 $(sed -nre 's/^[[:space:]]+label=\"?resolvconf-([^;\"]*)\";.*/\1/p' \
270 ${config_file})"
271 - echo -n "${result}"
272 + printf "%s" "${result}"
273 }
274
275 ###
276 @@ -521,10 +538,10 @@
277 #
278 installation_check() {
279 local config_file="$1"
280 - if [[ -e ${config_file} ]] ; then
281 - if ! grep ${INSTALLATION_CHECK} ${config_file} &>/dev/null ; then
282 - echo -e "${COMMENT}" >> ${config_file}
283 - echo -e "\n${BASIC_SETTINGS}" >> ${config_file}
284 + if [ -e "${config_file}" ] ; then
285 + if ! grep ${INSTALLATION_CHECK} "${config_file}" >/dev/null 2>&1; then
286 + printf "%s\n" "${COMMENT}" >> "${config_file}"
287 + printf "\n%s\n" "${BASIC_SETTINGS}" >> "${config_file}"
288 fi
289 return 0
290 else
291 @@ -541,8 +558,8 @@
292 local config_file="$1"
293
294 # Compatibility fix for new openresolv-2.0
295 - if [[ -z ${NEWNS} && -n ${NAMESERVERS} ]]; then
296 - NEWDOMAIN=${DOMAINS//:/,}
297 + if [ -z "${NEWNS}" -a -n "${NAMESERVERS}" ]; then
298 + NEWDOMAIN=$(replace "${DOMAINS}" ":" ",")
299 NEWSEARCH=
300 NEWNS=${NAMESERVERS}
301 DOMAINS=
302 @@ -582,18 +599,18 @@
303
304 # Find what has to be disabled
305 for x in ${configured} ; do
306 - if [[ " ${domains} " != *" ${x} "* ]] ; then
307 - CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}"
308 - fi
309 + case " ${domains} " in
310 + *" ${x} "*) ;;
311 + *) CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}" ;;
312 + esac
313 done
314
315 # Find what has to be added
316 for x in ${domains} ; do
317 - if [[ " ${configured} " != *" ${x} "* ]] ; then
318 - ADD_DOMAINS="${ADD_DOMAINS} ${x}"
319 - else
320 - CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}"
321 - fi
322 + case " ${configured} " in
323 + *" ${x} "*) CHANGE_DOMAINS="${CHANGE_DOMAINS} ${x}" ;;
324 + *) ADD_DOMAINS="${ADD_DOMAINS} ${x}" ;;
325 + esac
326 done
327
328 ADD_DOMAINS=$(uniqify ${ADD_DOMAINS})
329 @@ -611,17 +628,17 @@
330 local config_file="$1" backup_suffix="$2" sed_script="$3"
331 local old_config new_config
332
333 - old_config=$(< ${config_file})
334 + old_config="$(cat "${config_file}")"
335
336 # Sanity check: add '}' at the end of the file
337 - new_config=$( (echo -n "${old_config}" && echo -ne "\n}" ) | \
338 + new_config=$( (printf "%s" "${old_config}" && printf "\n}" ) | \
339 sed -nre "${sed_script}")
340 # Now remove what we added
341 new_config=${new_config%?\}}
342
343 - if [[ "${old_config}" != "${new_config}" ]] ; then
344 + if [ x"${old_config}" != x"${new_config}" ] ; then
345 cp ${config_file} ${config_file}${backup_suffix}
346 - echo "${new_config}" > "${config_file}"
347 + printf "%s\n" "${new_config}" > "${config_file}"
348 return 0
349 else
350 return 1
351 @@ -650,7 +667,7 @@
352 [ -e /var/cache/pdnsd/pdnsd.status ] || exit 0
353
354 # Reload config files
355 - /usr/sbin/pdnsd-ctl config &>/dev/null
356 + /usr/sbin/pdnsd-ctl config >/dev/null 2>&1
357 fi
358
359 exit 0