Annotation of embedaddon/php/build/shtool, revision 1.1.1.1
1.1 misho 1: #!/bin/sh
2: ##
3: ## GNU shtool -- The GNU Portable Shell Tool
4: ## Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>
5: ##
6: ## See http://www.gnu.org/software/shtool/ for more information.
7: ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
8: ##
9: ## Version: 2.0.8 (18-Jul-2008)
10: ## Contents: 5/19 available modules
11: ##
12:
13: ##
14: ## This program is free software; you can redistribute it and/or modify
15: ## it under the terms of the GNU General Public License as published by
16: ## the Free Software Foundation; either version 2 of the License, or
17: ## (at your option) any later version.
18: ##
19: ## This program is distributed in the hope that it will be useful,
20: ## but WITHOUT ANY WARRANTY; without even the implied warranty of
21: ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22: ## General Public License for more details.
23: ##
24: ## You should have received a copy of the GNU General Public License
25: ## along with this program; if not, write to the Free Software
26: ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27: ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
28: ##
29: ## NOTICE: Given that you include this file verbatim into your own
30: ## source tree, you are justified in saying that it remains separate
31: ## from your package, and that this way you are simply just using GNU
32: ## shtool. So, in this situation, there is no requirement that your
33: ## package itself is licensed under the GNU General Public License in
34: ## order to take advantage of GNU shtool.
35: ##
36:
37: ##
38: ## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
39: ##
40: ## Available commands:
41: ## echo Print string with optional construct expansion
42: ## install Install a program, script or datafile
43: ## mkdir Make one or more directories
44: ## platform Platform Identification Utility
45: ## path Deal with program paths
46: ##
47: ## Not available commands (because module was not built-in):
48: ## mdate Pretty-print modification time of a file or dir
49: ## table Pretty-print a field-separated list as a table
50: ## prop Display progress with a running propeller
51: ## move Move files with simultaneous substitution
52: ## mkln Make link with calculation of relative paths
53: ## mkshadow Make a shadow tree through symbolic links
54: ## fixperm Fix file permissions inside a source tree
55: ## rotate Logfile rotation
56: ## tarball Roll distribution tarballs
57: ## subst Apply sed(1) substitution operations
58: ## arx Extended archive command
59: ## slo Separate linker options by library class
60: ## scpp Sharing C Pre-Processor
61: ## version Maintain a version information file
62: ##
63:
64: # maximum Bourne-Shell compatibility
65: if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then
66: # reconfigure zsh(1)
67: emulate sh
68: NULLCMD=:
69: alias -g '${1+"$@"}'='"$@"'
70: elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then
71: # reconfigure bash(1)
72: set -o posix
73: fi
74:
75: # maximum independence of NLS nuisances
76: for var in \
77: LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
78: LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
79: LC_TELEPHONE LC_TIME
80: do
81: if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then
82: eval $var=C; export $var
83: else
84: unset $var
85: fi
86: done
87:
88: # initial command line handling
89: if [ $# -eq 0 ]; then
90: echo "$0:Error: invalid command line" 1>&2
91: echo "$0:Hint: run \`$0 -h' for usage" 1>&2
92: exit 1
93: fi
94: if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then
95: echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)"
96: echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>'
97: echo 'Report bugs to <bug-shtool@gnu.org>'
98: echo ''
99: echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
100: echo ''
101: echo 'Available global <options>:'
102: echo ' -v, --version display shtool version information'
103: echo ' -h, --help display shtool usage help page (this one)'
104: echo ' -d, --debug display shell trace information'
105: echo ' -r, --recreate recreate this shtool script via shtoolize'
106: echo ''
107: echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
108: echo ' echo [-n|--newline] [-e|--expand] [<string> ...]'
109: echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
110: echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
111: echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
112: echo ' <sed-cmd>] <file> [<file> ...] <path>'
113: echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
114: echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
115: echo ' [<dir> ...]'
116: echo ' platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc'
117: echo ' <string>] [-L|--lower] [-U|--upper] [-v|--verbose]'
118: echo ' [-c|--concise] [-n|--no-newline] [-t|--type <type>]'
119: echo ' [-V|--version] [-h|--help]'
120: echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
121: echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
122: echo ''
123: echo 'Not available <cmd-name> (because module was not built-in):'
124: echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
125: echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
126: echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
127: echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
128: echo ' prop [-p|--prefix <str>]'
129: echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
130: echo ' <src-file> <dst-file>'
131: echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
132: echo ' [<src-path> ...] <dst-path>'
133: echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
134: echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
135: echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
136: echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
137: echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
138: echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode'
139: echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate'
140: echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
141: echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
142: echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
143: echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
144: echo ' <path> [<path> ...]'
145: echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]'
146: echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup'
147: echo ' <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]'
148: echo ' [...]'
149: echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
150: echo ' ...]'
151: echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
152: echo ' ...]'
153: echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
154: echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
155: echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
156: echo ' <file> [<file> ...]'
157: echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
158: echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
159: echo ' <knob>] [-d|--display <type>] <file>'
160: echo ''
161: exit 0
162: fi
163: if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then
164: echo "GNU shtool 2.0.8 (18-Jul-2008)"
165: exit 0
166: fi
167: if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then
168: shtoolize -obuild/shtool echo install mkdir platform path
169: exit 0
170: fi
171: if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then
172: shift
173: set -x
174: fi
175: name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
176: case "$name" in
177: echo|install|mkdir|platform|path )
178: # implicit tool command selection
179: tool="$name"
180: ;;
181: * )
182: # explicit tool command selection
183: tool="$1"
184: shift
185: ;;
186: esac
187: arg_spec=""
188: opt_spec=""
189: gen_tmpfile=no
190:
191: ##
192: ## DISPATCH INTO SCRIPT PROLOG
193: ##
194:
195: case $tool in
196: echo )
197: str_tool="echo"
198: str_usage="[-n|--newline] [-e|--expand] [<string> ...]"
199: arg_spec="0+"
200: opt_spec="n.e."
201: opt_alias="n:newline,e:expand"
202: opt_n=no
203: opt_e=no
204: ;;
205: install )
206: str_tool="install"
207: str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
208: arg_spec="1+"
209: opt_spec="v.t.d.c.C.s.m:o:g:e+"
210: opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
211: opt_v=no
212: opt_t=no
213: opt_d=no
214: opt_c=no
215: opt_C=no
216: opt_s=no
217: opt_m="0755"
218: opt_o=""
219: opt_g=""
220: opt_e=""
221: ;;
222: mkdir )
223: str_tool="mkdir"
224: str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
225: arg_spec="1+"
226: opt_spec="t.f.p.m:o:g:"
227: opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
228: opt_t=no
229: opt_f=no
230: opt_p=no
231: opt_m=""
232: opt_o=""
233: opt_g=""
234: ;;
235: platform )
236: str_tool="platform"
237: str_usage="[-F|--format <format>] [-S|--sep <string>] [-C|--conc <string>] [-L|--lower] [-U|--upper] [-v|--verbose] [-c|--concise] [-n|--no-newline] [-t|--type <type>] [-V|--version] [-h|--help]"
238: arg_spec="0="
239: opt_spec="F:S:C:L.U.v.c.n.t:d.V.h."
240: opt_alias="F:format,S:sep,C:conc,L:lower,U:upper,v:verbose,c:consise,t:type,n:no-newline,V:version,h:help"
241: opt_F="%{sp} (%{ap})"
242: opt_S=" "
243: opt_C="/"
244: opt_L=no
245: opt_U=no
246: opt_t=""
247: opt_v=no
248: opt_c=no
249: opt_n=no
250: opt_V=no
251: opt_h=no
252: ;;
253: path )
254: str_tool="path"
255: str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
256: gen_tmpfile=yes
257: arg_spec="1+"
258: opt_spec="s.r.d.b.m.p:"
259: opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
260: opt_s=no
261: opt_r=no
262: opt_d=no
263: opt_b=no
264: opt_m=no
265: opt_p="$PATH"
266: ;;
267: -* )
268: echo "$0:Error: unknown option \`$tool'" 2>&1
269: echo "$0:Hint: run \`$0 -h' for usage" 2>&1
270: exit 1
271: ;;
272: * )
273: echo "$0:Error: unknown command \`$tool'" 2>&1
274: echo "$0:Hint: run \`$0 -h' for usage" 2>&1
275: exit 1
276: ;;
277: esac
278:
279: ##
280: ## COMMON UTILITY CODE
281: ##
282:
283: # commonly used ASCII values
284: ASC_TAB=" "
285: ASC_NL="
286: "
287:
288: # determine name of tool
289: if [ ".$tool" != . ]; then
290: # used inside shtool script
291: toolcmd="$0 $tool"
292: toolcmdhelp="shtool $tool"
293: msgprefix="shtool:$tool"
294: else
295: # used as standalone script
296: toolcmd="$0"
297: toolcmdhelp="sh $0"
298: msgprefix="$str_tool"
299: fi
300:
301: # parse argument specification string
302: eval `echo $arg_spec |\
303: sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
304:
305: # parse option specification string
306: eval `echo h.$opt_spec |\
307: sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
308:
309: # parse option alias string
310: eval `echo h:help,$opt_alias |\
311: sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
312:
313: # interate over argument line
314: opt_PREV=''
315: while [ $# -gt 0 ]; do
316: # special option stops processing
317: if [ ".$1" = ".--" ]; then
318: shift
319: break
320: fi
321:
322: # determine option and argument
323: opt_ARG_OK=no
324: if [ ".$opt_PREV" != . ]; then
325: # merge previous seen option with argument
326: opt_OPT="$opt_PREV"
327: opt_ARG="$1"
328: opt_ARG_OK=yes
329: opt_PREV=''
330: else
331: # split argument into option and argument
332: case "$1" in
333: --[a-zA-Z0-9]*=*)
334: eval `echo "x$1" |\
335: sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
336: opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
337: eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
338: ;;
339: --[a-zA-Z0-9]*)
340: opt_OPT=`echo "x$1" | cut -c4-`
341: opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
342: eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
343: opt_ARG=''
344: ;;
345: -[a-zA-Z0-9]*)
346: eval `echo "x$1" |\
347: sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
348: -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
349: ;;
350: -[a-zA-Z0-9])
351: opt_OPT=`echo "x$1" | cut -c3-`
352: opt_ARG=''
353: ;;
354: *)
355: break
356: ;;
357: esac
358: fi
359:
360: # eat up option
361: shift
362:
363: # determine whether option needs an argument
364: eval "opt_MODE=\$opt_MODE_${opt_OPT}"
365: if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then
366: if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then
367: opt_PREV="$opt_OPT"
368: continue
369: fi
370: fi
371:
372: # process option
373: case $opt_MODE in
374: '.' )
375: # boolean option
376: eval "opt_${opt_OPT}=yes"
377: ;;
378: ':' )
379: # option with argument (multiple occurances override)
380: eval "opt_${opt_OPT}=\"\$opt_ARG\""
381: ;;
382: '+' )
383: # option with argument (multiple occurances append)
384: eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
385: ;;
386: * )
387: echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
388: echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
389: exit 1
390: ;;
391: esac
392: done
393: if [ ".$opt_PREV" != . ]; then
394: echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
395: echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
396: exit 1
397: fi
398:
399: # process help option
400: if [ ".$opt_h" = .yes ]; then
401: echo "Usage: $toolcmdhelp $str_usage"
402: exit 0
403: fi
404:
405: # complain about incorrect number of arguments
406: case $arg_MODE in
407: '=' )
408: if [ $# -ne $arg_NUMS ]; then
409: echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
410: echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
411: exit 1
412: fi
413: ;;
414: '+' )
415: if [ $# -lt $arg_NUMS ]; then
416: echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
417: echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
418: exit 1
419: fi
420: ;;
421: esac
422:
423: # establish a temporary file on request
424: if [ ".$gen_tmpfile" = .yes ]; then
425: # create (explicitly) secure temporary directory
426: if [ ".$TMPDIR" != . ]; then
427: tmpdir="$TMPDIR"
428: elif [ ".$TEMPDIR" != . ]; then
429: tmpdir="$TEMPDIR"
430: else
431: tmpdir="/tmp"
432: fi
433: tmpdir="$tmpdir/.shtool.$$"
434: ( umask 077
435: rm -rf "$tmpdir" >/dev/null 2>&1 || true
436: mkdir "$tmpdir" >/dev/null 2>&1
437: if [ $? -ne 0 ]; then
438: echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
439: exit 1
440: fi
441: )
442:
443: # create (implicitly) secure temporary file
444: tmpfile="$tmpdir/shtool.tmp"
445: touch "$tmpfile"
446: fi
447:
448: # utility function: map string to lower case
449: util_lower () {
450: echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
451: }
452:
453: # utility function: map string to upper case
454: util_upper () {
455: echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
456: }
457:
458: # cleanup procedure
459: shtool_exit () {
460: rc="$1"
461: if [ ".$gen_tmpfile" = .yes ]; then
462: rm -rf "$tmpdir" >/dev/null 2>&1 || true
463: fi
464: exit $rc
465: }
466:
467: ##
468: ## DISPATCH INTO SCRIPT BODY
469: ##
470:
471: case $tool in
472:
473: echo )
474: ##
475: ## echo -- Print string with optional construct expansion
476: ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
477: ##
478:
479: text="$*"
480:
481: # check for broken escape sequence expansion
482: seo=''
483: bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
484: if [ ".$bytes" != .3 ]; then
485: bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
486: if [ ".$bytes" = .3 ]; then
487: seo='-E'
488: fi
489: fi
490:
491: # check for existing -n option (to suppress newline)
492: minusn=''
493: bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
494: if [ ".$bytes" = .3 ]; then
495: minusn='-n'
496: fi
497:
498: # determine terminal bold sequence
499: term_bold=''
500: term_norm=''
501: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then
502: case $TERM in
503: # for the most important terminal types we directly know the sequences
504: xterm|xterm*|vt220|vt220*)
505: term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
506: term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
507: ;;
508: vt100|vt100*|cygwin)
509: term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
510: term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
511: ;;
512: # for all others, we try to use a possibly existing `tput' or `tcout' utility
513: * )
514: paths=`echo $PATH | sed -e 's/:/ /g'`
515: for tool in tput tcout; do
516: for dir in $paths; do
517: if [ -r "$dir/$tool" ]; then
518: for seq in bold md smso; do # 'smso' is last
519: bold="`$dir/$tool $seq 2>/dev/null`"
520: if [ ".$bold" != . ]; then
521: term_bold="$bold"
522: break
523: fi
524: done
525: if [ ".$term_bold" != . ]; then
526: for seq in sgr0 me rmso init reset; do # 'reset' is last
527: norm="`$dir/$tool $seq 2>/dev/null`"
528: if [ ".$norm" != . ]; then
529: term_norm="$norm"
530: break
531: fi
532: done
533: fi
534: break
535: fi
536: done
537: if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then
538: break;
539: fi
540: done
541: ;;
542: esac
543: if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then
544: echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
545: term_bold=''
546: term_norm=''
547: fi
548: fi
549:
550: # determine user name
551: username=''
552: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then
553: username="`(id -un) 2>/dev/null`"
554: if [ ".$username" = . ]; then
555: str="`(id) 2>/dev/null`"
556: if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
557: username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
558: fi
559: if [ ".$username" = . ]; then
560: username="$LOGNAME"
561: if [ ".$username" = . ]; then
562: username="$USER"
563: if [ ".$username" = . ]; then
564: username="`(whoami) 2>/dev/null |\
565: awk '{ printf("%s", $1); }'`"
566: if [ ".$username" = . ]; then
567: username="`(who am i) 2>/dev/null |\
568: awk '{ printf("%s", $1); }'`"
569: if [ ".$username" = . ]; then
570: username='unknown'
571: fi
572: fi
573: fi
574: fi
575: fi
576: fi
577: fi
578:
579: # determine user id
580: userid=''
581: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then
582: userid="`(id -u) 2>/dev/null`"
583: if [ ".$userid" = . ]; then
584: userid="`(id -u ${username}) 2>/dev/null`"
585: if [ ".$userid" = . ]; then
586: str="`(id) 2>/dev/null`"
587: if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
588: userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'`
589: fi
590: if [ ".$userid" = . ]; then
591: userid=`(getent passwd ${username}) 2>/dev/null | \
592: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
593: if [ ".$userid" = . ]; then
594: userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
595: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
596: if [ ".$userid" = . ]; then
597: userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
598: sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
599: if [ ".$userid" = . ]; then
600: userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
601: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
602: if [ ".$userid" = . ]; then
603: userid='?'
604: fi
605: fi
606: fi
607: fi
608: fi
609: fi
610: fi
611: fi
612:
613: # determine (primary) group id
614: groupid=''
615: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then
616: groupid="`(id -g ${username}) 2>/dev/null`"
617: if [ ".$groupid" = . ]; then
618: str="`(id) 2>/dev/null`"
619: if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
620: groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'`
621: fi
622: if [ ".$groupid" = . ]; then
623: groupid=`(getent passwd ${username}) 2>/dev/null | \
624: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
625: if [ ".$groupid" = . ]; then
626: groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
627: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
628: if [ ".$groupid" = . ]; then
629: groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
630: sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
631: if [ ".$groupid" = . ]; then
632: groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
633: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
634: if [ ".$groupid" = . ]; then
635: groupid='?'
636: fi
637: fi
638: fi
639: fi
640: fi
641: fi
642: fi
643:
644: # determine (primary) group name
645: groupname=''
646: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then
647: groupname="`(id -gn ${username}) 2>/dev/null`"
648: if [ ".$groupname" = . ]; then
649: str="`(id) 2>/dev/null`"
650: if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
651: groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
652: fi
653: if [ ".$groupname" = . ]; then
654: groupname=`(getent group) 2>/dev/null | \
655: grep "^[^:]*:[^:]*:${groupid}:" | \
656: sed -e 's/:.*$//'`
657: if [ ".$groupname" = . ]; then
658: groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
659: sed -e 's/:.*$//'`
660: if [ ".$groupname" = . ]; then
661: groupname=`(ypcat group; niscat group) 2>/dev/null | \
662: sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \
663: sed -e 's/:.*$//'`
664: if [ ".$groupname" = . ]; then
665: groupname=`(nidump group .) 2>/dev/null | \
666: grep "^[^:]*:[^:]*:${groupid}:" | \
667: sed -e 's/:.*$//'`
668: if [ ".$groupname" = . ]; then
669: groupname='?'
670: fi
671: fi
672: fi
673: fi
674: fi
675: fi
676: fi
677:
678: # determine host and domain name
679: hostname=''
680: domainname=''
681: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then
682: hostname="`(uname -n) 2>/dev/null |\
683: awk '{ printf("%s", $1); }'`"
684: if [ ".$hostname" = . ]; then
685: hostname="`(hostname) 2>/dev/null |\
686: awk '{ printf("%s", $1); }'`"
687: if [ ".$hostname" = . ]; then
688: hostname='unknown'
689: fi
690: fi
691: case $hostname in
692: *.* )
693: domainname=".`echo $hostname | cut -d. -f2-`"
694: hostname="`echo $hostname | cut -d. -f1`"
695: ;;
696: esac
697: fi
698: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then
699: if [ ".$domainname" = . ]; then
700: if [ -f /etc/resolv.conf ]; then
701: domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
702: sed -e 's/.*domain//' \
703: -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
704: -e 's/^\.//' -e 's/^/./' |\
705: awk '{ printf("%s", $1); }'`"
706: if [ ".$domainname" = . ]; then
707: domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
708: sed -e 's/.*search//' \
709: -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
710: -e 's/ .*//' -e 's/ .*//' \
711: -e 's/^\.//' -e 's/^/./' |\
712: awk '{ printf("%s", $1); }'`"
713: fi
714: fi
715: fi
716: fi
717:
718: # determine current time
719: time_day=''
720: time_month=''
721: time_year=''
722: time_monthname=''
723: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then
724: time_day=`date '+%d'`
725: time_month=`date '+%m'`
726: time_year=`date '+%Y' 2>/dev/null`
727: if [ ".$time_year" = . ]; then
728: time_year=`date '+%y'`
729: case $time_year in
730: [5-9][0-9]) time_year="19$time_year" ;;
731: [0-4][0-9]) time_year="20$time_year" ;;
732: esac
733: fi
734: case $time_month in
735: 1|01) time_monthname='Jan' ;;
736: 2|02) time_monthname='Feb' ;;
737: 3|03) time_monthname='Mar' ;;
738: 4|04) time_monthname='Apr' ;;
739: 5|05) time_monthname='May' ;;
740: 6|06) time_monthname='Jun' ;;
741: 7|07) time_monthname='Jul' ;;
742: 8|08) time_monthname='Aug' ;;
743: 9|09) time_monthname='Sep' ;;
744: 10) time_monthname='Oct' ;;
745: 11) time_monthname='Nov' ;;
746: 12) time_monthname='Dec' ;;
747: esac
748: fi
749:
750: # expand special ``%x'' constructs
751: if [ ".$opt_e" = .yes ]; then
752: text=`echo $seo "$text" |\
753: sed -e "s/%B/${term_bold}/g" \
754: -e "s/%b/${term_norm}/g" \
755: -e "s/%u/${username}/g" \
756: -e "s/%U/${userid}/g" \
757: -e "s/%g/${groupname}/g" \
758: -e "s/%G/${groupid}/g" \
759: -e "s/%h/${hostname}/g" \
760: -e "s/%d/${domainname}/g" \
761: -e "s/%D/${time_day}/g" \
762: -e "s/%M/${time_month}/g" \
763: -e "s/%Y/${time_year}/g" \
764: -e "s/%m/${time_monthname}/g" 2>/dev/null`
765: fi
766:
767: # create output
768: if [ .$opt_n = .no ]; then
769: echo $seo "$text"
770: else
771: # the harder part: echo -n is best, because
772: # awk may complain about some \xx sequences.
773: if [ ".$minusn" != . ]; then
774: echo $seo $minusn "$text"
775: else
776: echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
777: fi
778: fi
779:
780: shtool_exit 0
781: ;;
782:
783: install )
784: ##
785: ## install -- Install a program, script or datafile
786: ## Copyright (c) 1997-2008 Ralf S. Engelschall <rse@engelschall.com>
787: ##
788:
789: # special case: "shtool install -d <dir> [...]" internally
790: # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
791: if [ "$opt_d" = yes ]; then
792: cmd="$0 mkdir -f -p -m 755"
793: if [ ".$opt_o" != . ]; then
794: cmd="$cmd -o '$opt_o'"
795: fi
796: if [ ".$opt_g" != . ]; then
797: cmd="$cmd -g '$opt_g'"
798: fi
799: if [ ".$opt_v" = .yes ]; then
800: cmd="$cmd -v"
801: fi
802: if [ ".$opt_t" = .yes ]; then
803: cmd="$cmd -t"
804: fi
805: for dir in "$@"; do
806: eval "$cmd $dir" || shtool_exit $?
807: done
808: shtool_exit 0
809: fi
810:
811: # determine source(s) and destination
812: argc=$#
813: srcs=""
814: while [ $# -gt 1 ]; do
815: srcs="$srcs $1"
816: shift
817: done
818: dstpath="$1"
819:
820: # type check for destination
821: dstisdir=0
822: if [ -d $dstpath ]; then
823: dstpath=`echo "$dstpath" | sed -e 's:/$::'`
824: dstisdir=1
825: fi
826:
827: # consistency check for destination
828: if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
829: echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
830: shtool_exit 1
831: fi
832:
833: # iterate over all source(s)
834: for src in $srcs; do
835: dst=$dstpath
836:
837: # if destination is a directory, append the input filename
838: if [ $dstisdir = 1 ]; then
839: dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
840: dst="$dst/$dstfile"
841: fi
842:
843: # check for correct arguments
844: if [ ".$src" = ".$dst" ]; then
845: echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
846: continue
847: fi
848: if [ -d "$src" ]; then
849: echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
850: continue
851: fi
852:
853: # make a temp file name in the destination directory
854: dsttmp=`echo $dst |\
855: sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
856: -e "s;\$;/#INST@$$#;"`
857:
858: # verbosity
859: if [ ".$opt_v" = .yes ]; then
860: echo "$src -> $dst" 1>&2
861: fi
862:
863: # copy or move the file name to the temp name
864: # (because we might be not allowed to change the source)
865: if [ ".$opt_C" = .yes ]; then
866: opt_c=yes
867: fi
868: if [ ".$opt_c" = .yes ]; then
869: if [ ".$opt_t" = .yes ]; then
870: echo "cp $src $dsttmp" 1>&2
871: fi
872: cp "$src" "$dsttmp" || shtool_exit $?
873: else
874: if [ ".$opt_t" = .yes ]; then
875: echo "mv $src $dsttmp" 1>&2
876: fi
877: mv "$src" "$dsttmp" || shtool_exit $?
878: fi
879:
880: # adjust the target file
881: if [ ".$opt_e" != . ]; then
882: sed='sed'
883: OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
884: for e
885: do
886: sed="$sed -e '$e'"
887: done
888: cp "$dsttmp" "$dsttmp.old"
889: chmod u+w $dsttmp
890: eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
891: rm -f $dsttmp.old
892: fi
893: if [ ".$opt_s" = .yes ]; then
894: if [ ".$opt_t" = .yes ]; then
895: echo "strip $dsttmp" 1>&2
896: fi
897: strip $dsttmp || shtool_exit $?
898: fi
899: if [ ".$opt_o" != . ]; then
900: if [ ".$opt_t" = .yes ]; then
901: echo "chown $opt_o $dsttmp" 1>&2
902: fi
903: chown $opt_o $dsttmp || shtool_exit $?
904: fi
905: if [ ".$opt_g" != . ]; then
906: if [ ".$opt_t" = .yes ]; then
907: echo "chgrp $opt_g $dsttmp" 1>&2
908: fi
909: chgrp $opt_g $dsttmp || shtool_exit $?
910: fi
911: if [ ".$opt_m" != ".-" ]; then
912: if [ ".$opt_t" = .yes ]; then
913: echo "chmod $opt_m $dsttmp" 1>&2
914: fi
915: chmod $opt_m $dsttmp || shtool_exit $?
916: fi
917:
918: # determine whether to do a quick install
919: # (has to be done _after_ the strip was already done)
920: quick=no
921: if [ ".$opt_C" = .yes ]; then
922: if [ -r $dst ]; then
923: if cmp -s "$src" "$dst"; then
924: quick=yes
925: fi
926: fi
927: fi
928:
929: # finally, install the file to the real destination
930: if [ $quick = yes ]; then
931: if [ ".$opt_t" = .yes ]; then
932: echo "rm -f $dsttmp" 1>&2
933: fi
934: rm -f $dsttmp
935: else
936: if [ ".$opt_t" = .yes ]; then
937: echo "rm -f $dst && mv $dsttmp $dst" 1>&2
938: fi
939: rm -f $dst && mv $dsttmp $dst
940: fi
941: done
942:
943: shtool_exit 0
944: ;;
945:
946: mkdir )
947: ##
948: ## mkdir -- Make one or more directories
949: ## Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
950: ##
951:
952: errstatus=0
953: for p in ${1+"$@"}; do
954: # if the directory already exists...
955: if [ -d "$p" ]; then
956: if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
957: echo "$msgprefix:Error: directory already exists: $p" 1>&2
958: errstatus=1
959: break
960: else
961: continue
962: fi
963: fi
964: # if the directory has to be created...
965: if [ ".$opt_p" = .no ]; then
966: if [ ".$opt_t" = .yes ]; then
967: echo "mkdir $p" 1>&2
968: fi
969: mkdir $p || errstatus=$?
970: if [ ".$opt_o" != . ]; then
971: if [ ".$opt_t" = .yes ]; then
972: echo "chown $opt_o $p" 1>&2
973: fi
974: chown $opt_o $p || errstatus=$?
975: fi
976: if [ ".$opt_g" != . ]; then
977: if [ ".$opt_t" = .yes ]; then
978: echo "chgrp $opt_g $p" 1>&2
979: fi
980: chgrp $opt_g $p || errstatus=$?
981: fi
982: if [ ".$opt_m" != . ]; then
983: if [ ".$opt_t" = .yes ]; then
984: echo "chmod $opt_m $p" 1>&2
985: fi
986: chmod $opt_m $p || errstatus=$?
987: fi
988: else
989: # the smart situation
990: set fnord `echo ":$p" |\
991: sed -e 's/^:\//%/' \
992: -e 's/^://' \
993: -e 's/\// /g' \
994: -e 's/^%/\//'`
995: shift
996: pathcomp=''
997: for d in ${1+"$@"}; do
998: pathcomp="$pathcomp$d"
999: case "$pathcomp" in
1000: -* ) pathcomp="./$pathcomp" ;;
1001: esac
1002: if [ ! -d "$pathcomp" ]; then
1003: if [ ".$opt_t" = .yes ]; then
1004: echo "mkdir $pathcomp" 1>&2
1005: fi
1006: mkdir $pathcomp || errstatus=$?
1007: if [ ".$opt_o" != . ]; then
1008: if [ ".$opt_t" = .yes ]; then
1009: echo "chown $opt_o $pathcomp" 1>&2
1010: fi
1011: chown $opt_o $pathcomp || errstatus=$?
1012: fi
1013: if [ ".$opt_g" != . ]; then
1014: if [ ".$opt_t" = .yes ]; then
1015: echo "chgrp $opt_g $pathcomp" 1>&2
1016: fi
1017: chgrp $opt_g $pathcomp || errstatus=$?
1018: fi
1019: if [ ".$opt_m" != . ]; then
1020: if [ ".$opt_t" = .yes ]; then
1021: echo "chmod $opt_m $pathcomp" 1>&2
1022: fi
1023: chmod $opt_m $pathcomp || errstatus=$?
1024: fi
1025: fi
1026: pathcomp="$pathcomp/"
1027: done
1028: fi
1029: done
1030:
1031: shtool_exit $errstatus
1032: ;;
1033:
1034: platform )
1035: ##
1036: ## platform -- Platform Identification Utility
1037: ## Copyright (c) 2003-2008 Ralf S. Engelschall <rse@engelschall.com>
1038: ##
1039:
1040: # option post-processing
1041: if [ ".$opt_t" != . ]; then
1042: case "$opt_t" in
1043: binary )
1044: # binary package id (OpenPKG RPM)
1045: opt_F="%<ap>-%<sp>"
1046: opt_L=yes
1047: opt_S=""
1048: opt_C="+"
1049: ;;
1050: build )
1051: # build time checking (OpenPKG RPM)
1052: opt_F="%<at>-%<st>"
1053: opt_L=yes
1054: opt_S=""
1055: opt_C="+"
1056: ;;
1057: gnu )
1058: # GNU config.guess style <arch>-<vendor>-<os><osversion>
1059: opt_F="%<at>-unknown-%<st>"
1060: opt_L=yes
1061: opt_S=""
1062: opt_C="+"
1063: ;;
1064: web )
1065: # non-whitespace HTTP Server-header id
1066: opt_F="%<sp>-%<ap>"
1067: opt_S="/"
1068: opt_C="+"
1069: ;;
1070: summary)
1071: # human readable verbose summary information
1072: opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
1073: opt_S=" "
1074: opt_C="/"
1075: ;;
1076: all-in-one )
1077: # full-table all-in-one information
1078: opt_F=""
1079: opt_F="${opt_F}concise architecture class: %<ac>\\n"
1080: opt_F="${opt_F}regular architecture class: %{ac}\\n"
1081: opt_F="${opt_F}verbose architecture class: %[ac]\\n"
1082: opt_F="${opt_F}concise architecture product: %<ap>\\n"
1083: opt_F="${opt_F}regular architecture product: %{ap}\\n"
1084: opt_F="${opt_F}verbose architecture product: %[ap]\\n"
1085: opt_F="${opt_F}concise architecture technology: %<at>\\n"
1086: opt_F="${opt_F}regular architecture technology: %{at}\\n"
1087: opt_F="${opt_F}verbose architecture technology: %[at]\\n"
1088: opt_F="${opt_F}concise system class: %<sc>\\n"
1089: opt_F="${opt_F}regular system class: %{sc}\\n"
1090: opt_F="${opt_F}verbose system class: %[sc]\\n"
1091: opt_F="${opt_F}concise system product: %<sp>\\n"
1092: opt_F="${opt_F}regular system product: %{sp}\\n"
1093: opt_F="${opt_F}verbose system product: %[sp]\\n"
1094: opt_F="${opt_F}concise system technology: %<st>\\n"
1095: opt_F="${opt_F}regular system technology: %{st}\\n"
1096: opt_F="${opt_F}verbose system technology: %[st]"
1097: ;;
1098: * )
1099: echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
1100: exit 1
1101: ;;
1102: esac
1103: fi
1104:
1105: # assemble initial platform information
1106: UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
1107: UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
1108: UNAME_MACHINE='unknown'
1109: UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\
1110: UNAME_SYSTEM='unknown'
1111: UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
1112: UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
1113: UNAME_RELEASE='unknown'
1114:
1115: UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
1116:
1117: AC=""; AP=""; AT=""
1118: SC=""; SP=""; ST=""
1119:
1120: # dispatch into platform specific sections
1121: case "${UNAME}" in
1122:
1123: # FreeBSD
1124: *:FreeBSD:* )
1125: # determine architecture
1126: AC="${UNAME_MACHINE}"
1127: case "${AC}" in
1128: i386 ) AC="iX86" ;;
1129: esac
1130: AP="${AC}"
1131: AT="${AP}"
1132: if [ ".${AT}" = ".iX86" ]; then
1133: case "`(/sbin/sysctl -n hw.model) 2>&1`" in
1134: *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
1135: *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
1136: *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
1137: esac
1138: fi
1139: # determine system
1140: r=`echo "${UNAME_RELEASE}" |\
1141: sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
1142: ST="FreeBSD ${r}"
1143: SP="${ST}"
1144: case "${r}" in
1145: 1.* ) SC="4.3BSD" ;;
1146: * ) SC="4.4BSD" ;;
1147: esac
1148: ;;
1149:
1150: # NetBSD
1151: *:NetBSD:* )
1152: # determine architecture
1153: AT="${UNAME_MACHINE}"
1154: AP="${AT}"
1155: case "${AP}" in
1156: i[3-6]86 ) AP="iX86" ;;
1157: esac
1158: AC="${AP}"
1159: # determine system
1160: r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1161: ST="NetBSD ${r}"
1162: SP="${ST}"
1163: case "${r}" in
1164: 0.* ) SC="4.3BSD" ;;
1165: * ) SC="4.4BSD" ;;
1166: esac
1167: ;;
1168:
1169: # OpenBSD
1170: *:OpenBSD:* )
1171: # determine architecture
1172: AT="${UNAME_MACHINE}"
1173: AP="${AT}"
1174: case "${AP}" in
1175: i[3-6]86 ) AP="iX86" ;;
1176: esac
1177: AC="${AP}"
1178: # determine system
1179: r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1180: ST="OpenBSD ${r}"
1181: SP="${ST}"
1182: SC="4.4BSD"
1183: ;;
1184:
1185: # DragonFly BSD
1186: *:DragonFly:* )
1187: # determine architecture
1188: AT="${UNAME_MACHINE}"
1189: AP="${AT}"
1190: case "${AP}" in
1191: i[3-6]86 ) AP="iX86" ;;
1192: esac
1193: AC="${AP}"
1194: # determine system
1195: r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1196: ST="DragonFly ${r}"
1197: SP="${ST}"
1198: SC="4.4BSD"
1199: ;;
1200:
1201: # GNU/Linux
1202: *:Linux:* )
1203: # determine architecture
1204: AT="${UNAME_MACHINE}"
1205: case "${AT}" in
1206: ia64 ) AT="IA64" ;;
1207: x86_64 ) AT='AMD64' ;;
1208: parisc ) AT="HPPA32" ;;
1209: parisc64 ) AT="HPPA64" ;;
1210: esac
1211: AP="${AT}"
1212: case "${AP}" in
1213: i[3-6]86 ) AP='iX86' ;;
1214: esac
1215: AC="${AP}"
1216: # determine system
1217: v_kern=`echo "${UNAME_RELEASE}" |\
1218: sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
1219: v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
1220: env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
1221: ST="GNU/<Linux >${v_libc}/<${v_kern}>"
1222: if [ -f /etc/lsb-release ]; then
1223: eval `( . /etc/lsb-release
1224: echo "SC=\"LSB${LSB_VERSION}\""
1225: if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
1226: echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
1227: fi
1228: ) 2>/dev/null`
1229: fi
1230: if [ ".$SP" = . ]; then
1231: for tagfile in x \
1232: `cd /etc && \
1233: /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
1234: sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
1235: echo redhat-release lsb-release`
1236: do
1237: [ ".${tagfile}" = .x ] && continue
1238: [ ! -f "/etc/${tagfile}" ] && continue
1239: n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
1240: v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
1241: sed -e 's/^/#/' \
1242: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1243: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1244: -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1245: -e 's/^#.*$//'`
1246: case "`util_lower ${n}`" in
1247: redhat )
1248: if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
1249: n="<R>ed <H>at <E>nterprise <L>inux"
1250: else
1251: n="<R>ed <H>at <L>inux"
1252: fi
1253: ;;
1254: debian ) n="Debian[ GNU/Linux]" ;;
1255: ubuntu ) n="Ubuntu[ GNU/Linux]" ;;
1256: fedora ) n="<Fedora> Core[ GNU/Linux]" ;;
1257: suse ) n="[Novell ]SUSE[ Linux]" ;;
1258: mandrake*|mandriva ) n="Mandriva[ Linux]" ;;
1259: gentoo ) n="Gentoo[ GNU/Linux]" ;;
1260: slackware ) n="Slackware[ Linux]" ;;
1261: turbolinux ) n="TurboLinux" ;;
1262: unitedlinux ) n="UnitedLinux" ;;
1263: * ) n="${n}[ GNU/Linux]" ;;
1264: esac
1265: case "$n" in
1266: *"<"*">"* ) SP="$n <$v>" ;;
1267: * ) SP="$n $v" ;;
1268: esac
1269: break
1270: done
1271: fi
1272: [ ".$SP" = . ] && SP="${ST}"
1273: [ ".$SC" = . ] && SC="LSB"
1274: ;;
1275:
1276: # Sun Solaris
1277: *:SunOS:* )
1278: # determine architecture
1279: AT="${UNAME_MACHINE}"
1280: case "${AT}" in
1281: i86pc )
1282: AT="iX86"
1283: case "`(/bin/isainfo -k) 2>&1`" in
1284: amd64 ) AT="AMD64" ;;
1285: esac
1286: ;;
1287: esac
1288: AP="${AT}"
1289: case "${AP}" in
1290: sun4[cdm] ) AP="SPARC32" ;;
1291: sun4[uv] ) AP="SPARC64" ;;
1292: sun4* ) AP="SPARC" ;;
1293: esac
1294: AC="${AP}"
1295: case "${AC}" in
1296: SPARC* ) AC="SPARC" ;;
1297: esac
1298: # determine system
1299: ST="[Sun ]SunOS ${UNAME_RELEASE}"
1300: v=`echo "${UNAME_RELEASE}" |\
1301: sed -e 's;^4\.;1.;' \
1302: -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
1303: -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
1304: SP="[Sun ]Solaris $v"
1305: case "${UNAME_RELEASE}" in
1306: 4.* ) SC="4.3BSD" ;;
1307: 5.* ) SC="SVR4" ;;
1308: esac
1309: ;;
1310:
1311: # SCO UnixWare
1312: *:UnixWare:* )
1313: # determine architecture
1314: AT="${UNAME_MACHINE}"
1315: case "${AT}" in
1316: i[3-6]86 | ix86at ) AT="iX86" ;;
1317: esac
1318: AP="${AT}"
1319: # determine system
1320: v=`/sbin/uname -v`
1321: ST="[SCO ]UnixWare ${v}"
1322: SP="${ST}"
1323: SC="SVR${UNAME_RELEASE}"
1324: ;;
1325:
1326: # QNX
1327: *:QNX:* )
1328: # determine architecture
1329: AT="${UNAME_MACHINE}"
1330: case "${AT}" in
1331: x86pc ) AT="iX86" ;;
1332: esac
1333: AP="${AT}"
1334: # determine system
1335: v="${UNAME_RELEASE}"
1336: ST="QNX[ Neutrino RTOS] ${v}"
1337: v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
1338: SP="QNX[ Neutrino RTOS] ${v}"
1339: SC="QNX"
1340: ;;
1341:
1342: # SGI IRIX
1343: *:IRIX*:* )
1344: # determine architecture
1345: AT="${UNAME_MACHINE}"
1346: AP="${AT}"
1347: case "${AP}:${UNAME_SYSTEM}" in
1348: IP*:IRIX64 ) AP="MIPS64" ;;
1349: IP*:* ) AP="MIPS" ;;
1350: esac
1351: AC="${AP}"
1352: # determine system
1353: v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
1354: ST="[SGI ]IRIX ${v}"
1355: v="${UNAME_RELEASE}"
1356: SP="[SGI ]IRIX ${v}"
1357: SC="4.2BSD/SVR3"
1358: ;;
1359:
1360: # HP HP-UX
1361: *:HP-UX:* )
1362: # determine architecture
1363: AT="${UNAME_MACHINE}"
1364: case "${AT}" in
1365: ia64 ) AT="IA64" ;;
1366: 9000/[34]?? ) AT=M68K ;;
1367: 9000/[678][0-9][0-9])
1368: sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
1369: sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
1370: case "${sc_cpu_version}" in
1371: 523 ) AT="HPPA1.0" ;;
1372: 528 ) AT="HPPA1.1" ;;
1373: 532 ) AT="HPPA2.0"
1374: case "${sc_kernel_bits}" in
1375: 32 ) AT="${AT}n" ;;
1376: 64 ) AT="${AT}w" ;;
1377: esac
1378: ;;
1379: esac
1380: ;;
1381: esac
1382: AP="${AT}"
1383: case "${AP}" in
1384: HPPA* ) AP="HPPA" ;;
1385: esac
1386: AC="${AP}"
1387: # determine system
1388: v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
1389: ST="[HP ]<HP>-<UX ${v}>"
1390: SP="${ST}"
1391: case "${v}" in
1392: 10.* ) SC="SVR4.2" ;;
1393: [7-9]* ) SC="SVR4" ;;
1394: esac
1395: ;;
1396:
1397: # HP Tru64 (OSF1)
1398: *:OSF1:* )
1399: # determine architecture
1400: AP="${UNAME_MACHINE}"
1401: case "${AP}" in
1402: alpha ) AP="Alpha" ;;
1403: esac
1404: alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
1405: sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
1406: AT="${AP}${alpha_type}"
1407: AC="${AP}"
1408: # determine system
1409: v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
1410: ST="[HP ]Tru64 ${v}"
1411: SP="${ST}"
1412: SC="OSF1"
1413: ;;
1414:
1415: # IBM AIX
1416: *:AIX:* )
1417: # determine architecture
1418: cpu_arch=RS6000
1419: if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
1420: cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
1421: if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
1422: cpu_arch=PPC
1423: fi
1424: elif [ -d /QOpenSys ]; then
1425: # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
1426: cpu_arch=PPC
1427: fi
1428: if [ -x /usr/bin/oslevel ]; then
1429: os_level=`/usr/bin/oslevel`
1430: else
1431: os_level="`uname -v`.`uname -r`"
1432: fi
1433: os_level=`echo "${os_level}" |\
1434: sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
1435: -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
1436: AT="${cpu_arch}"
1437: AP="${AT}"
1438: AC="${AP}"
1439: # determine system
1440: ST="[IBM ]<AIX >${os_level}"
1441: SP="${ST}"
1442: case "${os_level}" in
1443: [12]* ) SC="SVR2" ;;
1444: * ) SC="SVR4" ;;
1445: esac
1446: ;;
1447:
1448: # Apple Mac OS X (Darwin)
1449: *:Darwin:* )
1450: # determine architecture
1451: AT="`uname -p`"
1452: case "${AT}" in
1453: powerpc ) AT="PPC" ;;
1454: esac
1455: AP="${AT}"
1456: case "${AP}" in
1457: i?86 ) AP="iX86" ;;
1458: esac
1459: AC="${AP}"
1460: # determine system
1461: unset v1; unset v2; unset v3
1462: eval `echo "${UNAME_RELEASE}" |\
1463: sed -e 's/^/#/' \
1464: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1465: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1466: -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1467: -e 's/^#.*$/v1="0"/'`
1468: ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
1469: SP="$ST"
1470: v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
1471: if [ ".$v" = . ]; then
1472: for name in System Server; do
1473: if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
1474: v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
1475: [ ".$v" != . ] && break
1476: fi
1477: done
1478: fi
1479: if [ ".$v" != . ]; then
1480: unset v1; unset v2; unset v3
1481: eval `echo "${v}" |\
1482: sed -e 's/^/#/' \
1483: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1484: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1485: -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1486: -e 's/^#.*$/v1="0"/'`
1487: SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
1488: fi
1489: SC="4.4BSD/Mach3.0"
1490: ;;
1491:
1492: # Windows/Cygwin
1493: *:CYGWIN*:* )
1494: # determine architecture
1495: AT="`uname -m`"
1496: AP="${AT}"
1497: case "${AP}" in
1498: i?86 ) AP="iX86" ;;
1499: esac
1500: AC="${AP}"
1501: # determine system
1502: unset v1; unset v2; unset v3
1503: eval `echo "${UNAME_RELEASE}" |\
1504: sed -e 's/^/#/' \
1505: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
1506: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
1507: -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
1508: -e 's/^#.*$/v1="0"/'`
1509: ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}"
1510: SP="$ST"
1511: SC="Windows"
1512: v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\
1513: sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'`
1514: case "$v" in
1515: 4.0 ) SC="$SC[ NT]" ;;
1516: 5.0 ) SC="$SC[ 2000]" ;;
1517: 5.1 ) SC="$SC[ XP]" ;;
1518: 6.0 ) SC="$SC[ Vista]" ;;
1519: esac
1520: ;;
1521:
1522: # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
1523: # *:XXX:* )
1524: # ...
1525: # ;;
1526:
1527: # ...A STILL UNKNOWN PLATFORM...
1528: * )
1529: AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
1530: AP="${AT}"
1531: AC="${AP}"
1532: v=`echo "${UNAME_RELEASE}" |\
1533: sed -e 's/^/#/' \
1534: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1535: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1536: -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1537: -e 's/^#.*$/?/'`
1538: ST="${UNAME_SYSTEM} ${v}"
1539: SP="${ST}"
1540: SC="${SP}"
1541: ;;
1542:
1543: esac
1544:
1545: # provide fallback values
1546: [ ".$AT" = . ] && AT="${AP:-${AC}}"
1547: [ ".$AP" = . ] && AP="${AT:-${AC}}"
1548: [ ".$AC" = . ] && AC="${AP:-${AT}}"
1549: [ ".$ST" = . ] && ST="${SP:-${SC}}"
1550: [ ".$SP" = . ] && SP="${ST:-${SC}}"
1551: [ ".$SC" = . ] && SC="${SP:-${ST}}"
1552:
1553: # support explicit enforced verbose/concise output
1554: if [ ".$opt_v" = .yes ]; then
1555: opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
1556: elif [ ".$opt_c" = .yes ]; then
1557: opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
1558: fi
1559:
1560: # provide verbose and concise variants
1561: AC_V=""; AC_N=""; AC_C=""
1562: AP_V=""; AP_N=""; AP_C=""
1563: AT_V=""; AT_N=""; AT_C=""
1564: SC_V=""; SC_N=""; SC_C=""
1565: SP_V=""; SP_N=""; SP_C=""
1566: ST_V=""; ST_N=""; ST_C=""
1567: for var_lc in at ap ac st sp sc; do
1568: case "$opt_F" in
1569: *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
1570: var_uc=`util_upper "$var_lc"`
1571: eval "val=\"\$${var_uc}\""
1572: val_V=""; val_N=""; val_C=""
1573: case "$opt_F" in
1574: *"%[${var_lc}]"* )
1575: val_V=`echo ":$val" | \
1576: sed -e 's/^://' \
1577: -e 's;\[\([^]]*\)\];\1;g' \
1578: -e 's;<\([^>]*\)>;\1;g' \
1579: -e "s; ;§§;g" \
1580: -e "s;/;%%;g" \
1581: -e "s;§§;${opt_S};g" \
1582: -e "s;%%;${opt_C};g"`
1583: eval "${var_uc}_V=\"\${val_V}\""
1584: ;;
1585: esac
1586: case "$opt_F" in
1587: *"%{${var_lc}}"* | *"%${var_lc}"* )
1588: val_N=`echo ":$val" | \
1589: sed -e 's/^://' \
1590: -e 's;\[\([^]]*\)\];;g' \
1591: -e 's;<\([^>]*\)>;\1;g' \
1592: -e "s; ;§§;g" \
1593: -e "s;/;%%;g" \
1594: -e "s;§§;${opt_S};g" \
1595: -e "s;%%;${opt_C};g"`
1596: eval "${var_uc}_N=\"\${val_N}\""
1597: ;;
1598: esac
1599: case "$opt_F" in
1600: *"%<${var_lc}>"* )
1601: val_C=`echo ":$val" | \
1602: sed -e 's/^://' \
1603: -e 's;\[\([^]]*\)\];;g' \
1604: -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
1605: -e "s; ;§§;g" \
1606: -e "s;/;%%;g" \
1607: -e "s;§§;${opt_S};g" \
1608: -e "s;%%;${opt_C};g"`
1609: eval "${var_uc}_C=\"\${val_C}\""
1610: ;;
1611: esac
1612: ;;
1613: esac
1614: done
1615:
1616: # create output string
1617: output=`echo ":$opt_F" |\
1618: sed -e "s/^://" \
1619: -e "s;%\\[ac\\];${AC_V};g" \
1620: -e "s;%{ac};${AC_N};g" \
1621: -e "s;%ac;${AC_N};g" \
1622: -e "s;%<ac>;${AC_C};g" \
1623: -e "s;%\\[ap\\];${AP_V};g" \
1624: -e "s;%{ap};${AP_N};g" \
1625: -e "s;%ap;${AP_N};g" \
1626: -e "s;%<ap>;${AP_C};g" \
1627: -e "s;%\\[at\\];${AT_V};g" \
1628: -e "s;%{at};${AT_N};g" \
1629: -e "s;%at;${AT_N};g" \
1630: -e "s;%<at>;${AT_C};g" \
1631: -e "s;%\\[sc\\];${SC_V};g" \
1632: -e "s;%{sc};${SC_N};g" \
1633: -e "s;%sc;${SC_N};g" \
1634: -e "s;%<sc>;${SC_C};g" \
1635: -e "s;%\\[sp\\];${SP_V};g" \
1636: -e "s;%{sp};${SP_N};g" \
1637: -e "s;%sp;${SP_N};g" \
1638: -e "s;%<sp>;${SP_C};g" \
1639: -e "s;%\\[st\\];${ST_V};g" \
1640: -e "s;%{st};${ST_N};g" \
1641: -e "s;%st;${ST_N};g" \
1642: -e "s;%<st>;${ST_C};g" \
1643: -e 's/\\\\n/^/g' |\
1644: tr '^' '\012'`
1645:
1646: # support lower/upper-case mapping
1647: if [ ".$opt_L" = .yes ]; then
1648: output=`util_lower "$output"`
1649: elif [ ".$opt_U" = .yes ]; then
1650: output=`util_upper "$output"`
1651: fi
1652:
1653: # display output string
1654: if [ ".$opt_n" = .yes ]; then
1655: echo . | awk '{ printf("%s", output); }' output="$output"
1656: else
1657: echo "$output"
1658: fi
1659:
1660: shtool_exit 0
1661: ;;
1662:
1663: path )
1664: ##
1665: ## path -- Deal with program paths
1666: ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
1667: ##
1668:
1669: namelist="$*"
1670:
1671: # check whether the test command supports the -x option
1672: if [ -x /bin/sh ] 2>/dev/null; then
1673: minusx="-x"
1674: else
1675: minusx="-r"
1676: fi
1677:
1678: # split path string
1679: paths="`echo $opt_p |\
1680: sed -e 's/^:/.:/' \
1681: -e 's/::/:.:/g' \
1682: -e 's/:$/:./' \
1683: -e 's/:/ /g'`"
1684:
1685: # SPECIAL REQUEST
1686: # translate forward to reverse path
1687: if [ ".$opt_r" = .yes ]; then
1688: if [ "x$namelist" = "x." ]; then
1689: rp='.'
1690: else
1691: rp=''
1692: for pe in `IFS="$IFS/"; echo $namelist`; do
1693: rp="../$rp"
1694: done
1695: fi
1696: echo $rp | sed -e 's:/$::'
1697: shtool_exit 0
1698: fi
1699:
1700: # SPECIAL REQUEST
1701: # strip out directory or base name
1702: if [ ".$opt_d" = .yes ]; then
1703: echo "$namelist" |\
1704: sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
1705: shtool_exit 0
1706: fi
1707: if [ ".$opt_b" = .yes ]; then
1708: echo "$namelist" |\
1709: sed -e 's;.*/\([^/]*\)$;\1;'
1710: shtool_exit 0
1711: fi
1712:
1713: # MAGIC SITUATION
1714: # Perl Interpreter (perl)
1715: if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
1716: rm -f $tmpfile >/dev/null 2>&1
1717: touch $tmpfile
1718: found=0
1719: pc=99
1720: for dir in $paths; do
1721: dir=`echo $dir | sed -e 's;/*$;;'`
1722: nc=99
1723: for name in perl perl5 miniperl; do
1724: if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
1725: perl="$dir/$name"
1726: pv=`$perl -e 'printf("%.3f", $]);'`
1727: echo "$pv:$pc:$nc:$perl" >>$tmpfile
1728: found=1
1729: fi
1730: nc=`expr $nc - 1`
1731: done
1732: pc=`expr $pc - 1`
1733: done
1734: if [ $found = 1 ]; then
1735: perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
1736: rm -f $tmpfile >/dev/null 2>&1
1737: echo "$perl"
1738: shtool_exit 0
1739: fi
1740: rm -f $tmpfile >/dev/null 2>&1
1741: shtool_exit 1
1742: fi
1743:
1744: # MAGIC SITUATION
1745: # C pre-processor (cpp)
1746: if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
1747: echo >$tmpfile.c "#include <assert.h>"
1748: echo >>$tmpfile.c "Syntax Error"
1749: # 1. try the standard cc -E approach
1750: cpp="${CC-cc} -E"
1751: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1752: my_error=`grep -v '^ *+' $tmpfile.out`
1753: if [ ".$my_error" != . ]; then
1754: # 2. try the cc -E approach and GCC's -traditional-ccp option
1755: cpp="${CC-cc} -E -traditional-cpp"
1756: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1757: my_error=`grep -v '^ *+' $tmpfile.out`
1758: if [ ".$my_error" != . ]; then
1759: # 3. try a standalone cpp command in path and lib dirs
1760: for path in $paths /lib /usr/lib /usr/local/lib; do
1761: path=`echo $path | sed -e 's;/*$;;'`
1762: if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
1763: cpp="$path/cpp"
1764: break
1765: fi
1766: done
1767: if [ ".$cpp" != . ]; then
1768: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1769: my_error=`grep -v '^ *+' $tmpfile.out`
1770: if [ ".$my_error" != . ]; then
1771: # ok, we gave up...
1772: cpp=''
1773: fi
1774: fi
1775: fi
1776: fi
1777: rm -f $tmpfile >/dev/null 2>&1
1778: rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
1779: if [ ".$cpp" != . ]; then
1780: echo "$cpp"
1781: shtool_exit 0
1782: fi
1783: shtool_exit 1
1784: fi
1785:
1786: # STANDARD SITUATION
1787: # iterate over names
1788: for name in $namelist; do
1789: # iterate over paths
1790: for path in $paths; do
1791: path=`echo $path | sed -e 's;/*$;;'`
1792: if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
1793: if [ ".$opt_s" != .yes ]; then
1794: echo "$path/$name"
1795: fi
1796: shtool_exit 0
1797: fi
1798: done
1799: done
1800:
1801: shtool_exit 1
1802: ;;
1803:
1804: esac
1805:
1806: shtool_exit 0
1807:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>