Fix warnings.
[banana.git] / po / shtool
CommitLineData
4cc7f778 1#!/bin/sh
2##
3## GNU shtool -- The GNU Portable Shell Tool
4## Copyright (c) 1994-2000 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 1.4.9 (16-Apr-2000)
10## Ingredients: 3/17 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##
45## Not available commands (because module was not built-in):
46## mdate Pretty-print modification time of a file or dir
47## table Pretty-print a field-separated list as a table
48## prop Display progress with a running propeller
49## move Move files with simultaneous substitution
50## mkln Make link with calculation of relative paths
51## mkshadow Make a shadow tree through symbolic links
52## fixperm Fix file permissions inside a source tree
53## tarball Roll distribution tarballs
54## guessos Simple operating system guesser
55## arx Extended archive command
56## slo Separate linker options by library class
57## scpp Sharing C Pre-Processor
58## version Generate and maintain a version information file
59## path Deal with program paths
60##
61
62if [ $# -eq 0 ]; then
63 echo "$0:Error: invalid command line" 1>&2
64 echo "$0:Hint: run \`$0 -h' for usage" 1>&2
65 exit 1
66fi
67if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
68 echo "This is GNU shtool, version 1.4.9 (16-Apr-2000)"
69 echo "Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>"
70 echo "Report bugs to <bug-shtool@gnu.org>"
71 echo ''
72 echo "Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
73 echo ''
74 echo 'Available global <options>:'
75 echo ' -v, --version display shtool version information'
76 echo ' -h, --help display shtool usage help page (this one)'
77 echo ' -d, --debug display shell trace information'
78 echo ''
79 echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
80 echo ' echo [-n] [-e] [<str> ...]'
81 echo ' install [-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>]'
82 echo ' [-e<ext>] <file> <path>'
83 echo ' mkdir [-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]'
84 echo ''
85 echo 'Not available <cmd-name> (because module was not built-in):'
86 echo ' mdate [-n] [-z] [-s] [-d] [-f<str>] [-o<spec>] <path>'
87 echo ' table [-F<sep>] [-w<width>] [-c<cols>] [-s<strip>] <str><sep><str>...'
88 echo ' prop [-p<str>]'
89 echo ' move [-v] [-t] [-e] [-p] <src-file> <dst-file>'
90 echo ' mkln [-t] [-f] [-s] <src-path> [<src-path> ...] <dst-path>'
91 echo ' mkshadow [-v] [-t] [-a] <src-dir> <dst-dir>'
92 echo ' fixperm [-v] [-t] <path> [<path> ...]'
93 echo ' tarball [-t] [-v] [-o <tarball>] [-c <prog>] [-d <dir>] [-u'
94 echo ' <user>] [-g <group>] [-e <pattern>] <path> [<path> ...]'
95 echo ' guessos '
96 echo ' arx [-t] [-C<cmd>] <op> <archive> [<file> ...]'
97 echo ' slo [-p<str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]'
98 echo ' scpp [-v] [-p] [-f<filter>] [-o<ofile>] [-t<tfile>] [-M<mark>]'
99 echo ' [-D<dname>] [-C<cname>] <file> [<file> ...]'
100 echo ' version [-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-i<knob>]'
101 echo ' [-d<type>] <file>'
102 echo ' path [-s] [-r] [-d] [-b] [-m] [-p<path>] <str> [<str> ...]'
103 echo ''
104 exit 0
105fi
106if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
107 echo "GNU shtool 1.4.9 (16-Apr-2000)"
108 exit 0
109fi
110if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
111 shift
112 set -x
113fi
114name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
115case "$name" in
116 echo|install|mkdir )
117 # implicit tool command selection
118 tool="$name"
119 ;;
120 * )
121 # explicit tool command selection
122 tool="$1"
123 shift
124 ;;
125esac
126arg_spec=""
127opt_spec=""
128gen_tmpfile=no
129
130##
131## DISPATCH INTO SCRIPT PROLOG
132##
133
134case $tool in
135 echo )
136 str_tool="echo"
137 str_usage="[-n] [-e] [<str> ...]"
138 arg_spec="0+"
139 opt_spec="n.e."
140 opt_n=no
141 opt_e=no
142 ;;
143 install )
144 str_tool="install"
145 str_usage="[-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>] [-e<ext>] <file> <path>"
146 arg_spec="2="
147 opt_spec="v.t.c.C.s.m:o:g:e:"
148 opt_v=no
149 opt_t=no
150 opt_c=no
151 opt_C=no
152 opt_s=no
153 opt_m=""
154 opt_o=""
155 opt_g=""
156 opt_e=""
157 ;;
158 mkdir )
159 str_tool="mkdir"
160 str_usage="[-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]"
161 arg_spec="1+"
162 opt_spec="t.f.p.m:"
163 opt_t=no
164 opt_f=no
165 opt_p=no
166 opt_m=""
167 ;;
168 -* )
169 echo "$0:Error: unknown option \`$tool'" 2>&1
170 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
171 exit 1
172 ;;
173 * )
174 echo "$0:Error: unknown command \`$tool'" 2>&1
175 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
176 exit 1
177 ;;
178esac
179
180##
181## COMMON UTILITY CODE
182##
183
184# determine name of tool
185if [ ".$tool" != . ]; then
186 # used inside shtool script
187 toolcmd="$0 $tool"
188 toolcmdhelp="shtool $tool"
189 msgprefix="shtool:$tool"
190else
191 # used as standalone script
192 toolcmd="$0"
193 toolcmdhelp="sh $0"
194 msgprefix="$str_tool"
195fi
196
197# parse argument specification string
198eval `echo $arg_spec |\
199 sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
200
201# parse option specification string
202eval `echo h.$opt_spec |\
203 sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
204
205# interate over argument line
206opt_PREV=''
207while [ $# -gt 0 ]; do
208 # special option stops processing
209 if [ ".$1" = ".--" ]; then
210 shift
211 break
212 fi
213
214 # determine option and argument
215 opt_ARG_OK=no
216 if [ ".$opt_PREV" != . ]; then
217 # merge previous seen option with argument
218 opt_OPT="$opt_PREV"
219 opt_ARG="$1"
220 opt_ARG_OK=yes
221 opt_PREV=''
222 else
223 # split argument into option and argument
224 case "$1" in
225 -[a-zA-Z0-9]*)
226 eval `echo "x$1" |\
227 sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
228 -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
229 ;;
230 -[a-zA-Z0-9])
231 opt_OPT=`echo "x$1" | cut -c3-`
232 opt_ARG=''
233 ;;
234 *)
235 break
236 ;;
237 esac
238 fi
239
240 # eat up option
241 shift
242
243 # determine whether option needs an argument
244 eval "opt_MODE=\$opt_MODE_${opt_OPT}"
245 if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then
246 if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then
247 opt_PREV="$opt_OPT"
248 continue
249 fi
250 fi
251
252 # process option
253 case $opt_MODE in
254 '.' )
255 # boolean option
256 eval "opt_${opt_OPT}=yes"
257 ;;
258 ':' )
259 # option with argument (multiple occurances override)
260 eval "opt_${opt_OPT}=\"\$opt_ARG\""
261 ;;
262 '+' )
263 # option with argument (multiple occurances append)
264 eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\""
265 ;;
266 * )
267 echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2
268 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
269 exit 1
270 ;;
271 esac
272done
273if [ ".$opt_PREV" != . ]; then
274 echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2
275 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
276 exit 1
277fi
278
279# process help option
280if [ ".$opt_h" = .yes ]; then
281 echo "Usage: $toolcmdhelp $str_usage"
282 exit 0
283fi
284
285# complain about incorrect number of arguments
286case $arg_MODE in
287 '=' )
288 if [ $# -ne $arg_NUMS ]; then
289 echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
290 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
291 exit 1
292 fi
293 ;;
294 '+' )
295 if [ $# -lt $arg_NUMS ]; then
296 echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
297 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
298 exit 1
299 fi
300 ;;
301esac
302
303# establish a temporary file on request
304if [ ".$gen_tmpfile" = .yes ]; then
305 if [ ".$TMPDIR" != . ]; then
306 tmpdir="$TMPDIR"
307 elif [ ".$TEMPDIR" != . ]; then
308 tmpdir="$TEMPDIR"
309 else
310 tmpdir="/tmp"
311 fi
312 tmpfile="$tmpdir/.shtool.$$"
313 rm -f $tmpfile >/dev/null 2>&1
314 touch $tmpfile
315fi
316
317##
318## DISPATCH INTO SCRIPT BODY
319##
320
321case $tool in
322
323echo )
324 ##
325 ## echo -- Print string with optional construct expansion
326 ## Copyright (c) 1998-2000 Ralf S. Engelschall <rse@engelschall.com>
327 ## Originally written for WML as buildinfo
328 ##
329
330 text="$*"
331
332 # check for broken escape sequence expansion
333 seo=''
334 bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
335 if [ ".$bytes" != .3 ]; then
336 bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
337 if [ ".$bytes" = .3 ]; then
338 seo='-E'
339 fi
340 fi
341
342 # check for existing -n option (to suppress newline)
343 minusn=''
344 bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
345 if [ ".$bytes" = .3 ]; then
346 minusn='-n'
347 fi
348
349 # determine terminal bold sequence
350 term_bold=''
351 term_norm=''
352 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then
353 case $TERM in
354 # for the most important terminal types we directly know the sequences
355 xterm|xterm*|vt220|vt220*)
356 term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
357 term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
358 ;;
359 vt100|vt100*)
360 term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
361 term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
362 ;;
363 # for all others, we try to use a possibly existing `tput' or `tcout' utility
364 * )
365 paths=`echo $PATH | sed -e 's/:/ /g'`
366 for tool in tput tcout; do
367 for dir in $paths; do
368 if [ -r "$dir/$tool" ]; then
369 for seq in bold md smso; do # 'smso' is last
370 bold="`$dir/$tool $seq 2>/dev/null`"
371 if [ ".$bold" != . ]; then
372 term_bold="$bold"
373 break
374 fi
375 done
376 if [ ".$term_bold" != . ]; then
377 for seq in sgr0 me rmso reset; do # 'reset' is last
378 norm="`$dir/$tool $seq 2>/dev/null`"
379 if [ ".$norm" != . ]; then
380 term_norm="$norm"
381 break
382 fi
383 done
384 fi
385 break
386 fi
387 done
388 if [ ".$term_bold" != . -a ".$term_norm" != . ]; then
389 break;
390 fi
391 done
392 ;;
393 esac
394 if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
395 echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
396 fi
397 fi
398
399 # determine user name
400 username=''
401 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then
402 username="$LOGNAME"
403 if [ ".$username" = . ]; then
404 username="$USER"
405 if [ ".$username" = . ]; then
406 username="`(whoami) 2>/dev/null |\
407 awk '{ printf("%s", $1); }'`"
408 if [ ".$username" = . ]; then
409 username="`(who am i) 2>/dev/null |\
410 awk '{ printf("%s", $1); }'`"
411 if [ ".$username" = . ]; then
412 username='unknown'
413 fi
414 fi
415 fi
416 fi
417 fi
418
419 # determine user id
420 userid=''
421 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then
422 userid="`(id -u) 2>/dev/null`"
423 if [ ".$userid" = . ]; then
424 str="`(id) 2>/dev/null`"
425 if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
426 userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'`
427 fi
428 if [ ".$userid" = . ]; then
429 userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
430 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
431 if [ ".$userid" = . ]; then
432 userid=`(ypcat passwd) 2>/dev/null |
433 egrep "^${username}:" | \
434 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
435 if [ ".$userid" = . ]; then
436 userid='?'
437 fi
438 fi
439 fi
440 fi
441 fi
442
443 # determine host name
444 hostname=''
445 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%h'`" != . ]; then
446 hostname="`(uname -n) 2>/dev/null |\
447 awk '{ printf("%s", $1); }'`"
448 if [ ".$hostname" = . ]; then
449 hostname="`(hostname) 2>/dev/null |\
450 awk '{ printf("%s", $1); }'`"
451 if [ ".$hostname" = . ]; then
452 hostname='unknown'
453 fi
454 fi
455 case $hostname in
456 *.* )
457 domainname=".`echo $hostname | cut -d. -f2-`"
458 hostname="`echo $hostname | cut -d. -f1`"
459 ;;
460 esac
461 fi
462
463 # determine domain name
464 domainname=''
465 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then
466 if [ ".$domainname" = . ]; then
467 if [ -f /etc/resolv.conf ]; then
468 domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
469 sed -e 's/.*domain//' \
470 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
471 -e 's/^\.//' -e 's/^/./' |\
472 awk '{ printf("%s", $1); }'`"
473 if [ ".$domainname" = . ]; then
474 domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
475 sed -e 's/.*search//' \
476 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
477 -e 's/ .*//' -e 's/ .*//' \
478 -e 's/^\.//' -e 's/^/./' |\
479 awk '{ printf("%s", $1); }'`"
480 fi
481 fi
482 fi
483 fi
484
485 # determine current time
486 time_day=''
487 time_month=''
488 time_year=''
489 time_monthname=''
490 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then
491 time_day=`date '+%d'`
492 time_month=`date '+%m'`
493 time_year=`date '+%Y' 2>/dev/null`
494 if [ ".$time_year" = . ]; then
495 time_year=`date '+%y'`
496 case $time_year in
497 [5-9][0-9]) time_year="19$time_year" ;;
498 [0-4][0-9]) time_year="20$time_year" ;;
499 esac
500 fi
501 case $time_month in
502 1|01) time_monthname='Jan' ;;
503 2|02) time_monthname='Feb' ;;
504 3|03) time_monthname='Mar' ;;
505 4|04) time_monthname='Apr' ;;
506 5|05) time_monthname='May' ;;
507 6|06) time_monthname='Jun' ;;
508 7|07) time_monthname='Jul' ;;
509 8|08) time_monthname='Aug' ;;
510 9|09) time_monthname='Sep' ;;
511 10) time_monthname='Oct' ;;
512 11) time_monthname='Nov' ;;
513 12) time_monthname='Dec' ;;
514 esac
515 fi
516
517 # expand special ``%x'' constructs
518 if [ ".$opt_e" = .yes ]; then
519 text=`echo $seo "$text" |\
520 sed -e "s/%B/${term_bold}/g" \
521 -e "s/%b/${term_norm}/g" \
522 -e "s/%u/${username}/g" \
523 -e "s/%U/${userid}/g" \
524 -e "s/%h/${hostname}/g" \
525 -e "s/%d/${domainname}/g" \
526 -e "s/%D/${time_day}/g" \
527 -e "s/%M/${time_month}/g" \
528 -e "s/%Y/${time_year}/g" \
529 -e "s/%m/${time_monthname}/g" 2>/dev/null`
530 fi
531
532 # create output
533 if [ .$opt_n = .no ]; then
534 echo $seo "$text"
535 else
536 # the harder part: echo -n is best, because
537 # awk may complain about some \xx sequences.
538 if [ ".$minusn" != . ]; then
539 echo $seo $minusn "$text"
540 else
541 echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
542 fi
543 fi
544 ;;
545
546install )
547 ##
548 ## install -- Install a program, script or datafile
549 ## Copyright (c) 1997-2000 Ralf S. Engelschall <rse@engelschall.com>
550 ## Originally written for shtool
551 ##
552
553 src="$1"
554 dst="$2"
555
556 # If destination is a directory, append the input filename
557 if [ -d $dst ]; then
558 dst=`echo "$dst" | sed -e 's:/$::'`
559 dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
560 dst="$dst/$dstfile"
561 fi
562
563 # Add a possible extension to src and dst
564 if [ ".$opt_e" != . ]; then
565 src="$src$opt_e"
566 dst="$dst$opt_e"
567 fi
568
569 # Check for correct arguments
570 if [ ".$src" = ".$dst" ]; then
571 echo "$msgprefix:Error: source and destination are the same" 1>&2
572 exit 1
573 fi
574
575 # Make a temp file name in the destination directory
576 dstdir=`echo $dst | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
577 dsttmp="$dstdir/#INST@$$#"
578
579 # Verbosity
580 if [ ".$opt_v" = .yes ]; then
581 echo "$src -> $dst" 1>&2
582 fi
583
584 # Copy or move the file name to the temp name
585 # (because we might be not allowed to change the source)
586 if [ ".$opt_C" = .yes ]; then
587 opt_c=yes
588 fi
589 if [ ".$opt_c" = .yes ]; then
590 if [ ".$opt_t" = .yes ]; then
591 echo "cp $src $dsttmp" 1>&2
592 fi
593 cp $src $dsttmp || exit $?
594 else
595 if [ ".$opt_t" = .yes ]; then
596 echo "mv $src $dsttmp" 1>&2
597 fi
598 mv $src $dsttmp || exit $?
599 fi
600
601 # Adjust the target file
602 # (we do chmod last to preserve setuid bits)
603 if [ ".$opt_s" = .yes ]; then
604 if [ ".$opt_t" = .yes ]; then
605 echo "strip $dsttmp" 1>&2
606 fi
607 strip $dsttmp || exit $?
608 fi
609 if [ ".$opt_o" != . ]; then
610 if [ ".$opt_t" = .yes ]; then
611 echo "chown $opt_o $dsttmp" 1>&2
612 fi
613 chown $opt_o $dsttmp || exit $?
614 fi
615 if [ ".$opt_g" != . ]; then
616 if [ ".$opt_t" = .yes ]; then
617 echo "chgrp $opt_g $dsttmp" 1>&2
618 fi
619 chgrp $opt_g $dsttmp || exit $?
620 fi
621 if [ ".$opt_m" != . ]; then
622 if [ ".$opt_t" = .yes ]; then
623 echo "chmod $opt_m $dsttmp" 1>&2
624 fi
625 chmod $opt_m $dsttmp || exit $?
626 fi
627
628 # Determine whether to do a quick install
629 # (has to be done _after_ the strip was already done)
630 quick=no
631 if [ ".$opt_C" = .yes ]; then
632 if [ -r $dst ]; then
633 if cmp -s $src $dst; then
634 quick=yes
635 fi
636 fi
637 fi
638
639 # Finally install the file to the real destination
640 if [ $quick = yes ]; then
641 if [ ".$opt_t" = .yes ]; then
642 echo "rm -f $dsttmp" 1>&2
643 fi
644 rm -f $dsttmp
645 else
646 if [ ".$opt_t" = .yes ]; then
647 echo "rm -f $dst && mv $dsttmp $dst" 1>&2
648 fi
649 rm -f $dst && mv $dsttmp $dst
650 fi
651 ;;
652
653mkdir )
654 ##
655 ## mkdir -- Make one or more directories
656 ## Copyright (c) 1996-2000 Ralf S. Engelschall <rse@engelschall.com>
657 ## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>
658 ## Cleaned up and enhanced for shtool
659 ##
660
661 errstatus=0
662 for p in ${1+"$@"}; do
663 # if the directory already exists...
664 if [ -d "$p" ]; then
665 if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
666 echo "$msgprefix:Error: directory already exists: $p" 1>&2
667 errstatus=1
668 break
669 else
670 continue
671 fi
672 fi
673 # if the directory has to be created...
674 if [ ".$opt_p" = .no ]; then
675 if [ ".$opt_t" = .yes ]; then
676 echo "mkdir $p" 1>&2
677 fi
678 mkdir $p || errstatus=$?
679 else
680 # the smart situation
681 set fnord `echo ":$p" |\
682 sed -e 's/^:\//%/' \
683 -e 's/^://' \
684 -e 's/\// /g' \
685 -e 's/^%/\//'`
686 shift
687 pathcomp=''
688 for d in ${1+"$@"}; do
689 pathcomp="$pathcomp$d"
690 case "$pathcomp" in
691 -* ) pathcomp="./$pathcomp" ;;
692 esac
693 if [ ! -d "$pathcomp" ]; then
694 if [ ".$opt_t" = .yes ]; then
695 echo "mkdir $pathcomp" 1>&2
696 fi
697 mkdir $pathcomp || errstatus=$?
698 if [ ".$opt_m" != . ]; then
699 if [ ".$opt_t" = .yes ]; then
700 echo "chmod $opt_m $pathcomp" 1>&2
701 fi
702 chmod $opt_m $pathcomp || errstatus=$?
703 fi
704 fi
705 pathcomp="$pathcomp/"
706 done
707 fi
708 done
709 exit $errstatus
710 ;;
711
712esac
713
714exit 0
715
716##EOF##