1 |
#!/bin/sh |
2 |
## |
3 |
## GNU shtool -- The GNU Portable Shell Tool |
4 |
## Copyright (c) 1994-2006 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.6 (19-Apr-2006) |
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.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>' |
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.6 (19-Apr-2006)" |
165 |
exit 0 |
166 |
fi |
167 |
if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then |
168 |
shtoolize -oshtool 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-2006 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=`(ypcat passwd) 2>/dev/null | |
598 |
grep "^${username}:" | \ |
599 |
sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` |
600 |
if [ ".$userid" = . ]; then |
601 |
userid='?' |
602 |
fi |
603 |
fi |
604 |
fi |
605 |
fi |
606 |
fi |
607 |
fi |
608 |
fi |
609 |
|
610 |
# determine (primary) group id |
611 |
groupid='' |
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/(.*$//'` |
618 |
fi |
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 |
629 |
groupid='?' |
630 |
fi |
631 |
fi |
632 |
fi |
633 |
fi |
634 |
fi |
635 |
fi |
636 |
|
637 |
# determine (primary) group name |
638 |
groupname='' |
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/).*$//'` |
645 |
fi |
646 |
if [ ".$groupname" = . ]; then |
647 |
groupname=`(getent group) 2>/dev/null | \ |
648 |
grep "^[^:]*:[^:]*:${groupid}:" | \ |
649 |
sed -e 's/:.*$//'` |
650 |
if [ ".$groupname" = . ]; then |
651 |
groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ |
652 |
sed -e 's/:.*$//'` |
653 |
if [ ".$groupname" = . ]; then |
654 |
groupname=`(ypcat group) 2>/dev/null | \ |
655 |
grep "^[^:]*:[^:]*:${groupid}:" | \ |
656 |
sed -e 's/:.*$//'` |
657 |
if [ ".$groupname" = . ]; then |
658 |
groupname='?' |
659 |
fi |
660 |
fi |
661 |
fi |
662 |
fi |
663 |
fi |
664 |
fi |
665 |
|
666 |
# determine host and domain name |
667 |
hostname='' |
668 |
domainname='' |
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 |
676 |
hostname='unknown' |
677 |
fi |
678 |
fi |
679 |
case $hostname in |
680 |
*.* ) |
681 |
domainname=".`echo $hostname | cut -d. -f2-`" |
682 |
hostname="`echo $hostname | cut -d. -f1`" |
683 |
;; |
684 |
esac |
685 |
fi |
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); }'`" |
701 |
fi |
702 |
fi |
703 |
fi |
704 |
fi |
705 |
|
706 |
# determine current time |
707 |
time_day='' |
708 |
time_month='' |
709 |
time_year='' |
710 |
time_monthname='' |
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'` |
717 |
case $time_year in |
718 |
[5-9][0-9]) time_year="19$time_year" ;; |
719 |
[0-4][0-9]) time_year="20$time_year" ;; |
720 |
esac |
721 |
fi |
722 |
case $time_month in |
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' ;; |
735 |
esac |
736 |
fi |
737 |
|
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` |
753 |
fi |
754 |
|
755 |
# create output |
756 |
if [ .$opt_n = .no ]; then |
757 |
echo $seo "$text" |
758 |
else |
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" |
763 |
else |
764 |
echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text" |
765 |
fi |
766 |
fi |
767 |
|
768 |
shtool_exit 0 |
769 |
;; |
770 |
|
771 |
install ) |
772 |
## |
773 |
## install -- Install a program, script or datafile |
774 |
## Copyright (c) 1997-2006 Ralf S. Engelschall <rse@engelschall.com> |
775 |
## |
776 |
|
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'" |
783 |
fi |
784 |
if [ ".$opt_g" != . ]; then |
785 |
cmd="$cmd -g '$opt_g'" |
786 |
fi |
787 |
if [ ".$opt_v" = .yes ]; then |
788 |
cmd="$cmd -v" |
789 |
fi |
790 |
if [ ".$opt_t" = .yes ]; then |
791 |
cmd="$cmd -t" |
792 |
fi |
793 |
for dir in "$@"; do |
794 |
eval "$cmd $dir" || shtool_exit $? |
795 |
done |
796 |
shtool_exit 0 |
797 |
fi |
798 |
|
799 |
# determine source(s) and destination |
800 |
argc=$# |
801 |
srcs="" |
802 |
while [ $# -gt 1 ]; do |
803 |
srcs="$srcs $1" |
804 |
shift |
805 |
done |
806 |
dstpath="$1" |
807 |
|
808 |
# type check for destination |
809 |
dstisdir=0 |
810 |
if [ -d $dstpath ]; then |
811 |
dstpath=`echo "$dstpath" | sed -e 's:/$::'` |
812 |
dstisdir=1 |
813 |
fi |
814 |
|
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 |
818 |
shtool_exit 1 |
819 |
fi |
820 |
|
821 |
# iterate over all source(s) |
822 |
for src in $srcs; do |
823 |
dst=$dstpath |
824 |
|
825 |
# if destination is a directory, append the input filename |
826 |
if [ $dstisdir = 1 ]; then |
827 |
dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'` |
828 |
dst="$dst/$dstfile" |
829 |
fi |
830 |
|
831 |
# check for correct arguments |
832 |
if [ ".$src" = ".$dst" ]; then |
833 |
echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2 |
834 |
continue |
835 |
fi |
836 |
if [ -d "$src" ]; then |
837 |
echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2 |
838 |
continue |
839 |
fi |
840 |
|
841 |
# make a temp file name in the destination directory |
842 |
dsttmp=`echo $dst |\ |
843 |
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \ |
844 |
-e "s;\$;/#INST@$$#;"` |
845 |
|
846 |
# verbosity |
847 |
if [ ".$opt_v" = .yes ]; then |
848 |
echo "$src -> $dst" 1>&2 |
849 |
fi |
850 |
|
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 |
854 |
opt_c=yes |
855 |
fi |
856 |
if [ ".$opt_c" = .yes ]; then |
857 |
if [ ".$opt_t" = .yes ]; then |
858 |
echo "cp $src $dsttmp" 1>&2 |
859 |
fi |
860 |
cp $src $dsttmp || shtool_exit $? |
861 |
else |
862 |
if [ ".$opt_t" = .yes ]; then |
863 |
echo "mv $src $dsttmp" 1>&2 |
864 |
fi |
865 |
mv $src $dsttmp || shtool_exit $? |
866 |
fi |
867 |
|
868 |
# adjust the target file |
869 |
if [ ".$opt_e" != . ]; then |
870 |
sed='sed' |
871 |
OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" |
872 |
for e |
873 |
do |
874 |
sed="$sed -e '$e'" |
875 |
done |
876 |
cp $dsttmp $dsttmp.old |
877 |
chmod u+w $dsttmp |
878 |
eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $? |
879 |
rm -f $dsttmp.old |
880 |
fi |
881 |
if [ ".$opt_s" = .yes ]; then |
882 |
if [ ".$opt_t" = .yes ]; then |
883 |
echo "strip $dsttmp" 1>&2 |
884 |
fi |
885 |
strip $dsttmp || shtool_exit $? |
886 |
fi |
887 |
if [ ".$opt_o" != . ]; then |
888 |
if [ ".$opt_t" = .yes ]; then |
889 |
echo "chown $opt_o $dsttmp" 1>&2 |
890 |
fi |
891 |
chown $opt_o $dsttmp || shtool_exit $? |
892 |
fi |
893 |
if [ ".$opt_g" != . ]; then |
894 |
if [ ".$opt_t" = .yes ]; then |
895 |
echo "chgrp $opt_g $dsttmp" 1>&2 |
896 |
fi |
897 |
chgrp $opt_g $dsttmp || shtool_exit $? |
898 |
fi |
899 |
if [ ".$opt_m" != ".-" ]; then |
900 |
if [ ".$opt_t" = .yes ]; then |
901 |
echo "chmod $opt_m $dsttmp" 1>&2 |
902 |
fi |
903 |
chmod $opt_m $dsttmp || shtool_exit $? |
904 |
fi |
905 |
|
906 |
# determine whether to do a quick install |
907 |
# (has to be done _after_ the strip was already done) |
908 |
quick=no |
909 |
if [ ".$opt_C" = .yes ]; then |
910 |
if [ -r $dst ]; then |
911 |
if cmp -s $src $dst; then |
912 |
quick=yes |
913 |
fi |
914 |
fi |
915 |
fi |
916 |
|
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 |
921 |
fi |
922 |
rm -f $dsttmp |
923 |
else |
924 |
if [ ".$opt_t" = .yes ]; then |
925 |
echo "rm -f $dst && mv $dsttmp $dst" 1>&2 |
926 |
fi |
927 |
rm -f $dst && mv $dsttmp $dst |
928 |
fi |
929 |
done |
930 |
|
931 |
shtool_exit 0 |
932 |
;; |
933 |
|
934 |
mkdir ) |
935 |
## |
936 |
## mkdir -- Make one or more directories |
937 |
## Copyright (c) 1996-2006 Ralf S. Engelschall <rse@engelschall.com> |
938 |
## |
939 |
|
940 |
errstatus=0 |
941 |
for p in ${1+"$@"}; do |
942 |
# if the directory already exists... |
943 |
if [ -d "$p" ]; then |
944 |
if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then |
945 |
echo "$msgprefix:Error: directory already exists: $p" 1>&2 |
946 |
errstatus=1 |
947 |
break |
948 |
else |
949 |
continue |
950 |
fi |
951 |
fi |
952 |
# if the directory has to be created... |
953 |
if [ ".$opt_p" = .no ]; then |
954 |
if [ ".$opt_t" = .yes ]; then |
955 |
echo "mkdir $p" 1>&2 |
956 |
fi |
957 |
mkdir $p || errstatus=$? |
958 |
if [ ".$opt_o" != . ]; then |
959 |
if [ ".$opt_t" = .yes ]; then |
960 |
echo "chown $opt_o $p" 1>&2 |
961 |
fi |
962 |
chown $opt_o $p || errstatus=$? |
963 |
fi |
964 |
if [ ".$opt_g" != . ]; then |
965 |
if [ ".$opt_t" = .yes ]; then |
966 |
echo "chgrp $opt_g $p" 1>&2 |
967 |
fi |
968 |
chgrp $opt_g $p || errstatus=$? |
969 |
fi |
970 |
if [ ".$opt_m" != . ]; then |
971 |
if [ ".$opt_t" = .yes ]; then |
972 |
echo "chmod $opt_m $p" 1>&2 |
973 |
fi |
974 |
chmod $opt_m $p || errstatus=$? |
975 |
fi |
976 |
else |
977 |
# the smart situation |
978 |
set fnord `echo ":$p" |\ |
979 |
sed -e 's/^:\//%/' \ |
980 |
-e 's/^://' \ |
981 |
-e 's/\// /g' \ |
982 |
-e 's/^%/\//'` |
983 |
shift |
984 |
pathcomp='' |
985 |
for d in ${1+"$@"}; do |
986 |
pathcomp="$pathcomp$d" |
987 |
case "$pathcomp" in |
988 |
-* ) pathcomp="./$pathcomp" ;; |
989 |
esac |
990 |
if [ ! -d "$pathcomp" ]; then |
991 |
if [ ".$opt_t" = .yes ]; then |
992 |
echo "mkdir $pathcomp" 1>&2 |
993 |
fi |
994 |
mkdir $pathcomp || errstatus=$? |
995 |
if [ ".$opt_o" != . ]; then |
996 |
if [ ".$opt_t" = .yes ]; then |
997 |
echo "chown $opt_o $pathcomp" 1>&2 |
998 |
fi |
999 |
chown $opt_o $pathcomp || errstatus=$? |
1000 |
fi |
1001 |
if [ ".$opt_g" != . ]; then |
1002 |
if [ ".$opt_t" = .yes ]; then |
1003 |
echo "chgrp $opt_g $pathcomp" 1>&2 |
1004 |
fi |
1005 |
chgrp $opt_g $pathcomp || errstatus=$? |
1006 |
fi |
1007 |
if [ ".$opt_m" != . ]; then |
1008 |
if [ ".$opt_t" = .yes ]; then |
1009 |
echo "chmod $opt_m $pathcomp" 1>&2 |
1010 |
fi |
1011 |
chmod $opt_m $pathcomp || errstatus=$? |
1012 |
fi |
1013 |
fi |
1014 |
pathcomp="$pathcomp/" |
1015 |
done |
1016 |
fi |
1017 |
done |
1018 |
|
1019 |
shtool_exit $errstatus |
1020 |
;; |
1021 |
|
1022 |
platform ) |
1023 |
## |
1024 |
## platform -- Platform Identification Utility |
1025 |
## Copyright (c) 2003-2006 Ralf S. Engelschall <rse@engelschall.com> |
1026 |
## |
1027 |
|
1028 |
# option post-processing |
1029 |
if [ ".$opt_t" != . ]; then |
1030 |
case "$opt_t" in |
1031 |
binary ) |
1032 |
# binary package id (OpenPKG RPM) |
1033 |
opt_F="%<ap>-%<sp>" |
1034 |
opt_L=yes |
1035 |
opt_S="" |
1036 |
opt_C="+" |
1037 |
;; |
1038 |
build ) |
1039 |
# build time checking (OpenPKG RPM) |
1040 |
opt_F="%<at>-%<st>" |
1041 |
opt_L=yes |
1042 |
opt_S="" |
1043 |
opt_C="+" |
1044 |
;; |
1045 |
gnu ) |
1046 |
# GNU config.guess style <arch>-<vendor>-<os><osversion> |
1047 |
opt_F="%<at>-unknown-%<st>" |
1048 |
opt_L=yes |
1049 |
opt_S="" |
1050 |
opt_C="+" |
1051 |
;; |
1052 |
web ) |
1053 |
# non-whitespace HTTP Server-header id |
1054 |
opt_F="%<sp>-%<ap>" |
1055 |
opt_S="/" |
1056 |
opt_C="+" |
1057 |
;; |
1058 |
summary) |
1059 |
# human readable verbose summary information |
1060 |
opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])" |
1061 |
opt_S=" " |
1062 |
opt_C="/" |
1063 |
;; |
1064 |
all-in-one ) |
1065 |
# full-table all-in-one information |
1066 |
opt_F="" |
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]" |
1085 |
;; |
1086 |
* ) |
1087 |
echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2 |
1088 |
exit 1 |
1089 |
;; |
1090 |
esac |
1091 |
fi |
1092 |
|
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' |
1102 |
|
1103 |
UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}" |
1104 |
|
1105 |
AC=""; AP=""; AT="" |
1106 |
SC=""; SP=""; ST="" |
1107 |
|
1108 |
# dispatch into platform specific sections |
1109 |
case "${UNAME}" in |
1110 |
|
1111 |
# FreeBSD |
1112 |
*:FreeBSD:* ) |
1113 |
# determine architecture |
1114 |
AC="${UNAME_MACHINE}" |
1115 |
case "${AC}" in |
1116 |
i386 ) AC="iX86" ;; |
1117 |
esac |
1118 |
AP="${AC}" |
1119 |
AT="${AP}" |
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" ;; |
1125 |
esac |
1126 |
fi |
1127 |
# determine system |
1128 |
r=`echo "${UNAME_RELEASE}" |\ |
1129 |
sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'` |
1130 |
ST="FreeBSD ${r}" |
1131 |
SP="${ST}" |
1132 |
case "${r}" in |
1133 |
1.* ) SC="4.3BSD" ;; |
1134 |
* ) SC="4.4BSD" ;; |
1135 |
esac |
1136 |
;; |
1137 |
|
1138 |
# NetBSD |
1139 |
*:NetBSD:* ) |
1140 |
# determine architecture |
1141 |
AT="${UNAME_MACHINE}" |
1142 |
AP="${AT}" |
1143 |
case "${AP}" in |
1144 |
i[3-6]86 ) AP="iX86" ;; |
1145 |
esac |
1146 |
AC="${AP}" |
1147 |
# determine system |
1148 |
r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'` |
1149 |
ST="NetBSD ${r}" |
1150 |
SP="${ST}" |
1151 |
case "${r}" in |
1152 |
0.* ) SC="4.3BSD" ;; |
1153 |
* ) SC="4.4BSD" ;; |
1154 |
esac |
1155 |
;; |
1156 |
|
1157 |
# OpenBSD |
1158 |
*:OpenBSD:* ) |
1159 |
# determine architecture |
1160 |
AT="${UNAME_MACHINE}" |
1161 |
AP="${AT}" |
1162 |
case "${AP}" in |
1163 |
i[3-6]86 ) AP="iX86" ;; |
1164 |
esac |
1165 |
AC="${AP}" |
1166 |
# determine system |
1167 |
r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'` |
1168 |
ST="OpenBSD ${r}" |
1169 |
SP="${ST}" |
1170 |
SC="4.4BSD" |
1171 |
;; |
1172 |
|
1173 |
# GNU/Linux |
1174 |
*:Linux:* ) |
1175 |
# determine architecture |
1176 |
AT="${UNAME_MACHINE}" |
1177 |
case "${AT}" in |
1178 |
ia64 ) AT="IA64" ;; |
1179 |
x86_64 ) AT='AMD64' ;; |
1180 |
parisc ) AT="HPPA32" ;; |
1181 |
parisc64 ) AT="HPPA64" ;; |
1182 |
esac |
1183 |
AP="${AT}" |
1184 |
case "${AP}" in |
1185 |
i[3-6]86 ) AP='iX86' ;; |
1186 |
esac |
1187 |
AC="${AP}" |
1188 |
# determine system |
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}\"" |
1199 |
fi |
1200 |
) 2>/dev/null` |
1201 |
fi |
1202 |
if [ ".$SP" = . ]; then |
1203 |
for tagfile in x \ |
1204 |
`cd /etc && \ |
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` |
1208 |
do |
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' |\ |
1213 |
sed -e 's/^/#/' \ |
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/' \ |
1217 |
-e 's/^#.*$//'` |
1218 |
case "`util_lower ${n}`" in |
1219 |
redhat ) |
1220 |
if [ ".`grep 'Red Hat Enterprise Linux' /etc/${tagfile}`" != . ]; then |
1221 |
n="<R>ed <H>at <E>nterprise <L>inux" |
1222 |
else |
1223 |
n="<R>ed <H>at <L>inux" |
1224 |
fi |
1225 |
;; |
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]" ;; |
1236 |
esac |
1237 |
case "$n" in |
1238 |
*"<"*">"* ) SP="$n <$v>" ;; |
1239 |
* ) SP="$n $v" ;; |
1240 |
esac |
1241 |
break |
1242 |
done |
1243 |
fi |
1244 |
[ ".$SP" = . ] && SP="${ST}" |
1245 |
[ ".$SC" = . ] && SC="LSB" |
1246 |
;; |
1247 |
|
1248 |
# Sun Solaris |
1249 |
*:SunOS:* ) |
1250 |
# determine architecture |
1251 |
AT="${UNAME_MACHINE}" |
1252 |
case "${AT}" in |
1253 |
i86pc ) |
1254 |
AT="iX86" |
1255 |
case "`(/bin/isainfo -k) 2>&1`" in |
1256 |
amd64 ) AT="AMD64" ;; |
1257 |
esac |
1258 |
;; |
1259 |
esac |
1260 |
AP="${AT}" |
1261 |
case "${AP}" in |
1262 |
sun4[cdm] ) AP="SPARC32" ;; |
1263 |
sun4[uv] ) AP="SPARC64" ;; |
1264 |
sun4* ) AP="SPARC" ;; |
1265 |
esac |
1266 |
AC="${AP}" |
1267 |
case "${AC}" in |
1268 |
SPARC* ) AC="SPARC" ;; |
1269 |
esac |
1270 |
# determine system |
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" ;; |
1279 |
5.* ) SC="SVR4" ;; |
1280 |
esac |
1281 |
;; |
1282 |
|
1283 |
# SCO UnixWare |
1284 |
*:UnixWare:* ) |
1285 |
# determine architecture |
1286 |
AT="${UNAME_MACHINE}" |
1287 |
case "${AT}" in |
1288 |
i[3-6]86 | ix86at ) AT="iX86" ;; |
1289 |
esac |
1290 |
AP="${AT}" |
1291 |
# determine system |
1292 |
v=`/sbin/uname -v` |
1293 |
ST="[SCO ]UnixWare ${v}" |
1294 |
SP="${ST}" |
1295 |
SC="SVR${UNAME_RELEASE}" |
1296 |
;; |
1297 |
|
1298 |
# QNX |
1299 |
*:QNX:* ) |
1300 |
# determine architecture |
1301 |
AT="${UNAME_MACHINE}" |
1302 |
case "${AT}" in |
1303 |
x86pc ) AT="iX86" ;; |
1304 |
esac |
1305 |
AP="${AT}" |
1306 |
# determine system |
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}" |
1311 |
SC="QNX" |
1312 |
;; |
1313 |
|
1314 |
# SGI IRIX |
1315 |
*:IRIX*:* ) |
1316 |
# determine architecture |
1317 |
AT="${UNAME_MACHINE}" |
1318 |
AP="${AT}" |
1319 |
case "${AP}:${UNAME_SYSTEM}" in |
1320 |
IP*:IRIX64 ) AP="MIPS64" ;; |
1321 |
IP*:* ) AP="MIPS" ;; |
1322 |
esac |
1323 |
AC="${AP}" |
1324 |
# determine system |
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}" |
1329 |
SC="4.2BSD/SVR3" |
1330 |
;; |
1331 |
|
1332 |
# HP HP-UX |
1333 |
*:HP-UX:* ) |
1334 |
# determine architecture |
1335 |
AT="${UNAME_MACHINE}" |
1336 |
case "${AT}" in |
1337 |
ia64 ) AT="IA64" ;; |
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" ;; |
1345 |
532 ) AT="HPPA2.0" |
1346 |
case "${sc_kernel_bits}" in |
1347 |
32 ) AT="${AT}n" ;; |
1348 |
64 ) AT="${AT}w" ;; |
1349 |
esac |
1350 |
;; |
1351 |
esac |
1352 |
;; |
1353 |
esac |
1354 |
AP="${AT}" |
1355 |
case "${AP}" in |
1356 |
HPPA* ) AP="HPPA" ;; |
1357 |
esac |
1358 |
AC="${AP}" |
1359 |
# determine system |
1360 |
v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'` |
1361 |
ST="[HP ]<HP>-<UX ${v}>" |
1362 |
SP="${ST}" |
1363 |
case "${v}" in |
1364 |
10.* ) SC="SVR4.2" ;; |
1365 |
[7-9]* ) SC="SVR4" ;; |
1366 |
esac |
1367 |
;; |
1368 |
|
1369 |
# HP Tru64 (OSF1) |
1370 |
*:OSF1:* ) |
1371 |
# determine architecture |
1372 |
AP="${UNAME_MACHINE}" |
1373 |
case "${AP}" in |
1374 |
alpha ) AP="Alpha" ;; |
1375 |
esac |
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}" |
1379 |
AC="${AP}" |
1380 |
# determine system |
1381 |
v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'` |
1382 |
ST="[HP ]Tru64 ${v}" |
1383 |
SP="${ST}" |
1384 |
SC="OSF1" |
1385 |
;; |
1386 |
|
1387 |
# IBM AIX |
1388 |
*:AIX:* ) |
1389 |
cpu_arch=rs6000 |
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 |
1393 |
cpu_arch=powerpc |
1394 |
fi |
1395 |
elif [ -d /QOpenSys ]; then |
1396 |
# IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment) |
1397 |
cpu_arch=powerpc |
1398 |
fi |
1399 |
if [ -x /usr/bin/oslevel ]; then |
1400 |
os_level=`/usr/bin/oslevel` |
1401 |
else |
1402 |
os_level="`uname -v`.`uname -r`" |
1403 |
fi |
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;'` |
1407 |
AT="${cpu_arch}" |
1408 |
AP="${AT}" |
1409 |
AC="${AP}" |
1410 |
ST="[IBM ]<AIX >${os_level}" |
1411 |
SP="${ST}" |
1412 |
case "${os_level}" in |
1413 |
[12]* ) SC="SVR2" ;; |
1414 |
* ) SC="SVR4" ;; |
1415 |
esac |
1416 |
;; |
1417 |
|
1418 |
# Apple MacOS X Darwin |
1419 |
*:Darwin:* ) |
1420 |
AT=`uname -p` |
1421 |
case "${AT}" in |
1422 |
powerpc ) AT="PPC" ;; |
1423 |
esac |
1424 |
AP="${AT}" |
1425 |
AC="${AP}" |
1426 |
case "${AC}" in |
1427 |
i?86 ) AC="iX86" ;; |
1428 |
esac |
1429 |
ST="[Apple ]${UNAME_SYSTEM} ${UNAME_RELEASE}" |
1430 |
SP="${ST}" |
1431 |
SC="4.4BSD/Mach3" |
1432 |
;; |
1433 |
|
1434 |
# TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO |
1435 |
# *:XXX:* ) |
1436 |
# ... |
1437 |
# ;; |
1438 |
|
1439 |
# ...A STILL UNKNOWN PLATFORM... |
1440 |
* ) |
1441 |
AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"` |
1442 |
AP="${AT}" |
1443 |
AC="${AP}" |
1444 |
v=`echo "${UNAME_RELEASE}" |\ |
1445 |
sed -e 's/^/#/' \ |
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/' \ |
1449 |
-e 's/^#.*$/?/'` |
1450 |
ST="${UNAME_SYSTEM} ${v}" |
1451 |
SP="${ST}" |
1452 |
SC="${SP}" |
1453 |
;; |
1454 |
|
1455 |
esac |
1456 |
|
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}}" |
1464 |
|
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'` |
1470 |
fi |
1471 |
|
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 |
1480 |
case "$opt_F" in |
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="" |
1485 |
case "$opt_F" in |
1486 |
*"%[${var_lc}]"* ) |
1487 |
val_V=`echo ":$val" | \ |
1488 |
sed -e 's/^://' \ |
1489 |
-e 's;\[\([^]]*\)\];\1;g' \ |
1490 |
-e 's;<\([^>]*\)>;\1;g' \ |
1491 |
-e "s; ;§§;g" \ |
1492 |
-e "s;/;%%;g" \ |
1493 |
-e "s;§§;${opt_S};g" \ |
1494 |
-e "s;%%;${opt_C};g"` |
1495 |
eval "${var_uc}_V=\"\${val_V}\"" |
1496 |
;; |
1497 |
esac |
1498 |
case "$opt_F" in |
1499 |
*"%{${var_lc}}"* | *"%${var_lc}"* ) |
1500 |
val_N=`echo ":$val" | \ |
1501 |
sed -e 's/^://' \ |
1502 |
-e 's;\[\([^]]*\)\];;g' \ |
1503 |
-e 's;<\([^>]*\)>;\1;g' \ |
1504 |
-e "s; ;§§;g" \ |
1505 |
-e "s;/;%%;g" \ |
1506 |
-e "s;§§;${opt_S};g" \ |
1507 |
-e "s;%%;${opt_C};g"` |
1508 |
eval "${var_uc}_N=\"\${val_N}\"" |
1509 |
;; |
1510 |
esac |
1511 |
case "$opt_F" in |
1512 |
*"%<${var_lc}>"* ) |
1513 |
val_C=`echo ":$val" | \ |
1514 |
sed -e 's/^://' \ |
1515 |
-e 's;\[\([^]]*\)\];;g' \ |
1516 |
-e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \ |
1517 |
-e "s; ;§§;g" \ |
1518 |
-e "s;/;%%;g" \ |
1519 |
-e "s;§§;${opt_S};g" \ |
1520 |
-e "s;%%;${opt_C};g"` |
1521 |
eval "${var_uc}_C=\"\${val_C}\"" |
1522 |
;; |
1523 |
esac |
1524 |
;; |
1525 |
esac |
1526 |
done |
1527 |
|
1528 |
# create output string |
1529 |
output=`echo ":$opt_F" |\ |
1530 |
sed -e "s/^://" \ |
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" \ |
1555 |
-e 's/\\\\n/^/g' |\ |
1556 |
tr '^' '\012'` |
1557 |
|
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"` |
1563 |
fi |
1564 |
|
1565 |
# display output string |
1566 |
if [ ".$opt_n" = .yes ]; then |
1567 |
echo . | awk '{ printf("%s", output); }' output="$output" |
1568 |
else |
1569 |
echo "$output" |
1570 |
fi |
1571 |
|
1572 |
shtool_exit 0 |
1573 |
;; |
1574 |
|
1575 |
path ) |
1576 |
## |
1577 |
## path -- Deal with program paths |
1578 |
## Copyright (c) 1998-2006 Ralf S. Engelschall <rse@engelschall.com> |
1579 |
## |
1580 |
|
1581 |
namelist="$*" |
1582 |
|
1583 |
# check whether the test command supports the -x option |
1584 |
if [ -x /bin/sh ] 2>/dev/null; then |
1585 |
minusx="-x" |
1586 |
else |
1587 |
minusx="-r" |
1588 |
fi |
1589 |
|
1590 |
# split path string |
1591 |
paths="`echo $opt_p |\ |
1592 |
sed -e 's/^:/.:/' \ |
1593 |
-e 's/::/:.:/g' \ |
1594 |
-e 's/:$/:./' \ |
1595 |
-e 's/:/ /g'`" |
1596 |
|
1597 |
# SPECIAL REQUEST |
1598 |
# translate forward to reverse path |
1599 |
if [ ".$opt_r" = .yes ]; then |
1600 |
if [ "x$namelist" = "x." ]; then |
1601 |
rp='.' |
1602 |
else |
1603 |
rp='' |
1604 |
for pe in `IFS="$IFS/"; echo $namelist`; do |
1605 |
rp="../$rp" |
1606 |
done |
1607 |
fi |
1608 |
echo $rp | sed -e 's:/$::' |
1609 |
shtool_exit 0 |
1610 |
fi |
1611 |
|
1612 |
# SPECIAL REQUEST |
1613 |
# strip out directory or base name |
1614 |
if [ ".$opt_d" = .yes ]; then |
1615 |
echo "$namelist" |\ |
1616 |
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' |
1617 |
shtool_exit 0 |
1618 |
fi |
1619 |
if [ ".$opt_b" = .yes ]; then |
1620 |
echo "$namelist" |\ |
1621 |
sed -e 's;.*/\([^/]*\)$;\1;' |
1622 |
shtool_exit 0 |
1623 |
fi |
1624 |
|
1625 |
# MAGIC SITUATION |
1626 |
# Perl Interpreter (perl) |
1627 |
if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then |
1628 |
rm -f $tmpfile >/dev/null 2>&1 |
1629 |
touch $tmpfile |
1630 |
found=0 |
1631 |
pc=99 |
1632 |
for dir in $paths; do |
1633 |
dir=`echo $dir | sed -e 's;/*$;;'` |
1634 |
nc=99 |
1635 |
for name in perl perl5 miniperl; do |
1636 |
if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then |
1637 |
perl="$dir/$name" |
1638 |
pv=`$perl -e 'printf("%.3f", $]);'` |
1639 |
echo "$pv:$pc:$nc:$perl" >>$tmpfile |
1640 |
found=1 |
1641 |
fi |
1642 |
nc=`expr $nc - 1` |
1643 |
done |
1644 |
pc=`expr $pc - 1` |
1645 |
done |
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 |
1649 |
echo "$perl" |
1650 |
shtool_exit 0 |
1651 |
fi |
1652 |
rm -f $tmpfile >/dev/null 2>&1 |
1653 |
shtool_exit 1 |
1654 |
fi |
1655 |
|
1656 |
# MAGIC SITUATION |
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 |
1662 |
cpp="${CC-cc} -E" |
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 |
1675 |
cpp="$path/cpp" |
1676 |
break |
1677 |
fi |
1678 |
done |
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 |
1683 |
# ok, we gave up... |
1684 |
cpp='' |
1685 |
fi |
1686 |
fi |
1687 |
fi |
1688 |
fi |
1689 |
rm -f $tmpfile >/dev/null 2>&1 |
1690 |
rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1 |
1691 |
if [ ".$cpp" != . ]; then |
1692 |
echo "$cpp" |
1693 |
shtool_exit 0 |
1694 |
fi |
1695 |
shtool_exit 1 |
1696 |
fi |
1697 |
|
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 |
1706 |
echo "$path/$name" |
1707 |
fi |
1708 |
shtool_exit 0 |
1709 |
fi |
1710 |
done |
1711 |
done |
1712 |
|
1713 |
shtool_exit 1 |
1714 |
;; |
1715 |
|
1716 |
esac |
1717 |
|
1718 |
shtool_exit 0 |
1719 |
|