| |
1 #!@l_prefix@/lib/openpkg/bash |
| |
2 ## |
| |
3 ## rpmtool -- OpenPKG RPM Auxiliary Tool |
| |
4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/> |
| |
5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/> |
| |
6 ## |
| |
7 ## Permission to use, copy, modify, and distribute this software for |
| |
8 ## any purpose with or without fee is hereby granted, provided that |
| |
9 ## the above copyright notice and this permission notice appear in all |
| |
10 ## copies. |
| |
11 ## |
| |
12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| |
13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| |
14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| |
15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
| |
16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| |
17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| |
18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| |
19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| |
20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| |
21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| |
22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| |
23 ## SUCH DAMAGE. |
| |
24 ## |
| |
25 |
| |
26 prog_path="$0" |
| |
27 prog_name="rpmtool" |
| |
28 prog_vers="1.1.0" |
| |
29 prog_date="05-Mar-2007" |
| |
30 |
| |
31 if [ $# -eq 0 ]; then |
| |
32 echo "$0:Error: invalid command line" 1>&2 |
| |
33 echo "$0:Hint: run \`$0 -h' for usage" 1>&2 |
| |
34 exit 1 |
| |
35 fi |
| |
36 if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then |
| |
37 echo "This is $prog_name, version $prog_vers ($prog_date)" |
| |
38 echo "Copyright (c) 2000-2004 Ralf S. Engelschall <rse@engelschall.com>" |
| |
39 echo '' |
| |
40 echo "Usage: $prog_name [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]" |
| |
41 echo '' |
| |
42 echo 'Available global <options>:' |
| |
43 echo ' -d, --debug enable internal debugging' |
| |
44 echo ' -v, --version display version information' |
| |
45 echo ' -h, --help display usage help page (this one)' |
| |
46 echo '' |
| |
47 echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:' |
| |
48 echo ' platform' |
| |
49 echo ' mflags [-O] <tool>' |
| |
50 echo ' cflags [-O] <tool>' |
| |
51 echo ' cppflags [-p <prefix>] [<subdir> ...]' |
| |
52 echo ' ldflags [-p <prefix>] [<subdir> ...]' |
| |
53 echo ' files [-v] [-o <outfile>] [-r <buildroot>] [<filelist>]' |
| |
54 echo ' signal [-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]' |
| |
55 echo ' config [-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>' |
| |
56 echo ' msg [-b] [-r] [-t <type>]' |
| |
57 echo '' |
| |
58 exit 0 |
| |
59 fi |
| |
60 if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then |
| |
61 echo "$prog_name $prog_vers ($prog_date)" |
| |
62 exit 0 |
| |
63 fi |
| |
64 if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then |
| |
65 shift |
| |
66 set -x |
| |
67 fi |
| |
68 |
| |
69 tool="$1" |
| |
70 shift |
| |
71 arg_spec="" |
| |
72 opt_spec="" |
| |
73 gen_tmpfile=no |
| |
74 |
| |
75 # configure tool specific option parsing |
| |
76 case $tool in |
| |
77 platform ) |
| |
78 str_usage="" |
| |
79 arg_spec="0=" |
| |
80 opt_spec="" |
| |
81 ;; |
| |
82 mflags ) |
| |
83 str_usage="[-O] <tool>" |
| |
84 arg_spec="1=" |
| |
85 opt_spec="O." |
| |
86 opt_O=no |
| |
87 ;; |
| |
88 cflags ) |
| |
89 str_usage="[-O] <tool>" |
| |
90 arg_spec="1=" |
| |
91 opt_spec="O." |
| |
92 opt_O=no |
| |
93 ;; |
| |
94 cppflags ) |
| |
95 str_usage="[-p <prefix>] [-i] [<subdir> ...]" |
| |
96 arg_spec="0+" |
| |
97 opt_spec="p:i." |
| |
98 opt_p="/" |
| |
99 ;; |
| |
100 ldflags ) |
| |
101 str_usage="[-p <prefix>] [<subdir> ...]" |
| |
102 arg_spec="0+" |
| |
103 opt_spec="p:" |
| |
104 opt_p="/" |
| |
105 ;; |
| |
106 files ) |
| |
107 gen_tmpfile=yes |
| |
108 str_usage="[-v] [-o <outfile>] [-r <buildroot>] [<filelist>]" |
| |
109 arg_spec="0+" |
| |
110 opt_spec="v.o:r:" |
| |
111 opt_v=no |
| |
112 opt_o='' |
| |
113 opt_r='' |
| |
114 ;; |
| |
115 signal ) |
| |
116 str_usage="[-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]" |
| |
117 arg_spec="1+" |
| |
118 opt_spec="v.t.n.c.d:p:m:" |
| |
119 opt_v=no |
| |
120 opt_t=no |
| |
121 opt_n=no |
| |
122 opt_c=no |
| |
123 opt_d=1 |
| |
124 opt_p="" |
| |
125 opt_m="" |
| |
126 ;; |
| |
127 config ) |
| |
128 str_usage="[-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>" |
| |
129 arg_spec="1=" |
| |
130 opt_spec="v.s.a.r.b:p:t:i:c:" |
| |
131 opt_v=no |
| |
132 opt_s=no |
| |
133 opt_a=no |
| |
134 opt_r=no |
| |
135 opt_b="" |
| |
136 opt_p="#" |
| |
137 opt_t="OpenPKG" |
| |
138 opt_i="" |
| |
139 gen_tmpfile=yes |
| |
140 ;; |
| |
141 msg ) |
| |
142 str_usage="[-b] [-r] [-t <type>]" |
| |
143 arg_spec="0=" |
| |
144 opt_spec="b.r.t:" |
| |
145 opt_b=no |
| |
146 opt_r=no |
| |
147 opt_t=info |
| |
148 ;; |
| |
149 check-class ) |
| |
150 str_usage="" |
| |
151 arg_spec="1=" |
| |
152 opt_spec="" |
| |
153 ;; |
| |
154 -* ) |
| |
155 echo "$prog_name:Error: unknown option \`$tool'" 2>&1 |
| |
156 echo "$prog_name:Hint: run \`$0 -h' for usage" 2>&1 |
| |
157 exit 1 |
| |
158 ;; |
| |
159 * ) |
| |
160 echo "$prog_name:Error: unknown command \`$tool'" 2>&1 |
| |
161 echo "$prog_name:Hint: run \`$0 -h' for usage" 2>&1 |
| |
162 exit 1 |
| |
163 ;; |
| |
164 esac |
| |
165 |
| |
166 # tool information |
| |
167 toolcmd="$0 $tool" |
| |
168 toolcmdhelp="$prog_name $tool" |
| |
169 msgprefix="$prog_name:$tool" |
| |
170 |
| |
171 # parse argument specification string |
| |
172 eval `echo $arg_spec |\ |
| |
173 sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
| |
174 |
| |
175 # parse option specification string |
| |
176 eval `echo h.$opt_spec |\ |
| |
177 sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
| |
178 |
| |
179 # iterate over argument line |
| |
180 opt_PREV='' |
| |
181 while [ $# -gt 0 ]; do |
| |
182 # special option stops processing |
| |
183 if [ ".$1" = ".--" ]; then |
| |
184 shift |
| |
185 break |
| |
186 fi |
| |
187 |
| |
188 # determine option and argument |
| |
189 opt_ARG_OK=no |
| |
190 if [ ".$opt_PREV" != . ]; then |
| |
191 # merge previous seen option with argument |
| |
192 opt_OPT="$opt_PREV" |
| |
193 opt_ARG="$1" |
| |
194 opt_ARG_OK=yes |
| |
195 opt_PREV='' |
| |
196 else |
| |
197 # split argument into option and argument |
| |
198 case "$1" in |
| |
199 -[a-zA-Z0-9]*) |
| |
200 eval `echo "x$1" |\ |
| |
201 sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
| |
202 -e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
| |
203 ;; |
| |
204 -[a-zA-Z0-9]) |
| |
205 opt_OPT=`echo "x$1" | cut -c3-` |
| |
206 opt_ARG='' |
| |
207 ;; |
| |
208 *) |
| |
209 break |
| |
210 ;; |
| |
211 esac |
| |
212 fi |
| |
213 |
| |
214 # eat up option |
| |
215 shift |
| |
216 |
| |
217 # determine whether option needs an argument |
| |
218 eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
| |
219 if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then |
| |
220 if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then |
| |
221 opt_PREV="$opt_OPT" |
| |
222 continue |
| |
223 fi |
| |
224 fi |
| |
225 |
| |
226 # process option |
| |
227 case $opt_MODE in |
| |
228 '.' ) |
| |
229 # boolean option |
| |
230 eval "opt_${opt_OPT}=yes" |
| |
231 ;; |
| |
232 ':' ) |
| |
233 # option with argument (multiple occurances override) |
| |
234 eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
| |
235 ;; |
| |
236 '+' ) |
| |
237 # option with argument (multiple occurances append) |
| |
238 eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" |
| |
239 ;; |
| |
240 * ) |
| |
241 echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2 |
| |
242 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2 |
| |
243 exit 1 |
| |
244 ;; |
| |
245 esac |
| |
246 done |
| |
247 if [ ".$opt_PREV" != . ]; then |
| |
248 echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2 |
| |
249 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2 |
| |
250 exit 1 |
| |
251 fi |
| |
252 |
| |
253 # process help option |
| |
254 if [ ".$opt_h" = .yes ]; then |
| |
255 echo "Usage: $toolcmdhelp $str_usage" |
| |
256 exit 0 |
| |
257 fi |
| |
258 |
| |
259 # complain about incorrect number of arguments |
| |
260 case $arg_MODE in |
| |
261 '=' ) |
| |
262 if [ $# -ne $arg_NUMS ]; then |
| |
263 echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
| |
264 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2 |
| |
265 exit 1 |
| |
266 fi |
| |
267 ;; |
| |
268 '+' ) |
| |
269 if [ $# -lt $arg_NUMS ]; then |
| |
270 echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
| |
271 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2 |
| |
272 exit 1 |
| |
273 fi |
| |
274 ;; |
| |
275 esac |
| |
276 |
| |
277 # establish a temporary file on request |
| |
278 if [ ".$gen_tmpfile" = .yes ]; then |
| |
279 if [ ".$TMPDIR" != . ]; then |
| |
280 tmpdir="$TMPDIR" |
| |
281 else |
| |
282 tmpdir="/tmp" |
| |
283 fi |
| |
284 tmpfile="$tmpdir/.$prog_name.$$" |
| |
285 rm -f $tmpfile >/dev/null 2>&1 |
| |
286 touch $tmpfile |
| |
287 fi |
| |
288 |
| |
289 # provide a few useful variables |
| |
290 NL=" |
| |
291 " |
| |
292 TAB=" " |
| |
293 DIFS=" ${TAB}${NL}" |
| |
294 |
| |
295 # determine platform information |
| |
296 platform_machine=`(uname -m) 2>/dev/null` ||\ |
| |
297 platform_machine=`(uname -p) 2>/dev/null` ||\ |
| |
298 platform_machine='unknown' |
| |
299 if [ ".$platform_machine" = ".Power Macintosh" ]; then |
| |
300 platform_machine=`(uname -p) 2>/dev/null` |
| |
301 fi |
| |
302 platform_release=`(uname -r) 2>/dev/null` ||\ |
| |
303 platform_release='unknown' |
| |
304 platform_system=`(uname -s) 2>/dev/null` ||\ |
| |
305 platform_system='unknown' |
| |
306 platform_version=`(uname -v) 2>/dev/null` ||\ |
| |
307 platform_version='unknown' |
| |
308 platform="${platform_machine}:${platform_system}:${platform_release}:${platform_version}" |
| |
309 |
| |
310 # dispatch into tools |
| |
311 case $tool in |
| |
312 platform ) |
| |
313 # provide unique platform id |
| |
314 m=`echo "$platform_machine" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` |
| |
315 s=`echo "$platform_system" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` |
| |
316 r=`echo "$platform_release" | sed -e 's;-.*$;;'` |
| |
317 echo "${m}-${s}${r}" |
| |
318 ;; |
| |
319 |
| |
320 mflags ) |
| |
321 tool="$1" |
| |
322 isgmake=no |
| |
323 if [ ".`$tool -v -f /dev/null 2>/dev/null | grep 'GNU Make'`" != . ]; then |
| |
324 isgmake=yes |
| |
325 fi |
| |
326 mflags='' |
| |
327 if [ ".$isgmake" = .yes ]; then |
| |
328 mflags="--no-print-directory" |
| |
329 fi |
| |
330 if [ ".$opt_O" = .yes ]; then |
| |
331 case $platform in |
| |
332 *:SunOS:5.*:* | *:OSF1:*:* ) |
| |
333 if [ ".$isgmake" = .yes ]; then |
| |
334 n=`(/bin/uname -X) 2>/dev/null | grep -i NumCPU | awk '{ print $3; }'` |
| |
335 if [ ".$n" != . ]; then |
| |
336 if [ $n -gt 1 ]; then |
| |
337 n=`expr $n \* 2` |
| |
338 mflags="$mflags -j$n" |
| |
339 fi |
| |
340 fi |
| |
341 fi |
| |
342 ;; |
| |
343 *:FreeBSD:[4-8].*:* ) |
| |
344 n=`/sbin/sysctl -n hw.ncpu` |
| |
345 if [ ".$n" != . ]; then |
| |
346 if [ $n -gt 1 ]; then |
| |
347 n=`expr $n \* 2` |
| |
348 mflags="$mflags -j$n" |
| |
349 if [ ".$isgmake" = .no ]; then |
| |
350 mflags="$mflags -B" |
| |
351 fi |
| |
352 fi |
| |
353 fi |
| |
354 ;; |
| |
355 *:NetBSD:1.[56]*:* | *:NetBSD:[2345].*:* ) |
| |
356 n=`/sbin/sysctl -n hw.ncpu` |
| |
357 if [ ".$n" != . ]; then |
| |
358 if [ $n -gt 1 ]; then |
| |
359 n=`expr $n \* 2` |
| |
360 mflags="$mflags -j$n" |
| |
361 if [ ".$isgmake" = .no ]; then |
| |
362 mflags="$mflags -B" |
| |
363 fi |
| |
364 fi |
| |
365 fi |
| |
366 ;; |
| |
367 *:Linux:*:* ) |
| |
368 n=`grep ^processor /proc/cpuinfo | wc -l | awk '{ print $1; }'` |
| |
369 if [ ".$n" != . ]; then |
| |
370 if [ $n -gt 1 ]; then |
| |
371 n=`expr $n \* 2` |
| |
372 mflags="$mflags -j$n" |
| |
373 fi |
| |
374 fi |
| |
375 ;; |
| |
376 *:HP-UX:*:* ) |
| |
377 if [ ".$isgmake" = .yes ]; then |
| |
378 n=`ioscan -d processor -k -F | wc -l` |
| |
379 if [ ".$n" != . ]; then |
| |
380 if [ $n -gt 1 ]; then |
| |
381 n=`expr $n \* 2` |
| |
382 mflags="$mflags -j$n" |
| |
383 fi |
| |
384 fi |
| |
385 fi |
| |
386 ;; |
| |
387 *:IRIX64:6.*:* ) |
| |
388 if [ ".$isgmake" = .yes ]; then |
| |
389 n=`/usr/sbin/sysconf | awk '/NUM_PROCESSORS/ { print $2; }'` |
| |
390 if [ ".$n" != . ]; then |
| |
391 if [ $n -gt 1 ]; then |
| |
392 n=`expr $n \* 2` |
| |
393 mflags="$mflags -j$n" |
| |
394 fi |
| |
395 fi |
| |
396 fi |
| |
397 ;; |
| |
398 *:Darwin:*:* ) |
| |
399 n=`/usr/sbin/sysctl hw.ncpu | awk '{ print $3; }'` |
| |
400 if [ ".$n" != . ]; then |
| |
401 if [ $n -gt 1 ]; then |
| |
402 n=`expr $n \* 2` |
| |
403 mflags="$mflags -j$n" |
| |
404 if [ ".$isgmake" = .no ]; then |
| |
405 mflags="$mflags -B" |
| |
406 fi |
| |
407 fi |
| |
408 fi |
| |
409 ;; |
| |
410 *:AIX:*:* ) |
| |
411 if [ ".$isgmake" = .yes ]; then |
| |
412 if [ -x /usr/sbin/lsdev ]; then |
| |
413 n=`/usr/sbin/lsdev -C -c processor -S available | wc -l | awk '{ print $1; }'` |
| |
414 if [ ".$n" != . ]; then |
| |
415 if [ $n -gt 1 ]; then |
| |
416 n=`expr $n \* 2` |
| |
417 mflags="$mflags -j$n" |
| |
418 fi |
| |
419 fi |
| |
420 fi |
| |
421 fi |
| |
422 ;; |
| |
423 esac |
| |
424 fi |
| |
425 echo "x$mflags" | sed -e 's;^x;;' |
| |
426 ;; |
| |
427 |
| |
428 cflags ) |
| |
429 tool="$1" |
| |
430 echo $tool | grep ^/ >/dev/null |
| |
431 if [ $? -eq 0 ]; then |
| |
432 if [ ! -x "$tool" -o -d "$tool" ]; then |
| |
433 echo "$msgprefix:Error: specified tool \`$tool' not found or not executable" 1>&2 |
| |
434 exit 1 |
| |
435 fi |
| |
436 else |
| |
437 shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'` |
| |
438 sh $shtool path --suppress $tool |
| |
439 if [ $? -ne 0 ]; then |
| |
440 echo "$msgprefix:Error: specified tool \`$tool' not found in PATH" 1>&2 |
| |
441 exit 1 |
| |
442 fi |
| |
443 fi |
| |
444 isgcc=no |
| |
445 if [ ".`($tool -v; $tool --version) </dev/null 2>&1 | grep -i 'gcc'`" != . ]; then |
| |
446 isgcc=yes |
| |
447 fi |
| |
448 cflags='' |
| |
449 if [ ".$opt_O" = .yes ]; then |
| |
450 if [ ".$isgcc" = .yes ]; then |
| |
451 case "$platform:`$tool -dumpversion 2>/dev/null`" in |
| |
452 *:NetBSD:1.6*:*:2.* ) |
| |
453 # NetBSD 1.6.x with GCC 2.95.x suffers from memory |
| |
454 # exhaustion problems under GCC optimizations. |
| |
455 ;; |
| |
456 * ) |
| |
457 cflags="-O2" |
| |
458 ;; |
| |
459 esac |
| |
460 if [ ".`$tool -v 2>/dev/null | grep 'with-gnu-as'`" != . ] || \ |
| |
461 [ ".`(as --version </dev/null) 2>/dev/null | grep 'GNU'`" != . ]; then |
| |
462 cflags="$cflags -pipe" |
| |
463 fi |
| |
464 else |
| |
465 cflags="-O" |
| |
466 fi |
| |
467 fi |
| |
468 case "$platform" in |
| |
469 amd64:FreeBSD:*:* | ia64:FreeBSD:*:* | sparc64:FreeBSD:*:* | x86_64:Linux:*:* ) |
| |
470 # at least under FreeBSD on amd64, ia64 and sparc64 |
| |
471 # the GNU binutils strictly require Position In- |
| |
472 # dependent Code (PIC) when Dynamic Shared Objects |
| |
473 # (DSO) are involved. As an ugly workaround we |
| |
474 # build everything with PIC there, although this is |
| |
475 # more than required. We also can assume that the C |
| |
476 # compiler is always GCC, either the OpenPKG one or |
| |
477 # the FreeBSD one. |
| |
478 cflags="-fPIC" |
| |
479 ;; |
| |
480 esac |
| |
481 echo "x$cflags" | sed -e 's;^x;;' |
| |
482 ;; |
| |
483 |
| |
484 cppflags ) |
| |
485 std=0 |
| |
486 cppflags="" |
| |
487 for pkg in .. $*; do |
| |
488 [ ".$pkg" = ... ] && continue |
| |
489 if [ ".$pkg" = .. ]; then |
| |
490 cppflags="$cppflags -I${opt_p}/include" |
| |
491 std=1 |
| |
492 else |
| |
493 cppflags="$cppflags -I${opt_p}/include/$pkg" |
| |
494 fi |
| |
495 done |
| |
496 if [ $std -eq 0 ]; then |
| |
497 cppflags="-I${opt_p}/include$cppflags" |
| |
498 fi |
| |
499 if [ ".$opt_i" = .yes ]; then |
| |
500 arch="unknown"; os_name="unknown"; os_vers="0" |
| |
501 shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'` |
| |
502 eval `sh $shtool platform -U -S ":" -C "" -F "%<ac>:%<st>" |\ |
| |
503 sed -e 's/^\(.*\):\(.*\):\(.*\)$/arch="\1"; os_name="\2"; os_vers="\3";/'` |
| |
504 V=0; R=0; L=0 |
| |
505 eval `echo "$os_vers" |\ |
| |
506 sed -e 's/^/X/' \ |
| |
507 -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2"; L="\3";/' \ |
| |
508 -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2";/' \ |
| |
509 -e 's/^X[^0-9]*\([0-9][0-9]*\).*$/V="\1";/' \ |
| |
510 -e 's/^X.*$/:/'` |
| |
511 os_vers=`echo . | awk '{ printf("%02d%02d%02d", V, R, L); }' V="$V" R="$R" L="$L"` |
| |
512 cppflags="$cppflags -D__OPENPKG_${arch} -D__OPENPKG_${os_name}=${os_vers}" |
| |
513 fi |
| |
514 echo "x$cppflags" | sed -e 's;^x;;' -e 's;^ *;;' |
| |
515 ;; |
| |
516 |
| |
517 ldflags ) |
| |
518 std=0 |
| |
519 ldflags="" |
| |
520 for pkg in .. $*; do |
| |
521 [ ".$pkg" = ... ] && continue |
| |
522 if [ ".$pkg" = .. ]; then |
| |
523 ldflags="$ldflags -L${opt_p}/lib" |
| |
524 std=1 |
| |
525 else |
| |
526 ldflags="$ldflags -L${opt_p}/lib/$pkg" |
| |
527 fi |
| |
528 done |
| |
529 if [ $std -eq 0 ]; then |
| |
530 ldflags="-L${opt_p}/lib$ldflags" |
| |
531 fi |
| |
532 echo "x$ldflags" | sed -e 's;^x;;' -e 's;^ *;;' |
| |
533 ;; |
| |
534 |
| |
535 files ) |
| |
536 # if a Perl interpreter is available, we perform the operation |
| |
537 # with it because Perl is a magnitude (factor 10!) faster than |
| |
538 # what we can do here in Bourne-Shell. |
| |
539 perl='' |
| |
540 for dir in `echo "$PATH:@l_prefix@/lib/openpkg" | sed -e 's/:/ /g'` .; do |
| |
541 [ ".$dir" = .. -o ".$dir" = . ] && continue |
| |
542 for tool in perl5 perl miniperl; do |
| |
543 if [ -f "$dir/$tool" ]; then |
| |
544 perl="$dir/$tool" |
| |
545 break |
| |
546 fi |
| |
547 done |
| |
548 if [ ".$perl" != . ]; then |
| |
549 break |
| |
550 fi |
| |
551 done |
| |
552 if [ ".$perl" != . ]; then |
| |
553 cat >$tmpfile <<'EOT' |
| |
554 ## |
| |
555 ## PERL IMPLEMENTATION (FAST) |
| |
556 ## |
| |
557 |
| |
558 my $opt_v = 0; |
| |
559 my $opt_o = ''; |
| |
560 my $opt_r = ''; |
| |
561 while ($ARGV[0] =~ m|^-(.)(.*)$|) { |
| |
562 my ($opt, $arg) = ($1, $2); |
| |
563 shift(@ARGV); |
| |
564 unshift(@ARGV, $arg) if ($arg ne ''); |
| |
565 $opt_v = 1 if ($opt eq 'v'); |
| |
566 $opt_o = shift(@ARGV) if ($opt eq 'o'); |
| |
567 $opt_r = shift(@ARGV) if ($opt eq 'r'); |
| |
568 } |
| |
569 |
| |
570 # remember the build root in a reasonable short variable ;) |
| |
571 my $br = "$opt_r"; |
| |
572 |
| |
573 # read input file list |
| |
574 my @L = (); |
| |
575 if ($#ARGV == -1 or ($#ARGV == 0 and $ARGV[0] eq "-")) { |
| |
576 # read file list from stdin |
| |
577 while (<STDIN>) { |
| |
578 s/\n$//s; |
| |
579 push(@L, $_); |
| |
580 } |
| |
581 } |
| |
582 else { |
| |
583 # read file list from argument line |
| |
584 @L = @ARGV; |
| |
585 } |
| |
586 |
| |
587 # PASS 1: PREPARATION AND SYNTACTICAL EXPANSION |
| |
588 if ($opt_v == 1) { |
| |
589 print STDERR "rpmtool:files: pass 1 (preparation and syntactical expansions)\n"; |
| |
590 } |
| |
591 my @T = (); |
| |
592 my $l; |
| |
593 foreach $l (@L) { |
| |
594 # replace tabs with spaces, reduce multiple spaces to single |
| |
595 # spaces, and remove leading and trailing spaces |
| |
596 $l =~ s|[ \t\n]+| |sg; |
| |
597 $l =~ s|^[ \t]+||sg; |
| |
598 $l =~ s|[ \t]+$||sg; |
| |
599 |
| |
600 # move tags to end of entry for easier parsing |
| |
601 1 while ($l =~ s|^(%\S+) (.+)|$2 $1|); |
| |
602 |
| |
603 # use `:' as a dummy path for tag-only entries (like `%defattr') |
| |
604 # to avoid special cases in the later processing |
| |
605 if ($l =~ m|^%.+|) { |
| |
606 $l = ": $l"; |
| |
607 } |
| |
608 |
| |
609 # split entry into path and optional tags |
| |
610 my ($p, $t) = ($l =~ m|^(\S+)(.*)$|); |
| |
611 |
| |
612 # expand `{foo,bar,quux}' constructs in path (silent |
| |
613 # assumtion to make life easier is that the constructs |
| |
614 # occurs only once in a path!) |
| |
615 if ($p =~ m|^(.*)\{([^\}]+)\}(.*)$|) { |
| |
616 # split path into prolog, the set construct, and the epilog |
| |
617 my ($pro, $set, $epi) = ($1, $2, $3); |
| |
618 |
| |
619 # repeat prolog and epilog for all elements in set |
| |
620 my $x; |
| |
621 foreach $x (split(/,/, $set)) { |
| |
622 push(@T, "${pro}${x}${epi}${t}"); |
| |
623 } |
| |
624 } |
| |
625 else { |
| |
626 # else just take over the entry as is |
| |
627 push(@T, $l); |
| |
628 } |
| |
629 } |
| |
630 @L = @T; |
| |
631 |
| |
632 # PASS 2: FILESYSTEM-BASED EXPANSIONS |
| |
633 if ($opt_v == 1) { |
| |
634 print STDERR "rpmtool:files: pass 2 (filesystem-based expansions)\n"; |
| |
635 } |
| |
636 @T = (); |
| |
637 foreach $l (@L) { |
| |
638 # split entry into path and optional tags |
| |
639 my ($p, $t) = ($l =~ m|^(\S*)(.*)$|); |
| |
640 |
| |
641 # expand... |
| |
642 if (-d "$br$p" and $t !~ m|.*%dir.*|) { |
| |
643 # expand path because it is not tagged with %dir |
| |
644 my @X = `cd "$br$p" && find . -print`; |
| |
645 my $x; |
| |
646 foreach $x (@X) { |
| |
647 $x =~ s|\n$||s; |
| |
648 $x =~ s|^\.|$p|s; |
| |
649 push(@T, "${x}${t}"); |
| |
650 } |
| |
651 } |
| |
652 else { |
| |
653 # expand path wildcards (`*' and `[..]') |
| |
654 # (if not wildcards are present, this doesn't harm) |
| |
655 my @X = glob("$br$p"); |
| |
656 my $x; |
| |
657 foreach $x (@X) { |
| |
658 my $brqm = quotemeta($br); |
| |
659 $x =~ s|^$brqm||s; |
| |
660 push(@T, "${x}${t}"); |
| |
661 } |
| |
662 } |
| |
663 } |
| |
664 @L = @T; |
| |
665 |
| |
666 # PASS 3: DUPLICATION REMOVAL AND CLEANUP |
| |
667 if ($opt_v == 1) { |
| |
668 print STDERR "rpmtool:files: pass 3 (duplication removal and cleanup)\n"; |
| |
669 } |
| |
670 @T = (); |
| |
671 foreach $l (@L) { |
| |
672 # split entry into path and optional tags |
| |
673 my ($p, $t) = ($l =~ m|^(\S*)(.*)$|); |
| |
674 |
| |
675 # add %dir tag if entry is a directory, but still not |
| |
676 # tagged as such (else RPM would again expand it recursively) |
| |
677 if (-d "$br$p") { |
| |
678 if ($t !~ m|%dir|) { |
| |
679 $t .= " %dir"; |
| |
680 } |
| |
681 } |
| |
682 |
| |
683 # remove duplicate entries in already processed part |
| |
684 # (but make sure we keep the entries with the dummy tags) |
| |
685 if ($p ne ":") { |
| |
686 my @T2 = (); |
| |
687 foreach $t (@T) { |
| |
688 my $pqm = quotemeta($p); |
| |
689 next if ($t =~ m|^$pqm | or $t eq $p); |
| |
690 push(@T2, $t); |
| |
691 } |
| |
692 @T = @T2; |
| |
693 } |
| |
694 |
| |
695 # keep entry only if no %not tag is present |
| |
696 # (else all entries are removed) |
| |
697 if ($t !~ m|.*%not.*|) { |
| |
698 push(@T, "${p}${t}"); |
| |
699 } |
| |
700 } |
| |
701 @L = @T; |
| |
702 |
| |
703 # write out new file list |
| |
704 @T = (); |
| |
705 foreach $l (@L) { |
| |
706 $l =~ s|^(\S+) (.*)$|$2 $1|sg; |
| |
707 $l =~ s|^\s+||s; |
| |
708 $l =~ s|\s+$||s; |
| |
709 $l =~ s|\s+:$||s; |
| |
710 push(@T, $l); |
| |
711 } |
| |
712 @L = @T; |
| |
713 if ($opt_o eq '' or $opt_o eq '-') { |
| |
714 print STDOUT join("\n", @L)."\n"; |
| |
715 } |
| |
716 else { |
| |
717 open(FP, ">$opt_o"); |
| |
718 print FP join("\n", @L)."\n"; |
| |
719 close(FP); |
| |
720 } |
| |
721 EOT |
| |
722 cmd="$perl $tmpfile"; |
| |
723 if [ ".$opt_v" = .yes ]; then |
| |
724 cmd="$cmd -v" |
| |
725 fi |
| |
726 if [ ".$opt_o" != . ]; then |
| |
727 cmd="$cmd -o \"$opt_o\"" |
| |
728 fi |
| |
729 if [ ".$opt_r" != . ]; then |
| |
730 cmd="$cmd -r \"$opt_r\"" |
| |
731 fi |
| |
732 for arg |
| |
733 do |
| |
734 cmd="$cmd \"$arg\"" |
| |
735 done |
| |
736 eval "$cmd" |
| |
737 else |
| |
738 ## |
| |
739 ## BOURNE-SHELL IMPLEMENTATION (PORTABLE) |
| |
740 ## |
| |
741 |
| |
742 # remember the build root in a reasonable short variable ;) |
| |
743 br="$opt_r" |
| |
744 |
| |
745 # make sure filename expansion is disabled per default |
| |
746 set -f |
| |
747 |
| |
748 # read input file list |
| |
749 L='' |
| |
750 if [ $# -eq 0 ] || [ $# -eq 1 -a ".$1" = ".-" ]; then |
| |
751 # read file list from stdin |
| |
752 L=`cat` |
| |
753 else |
| |
754 # read file list from argument line |
| |
755 for arg |
| |
756 do |
| |
757 L="$L$NL$arg" |
| |
758 done |
| |
759 fi |
| |
760 |
| |
761 # PASS 1: PREPARATION AND SYNTACTICAL EXPANSION |
| |
762 if [ ".$opt_v" = .yes ]; then |
| |
763 echo "rpmtool:files: pass 1 (preparation and syntactical expansions)" 1>&2 |
| |
764 fi |
| |
765 T='' |
| |
766 OIFS="$IFS"; IFS="$NL" |
| |
767 for l in $L; do |
| |
768 [ ".$l" = . ] && continue |
| |
769 |
| |
770 # replace tabs with spaces, reduce multiple spaces to single |
| |
771 # spaces, and remove leading and trailing spaces |
| |
772 l=`echo "$l" | sed -e "s;${TAB}; ;g" -e 's; *; ;g' -e 's;^ *;;' -e 's; *$;;'` |
| |
773 |
| |
774 # move tags to end of entry for easier parsing |
| |
775 while [ ".`echo \"$l\" | grep '^%[^ ]* .*'`" != . ]; do |
| |
776 l=`echo "$l" | sed -e 's;^\(%[^ ]*\) \(.*\);\2 \1;'` |
| |
777 done |
| |
778 |
| |
779 # use `:' as a dummy path for tag-only entries (like `%defattr') |
| |
780 # to avoid special cases in the later processing |
| |
781 if [ ".`echo \"$l\" | grep '^%.*'`" != . ]; then |
| |
782 l=": $l" |
| |
783 fi |
| |
784 |
| |
785 # split entry into path and optional tags |
| |
786 eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
| |
787 |
| |
788 # expand `{foo,bar,quux}' constructs in path (silent |
| |
789 # assumtion to make life easier is that the constructs |
| |
790 # occurs only once in a path!) |
| |
791 if [ ".`echo \".$p\" | grep '^\..*{[^}]*}.*$'`" != . ]; then |
| |
792 |
| |
793 # split path into prolog, the set construct, and the epilog |
| |
794 eval `echo ".$p" | sed -e 's;^\.\(.*\){\([^}]*\)}\(.*\)$;pro="\1" set="\2" epi="\3";'` |
| |
795 |
| |
796 # repeat prolog and epilog for all elements in set |
| |
797 OIFS2="$IFS"; IFS="," |
| |
798 for x in $set; do |
| |
799 T="$T$NL${pro}${x}${epi}${t}" |
| |
800 done |
| |
801 IFS="$OIFS2" |
| |
802 else |
| |
803 # else just take over the entry as is |
| |
804 T="$T$NL$l" |
| |
805 fi |
| |
806 done |
| |
807 L="$T" |
| |
808 IFS="$OIFS" |
| |
809 |
| |
810 # PASS 2: FILESYSTEM-BASED EXPANSIONS |
| |
811 if [ ".$opt_v" = .yes ]; then |
| |
812 echo "rpmtool:files: pass 2 (filesystem-based expansions)" 1>&2 |
| |
813 fi |
| |
814 T='' |
| |
815 OIFS="$IFS"; IFS="$NL" |
| |
816 for l in $L; do |
| |
817 [ ".$l" = . ] && continue |
| |
818 |
| |
819 # split entry into path and optional tags |
| |
820 eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
| |
821 |
| |
822 # expand... |
| |
823 if [ -d "$br$p" -a ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then |
| |
824 # expand path because it is not tagged with %dir |
| |
825 OIFS2="$IFS"; IFS="$DIFS" |
| |
826 for x in `cd "$br$p" && find . -print | sed -e "s;^\\.;$p;"`; do |
| |
827 T="$T$NL${x}${t}" |
| |
828 done |
| |
829 IFS="$OIFS2" |
| |
830 else |
| |
831 # expand path wildcards (`*' and `[..]') |
| |
832 # (if not wildcards are present, this doesn't harm) |
| |
833 OIFS2="$IFS"; IFS="$DIFS" |
| |
834 for x in `(set +f; echo $br$p) | sed -e "s;^$br;;" -e "s; $br; ;g"`; do |
| |
835 T="$T$NL${x}${t}" |
| |
836 done |
| |
837 IFS="$OIFS2" |
| |
838 fi |
| |
839 done |
| |
840 IFS="$OIFS" |
| |
841 L="$T" |
| |
842 |
| |
843 # PASS 3: DUPLICATION REMOVAL AND CLEANUP |
| |
844 if [ ".$opt_v" = .yes ]; then |
| |
845 echo "rpmtool:files: pass 3 (duplication removal and cleanup)" 1>&2 |
| |
846 fi |
| |
847 T='' |
| |
848 OIFS="$IFS"; IFS="$NL" |
| |
849 for l in $L; do |
| |
850 [ ".$l" = . ] && continue |
| |
851 |
| |
852 # split entry into path and optional tags |
| |
853 eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
| |
854 |
| |
855 # add %dir tag if entry is a directory, but still not |
| |
856 # tagged as such (else RPM would again expand it recursively) |
| |
857 if [ -d "$br$p" ]; then |
| |
858 if [ ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then |
| |
859 t="$t %dir" |
| |
860 fi |
| |
861 fi |
| |
862 |
| |
863 # remove duplicate entries in already processed part |
| |
864 # (but make sure we keep the entries with the dummy tags) |
| |
865 if [ ".$p" != ".:" ]; then |
| |
866 T=`echo "$T" | grep -v "^$p " | grep -v "^$p\$"` |
| |
867 fi |
| |
868 |
| |
869 # keep entry only if no %not tag is present |
| |
870 # (else all entries are removed) |
| |
871 if [ ".`expr \".$t\" : '\..*%not.*'`" = .0 ]; then |
| |
872 T="$T$NL${p}${t}" |
| |
873 fi |
| |
874 done |
| |
875 IFS="$OIFS" |
| |
876 L="$T" |
| |
877 |
| |
878 # write out new file list |
| |
879 if [ ".$opt_o" = . -o ".$opt_o" = ".-" ]; then |
| |
880 outcmd="cat" |
| |
881 else |
| |
882 outcmd="cat > $opt_o" |
| |
883 fi |
| |
884 echo "$L" |\ |
| |
885 sed -e '/^$/d' \ |
| |
886 -e 's;^\([^ ]*\) *\(.*\)$;\2 \1;g' \ |
| |
887 -e 's;^ *;;' \ |
| |
888 -e 's; *$;;' \ |
| |
889 -e 's; *:$;;' | eval $outcmd |
| |
890 fi |
| |
891 ;; |
| |
892 |
| |
893 signal ) |
| |
894 if [ ".$opt_p" = . -a ".$opt_m" = . ]; then |
| |
895 echo "$msgprefix:Error: either option -p or -m has to be specified" 1>&2 |
| |
896 exit 1 |
| |
897 fi |
| |
898 case "$platform" in |
| |
899 *:FreeBSD:*:* | *:NetBSD:*:* ) |
| |
900 cmd0="ps -ax -o pid" |
| |
901 cmd1="ps -ax -o command" |
| |
902 cmd2="ps -ax -o pid,command" |
| |
903 cmd3="ps -ax -o pid,ppid" |
| |
904 ;; |
| |
905 *:Linux:*:* | *:OSF1:5.*:* ) |
| |
906 cmd0="ps axo pid" |
| |
907 cmd1="ps axo cmd" |
| |
908 cmd2="ps axo pid,cmd" |
| |
909 cmd3="ps axo pid,ppid" |
| |
910 ;; |
| |
911 *:SunOS:5.*:* ) |
| |
912 cmd0="ps -ef -o pid" |
| |
913 cmd1="ps -ef -o args" |
| |
914 cmd2="ps -ef -o pid,args" |
| |
915 cmd3="ps -ef -o pid,ppid" |
| |
916 ;; |
| |
917 *:HP-UX:*:* ) |
| |
918 cmd0="ps -ef" # FIXME |
| |
919 cmd1="ps -ef" # FIXME |
| |
920 cmd2="ps -ef" # FIXME |
| |
921 cmd3="ps -ef" # FIXME |
| |
922 ;; |
| |
923 *:IRIX64:6.*:* ) |
| |
924 cmd0="ps -ef -o pid" |
| |
925 cmd1="ps -ef -o args" |
| |
926 cmd2="ps -ef -o pid,args" |
| |
927 cmd3="ps -ef -o pid,ppid" |
| |
928 ;; |
| |
929 *:Darwin:*:* ) |
| |
930 cmd0="ps -ax -opid" |
| |
931 cmd1="ps -ax -ocommand" |
| |
932 cmd2="ps -ax -opid,command" |
| |
933 cmd3="ps -ax -opid,ppid" |
| |
934 esac |
| |
935 # try all signals in order |
| |
936 i=$# |
| |
937 for sig in "$@"; do |
| |
938 # check whether program is still running/active |
| |
939 active="" |
| |
940 if [ ".$opt_p" != . ]; then |
| |
941 active=`$cmd0 | grep "$opt_p" | grep -v grep | grep -v rpmtool` |
| |
942 elif [ ".$opt_m" != . ]; then |
| |
943 active=`$cmd1 | grep "$opt_m" | grep -v grep | grep -v rpmtool` |
| |
944 fi |
| |
945 if [ ".$active" = . ]; then |
| |
946 break |
| |
947 fi |
| |
948 |
| |
949 # send signal to program |
| |
950 if [ ".$opt_p" != . ]; then |
| |
951 pids="$opt_p" |
| |
952 elif [ ".$opt_m" != . ]; then |
| |
953 pids=`$cmd2 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* .*$opt_m" |\ |
| |
954 grep -v grep | grep -v rpmtool |\ |
| |
955 awk '{ printf("%s\n", $1); }'` |
| |
956 fi |
| |
957 for pid in $pids; do |
| |
958 if [ ".$opt_v" = .yes ]; then |
| |
959 echo "sending $sig signal to process $pid" |
| |
960 fi |
| |
961 if [ ".$opt_t" = .yes ]; then |
| |
962 echo "kill -$sig $pid" |
| |
963 fi |
| |
964 if [ ".$opt_n" = .no ]; then |
| |
965 eval "kill -$sig $pid" |
| |
966 fi |
| |
967 done |
| |
968 |
| |
969 # optionally send signal to childs of program |
| |
970 if [ ".$opt_c" = .yes ]; then |
| |
971 for pid in $pids; do |
| |
972 cpids=`$cmd3 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* $pid" |\ |
| |
973 grep -v grep | grep -v rpmtool |\ |
| |
974 awk '{ printf("%s\n", $1); }'` |
| |
975 for cpid in $cpids; do |
| |
976 if [ ".$opt_v" = .yes ]; then |
| |
977 echo "sending $sig signal to child process $cpid" |
| |
978 fi |
| |
979 if [ ".$opt_t" = .yes ]; then |
| |
980 echo "kill -$sig $cpid" |
| |
981 fi |
| |
982 if [ ".$opt_n" = .no ]; then |
| |
983 eval "kill -$sig $cpid >/dev/null 2>&1" |
| |
984 fi |
| |
985 done |
| |
986 done |
| |
987 fi |
| |
988 |
| |
989 # perform optional delay |
| |
990 i=`expr $i - 1` |
| |
991 if [ $i -gt 0 ]; then |
| |
992 if [ ".$opt_d" != . -a ".$opt_d" != . ]; then |
| |
993 sleep $opt_d |
| |
994 fi |
| |
995 fi |
| |
996 done |
| |
997 ;; |
| |
998 |
| |
999 config ) |
| |
1000 # usage consistency |
| |
1001 if [ ".$opt_a" = .no -a ".$opt_r" = .no ]; then |
| |
1002 echo "$msgprefix:Error: either option -a or -r has to be specified" 1>&2 |
| |
1003 exit 1 |
| |
1004 fi |
| |
1005 configfile="$1" |
| |
1006 |
| |
1007 # determine block markers |
| |
1008 block_start="${opt_p}<${opt_t}" |
| |
1009 if [ ".$opt_i" != . ]; then |
| |
1010 block_start="${block_start} id=\"${opt_i}\"" |
| |
1011 fi |
| |
1012 block_start="${block_start}>" |
| |
1013 block_end="${opt_p}</${opt_t}>" |
| |
1014 |
| |
1015 # slash-escaped versions of block markers (for sed(3) call) |
| |
1016 block_start_esc=`echo "$block_start" | sed -e 's;/;\\\\/;g'` |
| |
1017 block_end_esc=`echo "$block_end" | sed -e 's;/;\\\\/;g'` |
| |
1018 |
| |
1019 # determine backup extension |
| |
1020 case "X$opt_b" in |
| |
1021 X ) ext=".bak" ;; |
| |
1022 X.* ) ext="$opt_b" ;; |
| |
1023 X* ) ext=".$opt_b" ;; |
| |
1024 esac |
| |
1025 |
| |
1026 # check for block in config file |
| |
1027 if [ -f $configfile ]; then |
| |
1028 check=`grep "^${block_start}" $configfile` |
| |
1029 else |
| |
1030 touch $configfile |
| |
1031 check="" |
| |
1032 fi |
| |
1033 |
| |
1034 # add entry |
| |
1035 if [ ".$opt_a" = .yes ]; then |
| |
1036 if [ ".$check" != . ]; then |
| |
1037 if [ ".$opt_s" = .yes ]; then |
| |
1038 exit 0 |
| |
1039 else |
| |
1040 echo "$msgprefix:Error: config entry already exists" 1>&2 |
| |
1041 exit 1 |
| |
1042 fi |
| |
1043 fi |
| |
1044 cp $configfile $configfile$ext |
| |
1045 echo "${block_start}" >$tmpfile |
| |
1046 cat >>$tmpfile |
| |
1047 echo "${block_end}" >>$tmpfile |
| |
1048 cat $tmpfile >>$configfile |
| |
1049 |
| |
1050 # remove entry |
| |
1051 elif [ ".$opt_r" = .yes ]; then |
| |
1052 if [ ".$check" = . ]; then |
| |
1053 if [ ".$opt_s" = .yes ]; then |
| |
1054 exit 0 |
| |
1055 else |
| |
1056 echo "$msgprefix:Error: config entry does not exist" 1>&2 |
| |
1057 exit 1 |
| |
1058 fi |
| |
1059 fi |
| |
1060 cp $configfile $configfile$ext |
| |
1061 sed -e "/^${block_start_esc}/,/^${block_end_esc}/d" \ |
| |
1062 <$configfile$ext >$configfile |
| |
1063 fi |
| |
1064 |
| |
1065 # verbosity |
| |
1066 if [ ".$opt_v" = .yes ]; then |
| |
1067 (diff -u1 $configfile$ext $configfile >$tmpfile) 2>/dev/null |
| |
1068 if [ ".`cat $tmpfile`" = . ]; then |
| |
1069 (diff -C1 $configfile$ext $configfile >$tmpfile) 2>/dev/null |
| |
1070 if [ ".`cat $tmpfile`" = . ]; then |
| |
1071 if [ ".$opt_s" = .no ]; then |
| |
1072 echo "$msgprefix:Warning: unable to show difference for config file \`$configfile'" 1>&2 |
| |
1073 fi |
| |
1074 fi |
| |
1075 fi |
| |
1076 echo "editing $configfile:" |
| |
1077 cat $tmpfile |
| |
1078 fi |
| |
1079 |
| |
1080 # optionally remove backup file |
| |
1081 if [ ".$opt_b" = . ]; then |
| |
1082 rm -f $configfile$ext |
| |
1083 fi |
| |
1084 ;; |
| |
1085 |
| |
1086 msg ) |
| |
1087 # optionally beep before message |
| |
1088 if [ ".$opt_b" = .yes ]; then |
| |
1089 echo . | awk '{ printf("%c", 7); }' |
| |
1090 fi |
| |
1091 title="" |
| |
1092 case $opt_t in |
| |
1093 info ) title="-------" ;; |
| |
1094 notice ) title="Notice-" ;; |
| |
1095 warn ) title="Warning" ;; |
| |
1096 error ) title="Error--" ;; |
| |
1097 * ) echo "$msgprefix:Error: invalid message type \`$opt_t'" 1>&2; exit 1 ;; |
| |
1098 esac |
| |
1099 |
| |
1100 # display message |
| |
1101 if [ ".$opt_r" != .yes ]; then |
| |
1102 echo . | awk '{ printf("\r"); }' |
| |
1103 fi |
| |
1104 echo "+----------------------------------${title}------------------------------------+" |
| |
1105 expand -t 8 | sed -e 's; *$;;' | awk '{ printf("| %-75s |\n", substr($0, 0, 75)); }' |
| |
1106 echo "+-----------------------------------------------------------------------------+" |
| |
1107 ;; |
| |
1108 check-class ) |
| |
1109 # check package class from within .spec file macro expansion for %prep section |
| |
1110 class="$1"; shift |
| |
1111 case "$class" in |
| |
1112 CORE|BASE ) |
| |
1113 ;; |
| |
1114 PLUS ) |
| |
1115 echo "set +x" |
| |
1116 ( echo "This OpenPKG package is of class PLUS." |
| |
1117 echo "This means it is still in extended QUALITY ASSURANCE state." |
| |
1118 echo "Hence it is still NOT ready for careless use." |
| |
1119 echo "Do not use it in critical production environments." |
| |
1120 echo "It might be still potentially unstable under run-time." |
| |
1121 ) | sh $prog_path msg -r -t notice | sed -e 's;^;echo ";' -e 's;$;";' |
| |
1122 echo "set -x" |
| |
1123 ;; |
| |
1124 EVAL ) |
| |
1125 echo "set +x" |
| |
1126 ( echo "This OpenPKG package is of class EVAL." |
| |
1127 echo "This means it is still in EVALUATION and QUALITY ASSURANCE state." |
| |
1128 echo "Hence it is still NOT ready for general use." |
| |
1129 echo "Do not use it in production environments." |
| |
1130 echo "It might be unstable under run-time or still incompletely packaged." |
| |
1131 ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";' |
| |
1132 echo "set -x" |
| |
1133 ;; |
| |
1134 JUNK ) |
| |
1135 echo "set +x" |
| |
1136 ( echo "This OpenPKG package is of class JUNK." |
| |
1137 echo "This means it is still in DEVELOPMENT state." |
| |
1138 echo "Hence it is still NOT ready even for general evaluation." |
| |
1139 echo "Do not use it at all, except in development environments!" |
| |
1140 echo "It is definitely unstable and incompletely packaged." |
| |
1141 ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";' |
| |
1142 echo "set -x" |
| |
1143 ;; |
| |
1144 esac |
| |
1145 ;; |
| |
1146 esac |
| |
1147 |
| |
1148 # cleanup |
| |
1149 if [ ".$gen_tmpfile" = .yes ]; then |
| |
1150 rm -f $tmpfile >/dev/null 2>&1 |
| |
1151 fi |
| |
1152 |
| |
1153 # die gracefully ;) |
| |
1154 exit 0 |
| |
1155 |