3 ## GNU shtool -- The GNU Portable Shell Tool
4 ## Copyright (c) 1994-2006 Ralf S. Engelschall <rse@engelschall.com>
6 ## See http://www.gnu.org/software/shtool/ for more information.
7 ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
9 ## Version: 2.0.6 (19-Apr-2006)
10 ## Contents: 5/19 available modules
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.
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.
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>.
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.
38 ## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
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
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
64 # maximum Bourne-Shell compatibility
65 if [ ".$ZSH_VERSION" != .
] && (emulate sh
) >/dev
/null
2>&1; then
69 alias -g '${1+"$@"}'='"$@"'
70 elif [ ".$BASH_VERSION" != .
] && (set -o posix
) >/dev
/null
2>&1; then
75 # maximum independence of NLS nuisances
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 \
81 if (set +x
; test -z "`(eval $var=C; export $var) 2>&1`"); then
82 eval $var=C
; export $var
88 # initial command line handling
90 echo "$0:Error: invalid command line" 1>&2
91 echo "$0:Hint: run \`$0 -h' for usage" 1>&2
94 if [ ".$1" = ".-h" ] ||
[ ".$1" = ".--help" ]; then
95 echo "This is GNU shtool, version 2.0.6 (19-Apr-2006)"
96 echo 'Copyright (c) 1994-2006 Ralf S. Engelschall <rse@engelschall.com>'
97 echo 'Report bugs to <bug-shtool@gnu.org>'
99 echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
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'
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>'
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> ...]'
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>]'
149 echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
151 echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
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>'
163 if [ ".$1" = ".-v" ] ||
[ ".$1" = ".--version" ]; then
164 echo "GNU shtool 2.0.6 (19-Apr-2006)"
167 if [ ".$1" = ".-r" ] ||
[ ".$1" = ".--recreate" ]; then
168 shtoolize
-oshtool echo install mkdir platform path
171 if [ ".$1" = ".-d" ] ||
[ ".$1" = ".--debug" ]; then
175 name
=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
177 echo|
install|mkdir|platform|path
)
178 # implicit tool command selection
182 # explicit tool command selection
192 ## DISPATCH INTO SCRIPT PROLOG
198 str_usage
="[-n|--newline] [-e|--expand] [<string> ...]"
201 opt_alias
="n:newline,e:expand"
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>"
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"
224 str_usage
="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
226 opt_spec
="t.f.p.m:o:g:"
227 opt_alias
="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
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]"
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})"
255 str_usage
="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
258 opt_spec
="s.r.d.b.m.p:"
259 opt_alias
="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
268 echo "$0:Error: unknown option \`$tool'" 2>&1
269 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
273 echo "$0:Error: unknown command \`$tool'" 2>&1
274 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
280 ## COMMON UTILITY CODE
283 # commonly used ASCII values
288 # determine name of tool
289 if [ ".$tool" != .
]; then
290 # used inside shtool script
292 toolcmdhelp
="shtool $tool"
293 msgprefix
="shtool:$tool"
295 # used as standalone script
298 msgprefix
="$str_tool"
301 # parse argument specification string
302 eval `echo $arg_spec |\
303 sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
305 # parse option specification string
306 eval `echo h.$opt_spec |\
307 sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
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'`
313 # interate over argument line
315 while [ $# -gt 0 ]; do
316 # special option stops processing
317 if [ ".$1" = ".--" ]; then
322 # determine option and argument
324 if [ ".$opt_PREV" != .
]; then
325 # merge previous seen option with argument
331 # split argument into option and argument
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}}"
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}}"
347 sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
348 -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
351 opt_OPT
=`echo "x$1" | cut -c3-`
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
376 eval "opt_${opt_OPT}=yes"
379 # option with argument (multiple occurances override)
380 eval "opt_${opt_OPT}=\"\$opt_ARG\""
383 # option with argument (multiple occurances append)
384 eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
387 echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
388 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
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
399 # process help option
400 if [ ".$opt_h" = .
yes ]; then
401 echo "Usage: $toolcmdhelp $str_usage"
405 # complain about incorrect number of arguments
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
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
423 # establish a temporary file on request
424 if [ ".$gen_tmpfile" = .
yes ]; then
425 # create (explicitly) secure temporary directory
426 if [ ".$TMPDIR" != .
]; then
428 elif [ ".$TEMPDIR" != .
]; then
433 tmpdir
="$tmpdir/.shtool.$$"
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
443 # create (implicitly) secure temporary file
444 tmpfile
="$tmpdir/shtool.tmp"
448 # utility function: map string to lower case
450 echo "$1" |
tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
453 # utility function: map string to upper case
455 echo "$1" |
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
461 if [ ".$gen_tmpfile" = .
yes ]; then
462 rm -rf "$tmpdir" >/dev
/null
2>&1 || true
468 ## DISPATCH INTO SCRIPT BODY
475 ## echo -- Print string with optional construct expansion
476 ## Copyright (c) 1998-2006 Ralf S. Engelschall <rse@engelschall.com>
481 # check for broken escape sequence expansion
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
491 # check for existing -n option (to suppress newline)
493 bytes
=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
494 if [ ".$bytes" = .3 ]; then
498 # determine terminal bold sequence
501 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%[Bb]'`" != .
]; then
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`
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`
512 # for all others, we try to use a possibly existing `tput' or `tcout' utility
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
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
537 if [ ".$term_bold" != .
] && [ ".$term_norm" != .
]; then
543 if [ ".$term_bold" = .
] ||
[ ".$term_norm" = .
]; then
544 echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
550 # determine user name
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/).*$//'`
559 if [ ".$username" = .
]; then
561 if [ ".$username" = .
]; then
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
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/(.*$//'`
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
=`(ypcat passwd) 2>/dev/null |
598 grep "^${username}:" | \
599 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
600 if [ ".$userid" = .
]; then
610 # determine (primary) group id
612 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%[gG]'`" != .
]; then
613 groupid
="`(id -g ${username}) 2>/dev/null`"
614 if [ ".$groupid" = .
]; then
615 str
="`(id) 2>/dev/null`"
616 if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != .
]; then
617 groupid
=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'`
619 if [ ".$groupid" = .
]; then
620 groupid
=`(getent passwd ${username}) 2>/dev/null | \
621 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
622 if [ ".$groupid" = .
]; then
623 groupid
=`grep "^${username}:" /etc/passwd 2>/dev/null | \
624 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
625 if [ ".$groupid" = .
]; then
626 groupid
=`(ypcat passwd) 2>/dev/null | grep "^${username}:" | \
627 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
628 if [ ".$groupid" = .
]; then
637 # determine (primary) group name
639 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%g'`" != .
]; then
640 groupname
="`(id -gn ${username}) 2>/dev/null`"
641 if [ ".$groupname" = .
]; then
642 str
="`(id) 2>/dev/null`"
643 if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != .
]; then
644 groupname
=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
646 if [ ".$groupname" = .
]; then
647 groupname
=`(getent group) 2>/dev/null | \
648 grep "^[^:]*:[^:]*:${groupid}:" | \
650 if [ ".$groupname" = .
]; then
651 groupname
=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
653 if [ ".$groupname" = .
]; then
654 groupname
=`(ypcat group) 2>/dev/null | \
655 grep "^[^:]*:[^:]*:${groupid}:" | \
657 if [ ".$groupname" = .
]; then
666 # determine host and domain name
669 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%h'`" != .
]; then
670 hostname
="`(uname -n) 2>/dev/null |\
671 awk '{ printf("%s
", $1); }'`"
672 if [ ".$hostname" = .
]; then
673 hostname
="`(hostname) 2>/dev/null |\
674 awk '{ printf("%s
", $1); }'`"
675 if [ ".$hostname" = .
]; then
681 domainname
=".`echo $hostname | cut -d. -f2-`"
682 hostname
="`echo $hostname | cut -d. -f1`"
686 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%d'`" != .
]; then
687 if [ ".$domainname" = .
]; then
688 if [ -f /etc
/resolv.conf
]; then
689 domainname
="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
690 sed -e 's/.*domain//' \
691 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
692 -e 's/^\.//' -e 's/^/./' |\
693 awk '{ printf("%s
", $1); }'`"
694 if [ ".$domainname" = .
]; then
695 domainname
="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
696 sed -e 's/.*search//' \
697 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
698 -e 's/ .*//' -e 's/ .*//' \
699 -e 's/^\.//' -e 's/^/./' |\
700 awk '{ printf("%s
", $1); }'`"
706 # determine current time
711 if [ ".$opt_e" = .
yes ] && [ ".`echo $text | grep '%[DMYm]'`" != .
]; then
712 time_day
=`date '+%d'`
713 time_month
=`date '+%m'`
714 time_year
=`date '+%Y' 2>/dev/null`
715 if [ ".$time_year" = .
]; then
716 time_year
=`date '+%y'`
718 [5-9][0-9]) time_year
="19$time_year" ;;
719 [0-4][0-9]) time_year
="20$time_year" ;;
723 1|
01) time_monthname
='Jan' ;;
724 2|
02) time_monthname
='Feb' ;;
725 3|
03) time_monthname
='Mar' ;;
726 4|
04) time_monthname
='Apr' ;;
727 5|
05) time_monthname
='May' ;;
728 6|
06) time_monthname
='Jun' ;;
729 7|
07) time_monthname
='Jul' ;;
730 8|
08) time_monthname
='Aug' ;;
731 9|
09) time_monthname
='Sep' ;;
732 10) time_monthname
='Oct' ;;
733 11) time_monthname
='Nov' ;;
734 12) time_monthname
='Dec' ;;
738 # expand special ``%x'' constructs
739 if [ ".$opt_e" = .
yes ]; then
740 text
=`echo $seo "$text" |\
741 sed -e "s/%B/${term_bold}/g" \
742 -e "s/%b/${term_norm}/g" \
743 -e "s/%u/${username}/g" \
744 -e "s/%U/${userid}/g" \
745 -e "s/%g/${groupname}/g" \
746 -e "s/%G/${groupid}/g" \
747 -e "s/%h/${hostname}/g" \
748 -e "s/%d/${domainname}/g" \
749 -e "s/%D/${time_day}/g" \
750 -e "s/%M/${time_month}/g" \
751 -e "s/%Y/${time_year}/g" \
752 -e "s/%m/${time_monthname}/g" 2>/dev/null`
756 if [ .
$opt_n = .no
]; then
759 # the harder part: echo -n is best, because
760 # awk may complain about some \xx sequences.
761 if [ ".$minusn" != .
]; then
762 echo $seo $minusn "$text"
764 echo dummy |
awk '{ printf("%s", TEXT); }' TEXT
="$text"
773 ## install -- Install a program, script or datafile
774 ## Copyright (c) 1997-2006 Ralf S. Engelschall <rse@engelschall.com>
777 # special case: "shtool install -d <dir> [...]" internally
778 # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
779 if [ "$opt_d" = yes ]; then
780 cmd
="$0 mkdir -f -p -m 755"
781 if [ ".$opt_o" != .
]; then
782 cmd
="$cmd -o '$opt_o'"
784 if [ ".$opt_g" != .
]; then
785 cmd
="$cmd -g '$opt_g'"
787 if [ ".$opt_v" = .
yes ]; then
790 if [ ".$opt_t" = .
yes ]; then
794 eval "$cmd $dir" || shtool_exit $?
799 # determine source(s) and destination
802 while [ $# -gt 1 ]; do
808 # type check for destination
810 if [ -d $dstpath ]; then
811 dstpath
=`echo "$dstpath" | sed -e 's:/$::'`
815 # consistency check for destination
816 if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
817 echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
821 # iterate over all source(s)
825 # if destination is a directory, append the input filename
826 if [ $dstisdir = 1 ]; then
827 dstfile
=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
831 # check for correct arguments
832 if [ ".$src" = ".$dst" ]; then
833 echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
836 if [ -d "$src" ]; then
837 echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
841 # make a temp file name in the destination directory
843 sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
844 -e "s;\$;/#INST@$$#;"`
847 if [ ".$opt_v" = .
yes ]; then
848 echo "$src -> $dst" 1>&2
851 # copy or move the file name to the temp name
852 # (because we might be not allowed to change the source)
853 if [ ".$opt_C" = .
yes ]; then
856 if [ ".$opt_c" = .
yes ]; then
857 if [ ".$opt_t" = .
yes ]; then
858 echo "cp $src $dsttmp" 1>&2
860 cp $src $dsttmp || shtool_exit $?
862 if [ ".$opt_t" = .
yes ]; then
863 echo "mv $src $dsttmp" 1>&2
865 mv $src $dsttmp || shtool_exit $?
868 # adjust the target file
869 if [ ".$opt_e" != .
]; then
871 OIFS
="$IFS"; IFS
="$ASC_NL"; set -- $opt_e; IFS
="$OIFS"
876 cp $dsttmp $dsttmp.old
878 eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
881 if [ ".$opt_s" = .
yes ]; then
882 if [ ".$opt_t" = .
yes ]; then
883 echo "strip $dsttmp" 1>&2
885 strip
$dsttmp || shtool_exit $?
887 if [ ".$opt_o" != .
]; then
888 if [ ".$opt_t" = .
yes ]; then
889 echo "chown $opt_o $dsttmp" 1>&2
891 chown
$opt_o $dsttmp || shtool_exit $?
893 if [ ".$opt_g" != .
]; then
894 if [ ".$opt_t" = .
yes ]; then
895 echo "chgrp $opt_g $dsttmp" 1>&2
897 chgrp
$opt_g $dsttmp || shtool_exit $?
899 if [ ".$opt_m" != ".-" ]; then
900 if [ ".$opt_t" = .
yes ]; then
901 echo "chmod $opt_m $dsttmp" 1>&2
903 chmod $opt_m $dsttmp || shtool_exit $?
906 # determine whether to do a quick install
907 # (has to be done _after_ the strip was already done)
909 if [ ".$opt_C" = .
yes ]; then
911 if cmp -s $src $dst; then
917 # finally, install the file to the real destination
918 if [ $quick = yes ]; then
919 if [ ".$opt_t" = .
yes ]; then
920 echo "rm -f $dsttmp" 1>&2
924 if [ ".$opt_t" = .
yes ]; then
925 echo "rm -f $dst && mv $dsttmp $dst" 1>&2
927 rm -f $dst && mv $dsttmp $dst
936 ## mkdir -- Make one or more directories
937 ## Copyright (c) 1996-2006 Ralf S. Engelschall <rse@engelschall.com>
941 for p
in ${1+"$@"}; do
942 # if the directory already exists...
944 if [ ".$opt_f" = .no
] && [ ".$opt_p" = .no
]; then
945 echo "$msgprefix:Error: directory already exists: $p" 1>&2
952 # if the directory has to be created...
953 if [ ".$opt_p" = .no
]; then
954 if [ ".$opt_t" = .
yes ]; then
957 mkdir
$p || errstatus
=$?
958 if [ ".$opt_o" != .
]; then
959 if [ ".$opt_t" = .
yes ]; then
960 echo "chown $opt_o $p" 1>&2
962 chown
$opt_o $p || errstatus
=$?
964 if [ ".$opt_g" != .
]; then
965 if [ ".$opt_t" = .
yes ]; then
966 echo "chgrp $opt_g $p" 1>&2
968 chgrp
$opt_g $p || errstatus
=$?
970 if [ ".$opt_m" != .
]; then
971 if [ ".$opt_t" = .
yes ]; then
972 echo "chmod $opt_m $p" 1>&2
974 chmod $opt_m $p || errstatus
=$?
977 # the smart situation
978 set fnord
`echo ":$p" |\
985 for d
in ${1+"$@"}; do
986 pathcomp
="$pathcomp$d"
988 -* ) pathcomp
="./$pathcomp" ;;
990 if [ ! -d "$pathcomp" ]; then
991 if [ ".$opt_t" = .
yes ]; then
992 echo "mkdir $pathcomp" 1>&2
994 mkdir
$pathcomp || errstatus
=$?
995 if [ ".$opt_o" != .
]; then
996 if [ ".$opt_t" = .
yes ]; then
997 echo "chown $opt_o $pathcomp" 1>&2
999 chown
$opt_o $pathcomp || errstatus
=$?
1001 if [ ".$opt_g" != .
]; then
1002 if [ ".$opt_t" = .
yes ]; then
1003 echo "chgrp $opt_g $pathcomp" 1>&2
1005 chgrp
$opt_g $pathcomp || errstatus
=$?
1007 if [ ".$opt_m" != .
]; then
1008 if [ ".$opt_t" = .
yes ]; then
1009 echo "chmod $opt_m $pathcomp" 1>&2
1011 chmod $opt_m $pathcomp || errstatus
=$?
1014 pathcomp
="$pathcomp/"
1019 shtool_exit
$errstatus
1024 ## platform -- Platform Identification Utility
1025 ## Copyright (c) 2003-2006 Ralf S. Engelschall <rse@engelschall.com>
1028 # option post-processing
1029 if [ ".$opt_t" != .
]; then
1032 # binary package id (OpenPKG RPM)
1039 # build time checking (OpenPKG RPM)
1046 # GNU config.guess style <arch>-<vendor>-<os><osversion>
1047 opt_F
="%<at>-unknown-%<st>"
1053 # non-whitespace HTTP Server-header id
1059 # human readable verbose summary information
1060 opt_F
="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
1065 # full-table all-in-one information
1067 opt_F
="${opt_F}concise architecture class: %<ac>\\n"
1068 opt_F
="${opt_F}regular architecture class: %{ac}\\n"
1069 opt_F
="${opt_F}verbose architecture class: %[ac]\\n"
1070 opt_F
="${opt_F}concise architecture product: %<ap>\\n"
1071 opt_F
="${opt_F}regular architecture product: %{ap}\\n"
1072 opt_F
="${opt_F}verbose architecture product: %[ap]\\n"
1073 opt_F
="${opt_F}concise architecture technology: %<at>\\n"
1074 opt_F
="${opt_F}regular architecture technology: %{at}\\n"
1075 opt_F
="${opt_F}verbose architecture technology: %[at]\\n"
1076 opt_F
="${opt_F}concise system class: %<sc>\\n"
1077 opt_F
="${opt_F}regular system class: %{sc}\\n"
1078 opt_F
="${opt_F}verbose system class: %[sc]\\n"
1079 opt_F
="${opt_F}concise system product: %<sp>\\n"
1080 opt_F
="${opt_F}regular system product: %{sp}\\n"
1081 opt_F
="${opt_F}verbose system product: %[sp]\\n"
1082 opt_F
="${opt_F}concise system technology: %<st>\\n"
1083 opt_F
="${opt_F}regular system technology: %{st}\\n"
1084 opt_F
="${opt_F}verbose system technology: %[st]"
1087 echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
1093 # assemble initial platform information
1094 UNAME_MACHINE
=`(uname -m) 2>/dev/null` ||\
1095 UNAME_MACHINE
=`(uname -p) 2>/dev/null` ||\
1096 UNAME_MACHINE
='unknown'
1097 UNAME_SYSTEM
=`(uname -s) 2>/dev/null` ||\
1098 UNAME_SYSTEM
='unknown'
1099 UNAME_RELEASE
=`(uname -r) 2>/dev/null` ||\
1100 UNAME_RELEASE
=`(uname -v) 2>/dev/null` ||\
1101 UNAME_RELEASE
='unknown'
1103 UNAME
="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
1108 # dispatch into platform specific sections
1113 # determine architecture
1114 AC
="${UNAME_MACHINE}"
1120 if [ ".${AT}" = ".iX86" ]; then
1121 case "`(/sbin/sysctl -n hw.model) 2>&1`" in
1122 *"Xeon"* |
*"Pentium Pro"* |
*"Cyrix 6x86MX"* |
*"Pentium II"* |
*"Pentium III"* |
*"Pentium 4"* |
*"Celeron"* ) AT
="i686" ;;
1123 *"Pentium"* ) AT
="i586" ;; *"i486[SD]X"* |
*"Cyrix 486"* |
*"Cyrix [56]x86"* |
*"Blue Lightning" |
*"Cyrix 486S/DX" ) AT
="i486" ;;
1124 *"i386[SD]X"* |
*"NexGen 586"* ) AT
="i386" ;;
1128 r
=`echo "${UNAME_RELEASE}" |\
1129 sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
1133 1.
* ) SC
="4.3BSD" ;;
1140 # determine architecture
1141 AT
="${UNAME_MACHINE}"
1144 i
[3-6]86 ) AP
="iX86" ;;
1148 r
=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1152 0.
* ) SC
="4.3BSD" ;;
1159 # determine architecture
1160 AT
="${UNAME_MACHINE}"
1163 i
[3-6]86 ) AP
="iX86" ;;
1167 r
=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
1175 # determine architecture
1176 AT
="${UNAME_MACHINE}"
1179 x86_64
) AT
='AMD64' ;;
1180 parisc
) AT
="HPPA32" ;;
1181 parisc64
) AT
="HPPA64" ;;
1185 i
[3-6]86 ) AP
='iX86' ;;
1189 v_kern
=`echo "${UNAME_RELEASE}" |\
1190 sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
1191 v_libc
=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
1192 env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
1193 ST
="GNU/<Linux >${v_libc}/<${v_kern}>"
1194 if [ -f /etc
/lsb-release
]; then
1195 eval `( . /etc/lsb-release
1196 echo "SC=\"LSB${LSB_VERSION}\""
1197 if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
1198 echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
1202 if [ ".$SP" = .
]; then
1205 /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
1206 sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
1207 echo redhat-release lsb-release`
1209 [ ".${tagfile}" = .x
] && continue
1210 [ ! -f "/etc/${tagfile}" ] && continue
1211 n
=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
1212 v
=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
1214 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1215 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1216 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1218 case "`util_lower ${n}`" in
1220 if [ ".`grep 'Red Hat Enterprise Linux' /etc/${tagfile}`" != .
]; then
1221 n
="<R>ed <H>at <E>nterprise <L>inux"
1223 n
="<R>ed <H>at <L>inux"
1226 debian
) n
="Debian[ GNU/Linux]" ;;
1227 ubuntu
) n
="Ubuntu[ GNU/Linux]" ;;
1228 fedora
) n
="<Fedora> Core[ GNU/Linux]" ;;
1229 suse
) n
="SuSE[ Linux]" ;;
1230 mandrake
*|mandriva
) n
="Mandriva[ Linux]" ;;
1231 gentoo
) n
="Gentoo[ GNU/Linux]" ;;
1232 slackware
) n
="Slackware[ Linux]" ;;
1233 turbolinux
) n
="TurboLinux" ;;
1234 unitedlinux
) n
="UnitedLinux" ;;
1235 * ) n
="${n}[ GNU/Linux]" ;;
1238 *"<"*">"* ) SP
="$n <$v>" ;;
1244 [ ".$SP" = .
] && SP
="${ST}"
1245 [ ".$SC" = .
] && SC
="LSB"
1250 # determine architecture
1251 AT
="${UNAME_MACHINE}"
1255 case "`(/bin/isainfo -k) 2>&1`" in
1256 amd64
) AT
="AMD64" ;;
1262 sun4
[cdm
] ) AP
="SPARC32" ;;
1263 sun4
[uv
] ) AP
="SPARC64" ;;
1264 sun4
* ) AP
="SPARC" ;;
1268 SPARC
* ) AC
="SPARC" ;;
1271 ST
="[Sun ]SunOS ${UNAME_RELEASE}"
1272 v
=`echo "${UNAME_RELEASE}" |\
1273 sed -e 's;^4\.;1.;' \
1274 -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
1275 -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
1276 SP
="[Sun ]Solaris $v"
1277 case "${UNAME_RELEASE}" in
1278 4.
* ) SC
="4.3BSD" ;;
1285 # determine architecture
1286 AT
="${UNAME_MACHINE}"
1288 i
[3-6]86 | ix86at
) AT
="iX86" ;;
1293 ST
="[SCO ]UnixWare ${v}"
1295 SC
="SVR${UNAME_RELEASE}"
1300 # determine architecture
1301 AT
="${UNAME_MACHINE}"
1303 x86pc
) AT
="iX86" ;;
1307 v
="${UNAME_RELEASE}"
1308 ST
="QNX[ Neutrino RTOS] ${v}"
1309 v
=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
1310 SP
="QNX[ Neutrino RTOS] ${v}"
1316 # determine architecture
1317 AT
="${UNAME_MACHINE}"
1319 case "${AP}:${UNAME_SYSTEM}" in
1320 IP
*:IRIX64
) AP
="MIPS64" ;;
1321 IP
*:* ) AP
="MIPS" ;;
1325 v
=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
1326 ST
="[SGI ]IRIX ${v}"
1327 v
="${UNAME_RELEASE}"
1328 SP
="[SGI ]IRIX ${v}"
1334 # determine architecture
1335 AT
="${UNAME_MACHINE}"
1338 9000/[34]??
) AT
=M68K
;;
1339 9000/[678][0-9][0-9])
1340 sc_cpu_version
=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
1341 sc_kernel_bits
=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
1342 case "${sc_cpu_version}" in
1343 523 ) AT
="HPPA1.0" ;;
1344 528 ) AT
="HPPA1.1" ;;
1346 case "${sc_kernel_bits}" in
1356 HPPA
* ) AP
="HPPA" ;;
1360 v
=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
1361 ST
="[HP ]<HP>-<UX ${v}>"
1364 10.
* ) SC
="SVR4.2" ;;
1365 [7-9]* ) SC
="SVR4" ;;
1371 # determine architecture
1372 AP
="${UNAME_MACHINE}"
1374 alpha
) AP
="Alpha" ;;
1376 alpha_type
=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
1377 sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
1378 AT
="${AP}${alpha_type}"
1381 v
=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
1382 ST
="[HP ]Tru64 ${v}"
1390 if [ -x /usr
/sbin
/lsdev
-a -x /usr
/sbin
/lsattr
]; then
1391 cpu_id
=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
1392 if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != .
]; then
1395 elif [ -d /QOpenSys
]; then
1396 # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
1399 if [ -x /usr
/bin
/oslevel
]; then
1400 os_level
=`/usr/bin/oslevel`
1402 os_level
="`uname -v`.`uname -r`"
1404 os_level
=`echo "${os_level}" |\
1405 sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
1406 -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
1410 ST
="[IBM ]<AIX >${os_level}"
1412 case "${os_level}" in
1413 [12]* ) SC
="SVR2" ;;
1418 # Apple MacOS X Darwin
1422 powerpc
) AT
="PPC" ;;
1429 ST
="[Apple ]${UNAME_SYSTEM} ${UNAME_RELEASE}"
1434 # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
1439 # ...A STILL UNKNOWN PLATFORM...
1441 AT
=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
1444 v
=`echo "${UNAME_RELEASE}" |\
1446 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1447 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
1448 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
1450 ST
="${UNAME_SYSTEM} ${v}"
1457 # provide fallback values
1458 [ ".$AT" = .
] && AT
="${AP:-${AC}}"
1459 [ ".$AP" = .
] && AP
="${AT:-${AC}}"
1460 [ ".$AC" = .
] && AC
="${AP:-${AT}}"
1461 [ ".$ST" = .
] && ST
="${SP:-${SC}}"
1462 [ ".$SP" = .
] && SP
="${ST:-${SC}}"
1463 [ ".$SC" = .
] && SC
="${SP:-${ST}}"
1465 # support explicit enforced verbose/concise output
1466 if [ ".$opt_v" = .
yes ]; then
1467 opt_F
=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
1468 elif [ ".$opt_c" = .
yes ]; then
1469 opt_F
=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
1472 # provide verbose and concise variants
1473 AC_V
=""; AC_N
=""; AC_C
=""
1474 AP_V
=""; AP_N
=""; AP_C
=""
1475 AT_V
=""; AT_N
=""; AT_C
=""
1476 SC_V
=""; SC_N
=""; SC_C
=""
1477 SP_V
=""; SP_N
=""; SP_C
=""
1478 ST_V
=""; ST_N
=""; ST_C
=""
1479 for var_lc
in at ap ac st sp sc
; do
1481 *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
1482 var_uc
=`util_upper "$var_lc"`
1483 eval "val=\"\$${var_uc}\""
1484 val_V
=""; val_N
=""; val_C
=""
1487 val_V
=`echo ":$val" | \
1489 -e 's;\[\([^]]*\)\];\1;g' \
1490 -e 's;<\([^>]*\)>;\1;g' \
1493 -e "s;§§;${opt_S};g" \
1494 -e "s;%%;${opt_C};g"`
1495 eval "${var_uc}_V=\"\${val_V}\""
1499 *"%{${var_lc}}"* |
*"%${var_lc}"* )
1500 val_N
=`echo ":$val" | \
1502 -e 's;\[\([^]]*\)\];;g' \
1503 -e 's;<\([^>]*\)>;\1;g' \
1506 -e "s;§§;${opt_S};g" \
1507 -e "s;%%;${opt_C};g"`
1508 eval "${var_uc}_N=\"\${val_N}\""
1513 val_C
=`echo ":$val" | \
1515 -e 's;\[\([^]]*\)\];;g' \
1516 -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
1519 -e "s;§§;${opt_S};g" \
1520 -e "s;%%;${opt_C};g"`
1521 eval "${var_uc}_C=\"\${val_C}\""
1528 # create output string
1529 output
=`echo ":$opt_F" |\
1531 -e "s;%\\[ac\\];${AC_V};g" \
1532 -e "s;%{ac};${AC_N};g" \
1533 -e "s;%ac;${AC_N};g" \
1534 -e "s;%<ac>;${AC_C};g" \
1535 -e "s;%\\[ap\\];${AP_V};g" \
1536 -e "s;%{ap};${AP_N};g" \
1537 -e "s;%ap;${AP_N};g" \
1538 -e "s;%<ap>;${AP_C};g" \
1539 -e "s;%\\[at\\];${AT_V};g" \
1540 -e "s;%{at};${AT_N};g" \
1541 -e "s;%at;${AT_N};g" \
1542 -e "s;%<at>;${AT_C};g" \
1543 -e "s;%\\[sc\\];${SC_V};g" \
1544 -e "s;%{sc};${SC_N};g" \
1545 -e "s;%sc;${SC_N};g" \
1546 -e "s;%<sc>;${SC_C};g" \
1547 -e "s;%\\[sp\\];${SP_V};g" \
1548 -e "s;%{sp};${SP_N};g" \
1549 -e "s;%sp;${SP_N};g" \
1550 -e "s;%<sp>;${SP_C};g" \
1551 -e "s;%\\[st\\];${ST_V};g" \
1552 -e "s;%{st};${ST_N};g" \
1553 -e "s;%st;${ST_N};g" \
1554 -e "s;%<st>;${ST_C};g" \
1558 # support lower/upper-case mapping
1559 if [ ".$opt_L" = .
yes ]; then
1560 output
=`util_lower "$output"`
1561 elif [ ".$opt_U" = .
yes ]; then
1562 output
=`util_upper "$output"`
1565 # display output string
1566 if [ ".$opt_n" = .
yes ]; then
1567 echo . |
awk '{ printf("%s", output); }' output
="$output"
1577 ## path -- Deal with program paths
1578 ## Copyright (c) 1998-2006 Ralf S. Engelschall <rse@engelschall.com>
1583 # check whether the test command supports the -x option
1584 if [ -x /bin
/sh
] 2>/dev
/null
; then
1591 paths
="`echo $opt_p |\
1598 # translate forward to reverse path
1599 if [ ".$opt_r" = .
yes ]; then
1600 if [ "x$namelist" = "x." ]; then
1604 for pe
in `IFS="$IFS/"; echo $namelist`; do
1608 echo $rp |
sed -e 's:/$::'
1613 # strip out directory or base name
1614 if [ ".$opt_d" = .
yes ]; then
1616 sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
1619 if [ ".$opt_b" = .
yes ]; then
1621 sed -e 's;.*/\([^/]*\)$;\1;'
1626 # Perl Interpreter (perl)
1627 if [ ".$opt_m" = .
yes ] && [ ".$namelist" = .perl
]; then
1628 rm -f $tmpfile >/dev
/null
2>&1
1632 for dir
in $paths; do
1633 dir
=`echo $dir | sed -e 's;/*$;;'`
1635 for name
in perl perl5 miniperl
; do
1636 if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
1638 pv
=`$perl -e 'printf("%.3f", $]);'`
1639 echo "$pv:$pc:$nc:$perl" >>$tmpfile
1646 if [ $found = 1 ]; then
1647 perl
="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
1648 rm -f $tmpfile >/dev
/null
2>&1
1652 rm -f $tmpfile >/dev
/null
2>&1
1657 # C pre-processor (cpp)
1658 if [ ".$opt_m" = .
yes ] && [ ".$namelist" = .cpp
]; then
1659 echo >$tmpfile.c
"#include <assert.h>"
1660 echo >>$tmpfile.c
"Syntax Error"
1661 # 1. try the standard cc -E approach
1663 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1664 my_error
=`grep -v '^ *+' $tmpfile.out`
1665 if [ ".$my_error" != .
]; then
1666 # 2. try the cc -E approach and GCC's -traditional-ccp option
1667 cpp
="${CC-cc} -E -traditional-cpp"
1668 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1669 my_error
=`grep -v '^ *+' $tmpfile.out`
1670 if [ ".$my_error" != .
]; then
1671 # 3. try a standalone cpp command in path and lib dirs
1672 for path
in $paths /lib
/usr
/lib
/usr
/local
/lib
; do
1673 path
=`echo $path | sed -e 's;/*$;;'`
1674 if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
1679 if [ ".$cpp" != .
]; then
1680 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
1681 my_error
=`grep -v '^ *+' $tmpfile.out`
1682 if [ ".$my_error" != .
]; then
1689 rm -f $tmpfile >/dev
/null
2>&1
1690 rm -f $tmpfile.c
$tmpfile.out
>/dev
/null
2>&1
1691 if [ ".$cpp" != .
]; then
1698 # STANDARD SITUATION
1699 # iterate over names
1700 for name
in $namelist; do
1701 # iterate over paths
1702 for path
in $paths; do
1703 path
=`echo $path | sed -e 's;/*$;;'`
1704 if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
1705 if [ ".$opt_s" != .
yes ]; then