1 |
gezelter |
1490 |
#!/bin/sh |
2 |
|
|
## |
3 |
|
|
## GNU shtool -- The GNU Portable Shell Tool |
4 |
|
|
## Copyright (c) 1994-2001 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.5.2 (27-Feb-2001) |
10 |
|
|
## Contents: 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 |
|
|
## install Install a program, script or datafile |
42 |
|
|
## mkdir Make one or more directories |
43 |
|
|
## mkshadow Make a shadow tree through symbolic links |
44 |
|
|
## |
45 |
|
|
## Not available commands (because module was not built-in): |
46 |
|
|
## echo Print string with optional construct expansion |
47 |
|
|
## mdate Pretty-print modification time of a file or dir |
48 |
|
|
## table Pretty-print a field-separated list as a table |
49 |
|
|
## prop Display progress with a running propeller |
50 |
|
|
## move Move files with simultaneous substitution |
51 |
|
|
## mkln Make link with calculation of relative paths |
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 Maintain a version information file |
59 |
|
|
## path Deal with program paths |
60 |
|
|
## |
61 |
|
|
|
62 |
|
|
if [ $# -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 |
66 |
|
|
fi |
67 |
|
|
if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then |
68 |
|
|
echo "This is GNU shtool, version 1.5.2 (27-Feb-2001)" |
69 |
|
|
echo "Copyright (c) 1994-2001 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 ' -r, --recreate recreate this shtool script via shtoolize' |
79 |
|
|
echo '' |
80 |
|
|
echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:' |
81 |
|
|
echo ' install [-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>]' |
82 |
|
|
echo ' [-e<sed-cmd>] <file> [<file> ...] <path>' |
83 |
|
|
echo ' mkdir [-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]' |
84 |
|
|
echo ' mkshadow [-v] [-t] [-a] <src-dir> <dst-dir>' |
85 |
|
|
echo '' |
86 |
|
|
echo 'Not available <cmd-name> (because module was not built-in):' |
87 |
|
|
echo ' echo [-n] [-e] [<str> ...]' |
88 |
|
|
echo ' mdate [-n] [-z] [-s] [-d] [-f<str>] [-o<spec>] <path>' |
89 |
|
|
echo ' table [-F<sep>] [-w<width>] [-c<cols>] [-s<strip>] <str><sep><str>...' |
90 |
|
|
echo ' prop [-p<str>]' |
91 |
|
|
echo ' move [-v] [-t] [-e] [-p] <src-file> <dst-file>' |
92 |
|
|
echo ' mkln [-t] [-f] [-s] <src-path> [<src-path> ...] <dst-path>' |
93 |
|
|
echo ' fixperm [-v] [-t] <path> [<path> ...]' |
94 |
|
|
echo ' tarball [-t] [-v] [-o <tarball>] [-c <prog>] [-d <dir>] [-u' |
95 |
|
|
echo ' <user>] [-g <group>] [-e <pattern>] <path> [<path> ...]' |
96 |
|
|
echo ' guessos ' |
97 |
|
|
echo ' arx [-t] [-C<cmd>] <op> <archive> [<file> ...]' |
98 |
|
|
echo ' slo [-p<str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]' |
99 |
|
|
echo ' scpp [-v] [-p] [-f<filter>] [-o<ofile>] [-t<tfile>] [-M<mark>]' |
100 |
|
|
echo ' [-D<dname>] [-C<cname>] <file> [<file> ...]' |
101 |
|
|
echo ' version [-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-e]' |
102 |
|
|
echo ' [-i<knob>] [-d<type>] <file>' |
103 |
|
|
echo ' path [-s] [-r] [-d] [-b] [-m] [-p<path>] <str> [<str> ...]' |
104 |
|
|
echo '' |
105 |
|
|
exit 0 |
106 |
|
|
fi |
107 |
|
|
if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then |
108 |
|
|
echo "GNU shtool 1.5.2 (27-Feb-2001)" |
109 |
|
|
exit 0 |
110 |
|
|
fi |
111 |
|
|
if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then |
112 |
|
|
shtoolize -oshtool install mkdir mkshadow |
113 |
|
|
exit 0 |
114 |
|
|
fi |
115 |
|
|
if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then |
116 |
|
|
shift |
117 |
|
|
set -x |
118 |
|
|
fi |
119 |
|
|
name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'` |
120 |
|
|
case "$name" in |
121 |
|
|
install|mkdir|mkshadow ) |
122 |
|
|
# implicit tool command selection |
123 |
|
|
tool="$name" |
124 |
|
|
;; |
125 |
|
|
* ) |
126 |
|
|
# explicit tool command selection |
127 |
|
|
tool="$1" |
128 |
|
|
shift |
129 |
|
|
;; |
130 |
|
|
esac |
131 |
|
|
arg_spec="" |
132 |
|
|
opt_spec="" |
133 |
|
|
gen_tmpfile=no |
134 |
|
|
|
135 |
|
|
## |
136 |
|
|
## DISPATCH INTO SCRIPT PROLOG |
137 |
|
|
## |
138 |
|
|
|
139 |
|
|
case $tool in |
140 |
|
|
install ) |
141 |
|
|
str_tool="install" |
142 |
|
|
str_usage="[-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>] [-e<sed-cmd>] <file> [<file> ...] <path>" |
143 |
|
|
arg_spec="2+" |
144 |
|
|
opt_spec="v.t.c.C.s.m:o:g:e+" |
145 |
|
|
opt_v=no |
146 |
|
|
opt_t=no |
147 |
|
|
opt_c=no |
148 |
|
|
opt_C=no |
149 |
|
|
opt_s=no |
150 |
|
|
opt_m="0755" |
151 |
|
|
opt_o="" |
152 |
|
|
opt_g="" |
153 |
|
|
opt_e="" |
154 |
|
|
;; |
155 |
|
|
mkdir ) |
156 |
|
|
str_tool="mkdir" |
157 |
|
|
str_usage="[-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]" |
158 |
|
|
arg_spec="1+" |
159 |
|
|
opt_spec="t.f.p.m:" |
160 |
|
|
opt_t=no |
161 |
|
|
opt_f=no |
162 |
|
|
opt_p=no |
163 |
|
|
opt_m="" |
164 |
|
|
;; |
165 |
|
|
mkshadow ) |
166 |
|
|
str_tool="mkshadow" |
167 |
|
|
str_usage="[-v] [-t] [-a] <src-dir> <dst-dir>" |
168 |
|
|
arg_spec="2=" |
169 |
|
|
opt_spec="v.t.a." |
170 |
|
|
opt_v=no |
171 |
|
|
opt_t=no |
172 |
|
|
opt_a=no |
173 |
|
|
;; |
174 |
|
|
-* ) |
175 |
|
|
echo "$0:Error: unknown option \`$tool'" 2>&1 |
176 |
|
|
echo "$0:Hint: run \`$0 -h' for usage" 2>&1 |
177 |
|
|
exit 1 |
178 |
|
|
;; |
179 |
|
|
* ) |
180 |
|
|
echo "$0:Error: unknown command \`$tool'" 2>&1 |
181 |
|
|
echo "$0:Hint: run \`$0 -h' for usage" 2>&1 |
182 |
|
|
exit 1 |
183 |
|
|
;; |
184 |
|
|
esac |
185 |
|
|
|
186 |
|
|
## |
187 |
|
|
## COMMON UTILITY CODE |
188 |
|
|
## |
189 |
|
|
|
190 |
|
|
# determine name of tool |
191 |
|
|
if [ ".$tool" != . ]; then |
192 |
|
|
# used inside shtool script |
193 |
|
|
toolcmd="$0 $tool" |
194 |
|
|
toolcmdhelp="shtool $tool" |
195 |
|
|
msgprefix="shtool:$tool" |
196 |
|
|
else |
197 |
|
|
# used as standalone script |
198 |
|
|
toolcmd="$0" |
199 |
|
|
toolcmdhelp="sh $0" |
200 |
|
|
msgprefix="$str_tool" |
201 |
|
|
fi |
202 |
|
|
|
203 |
|
|
# parse argument specification string |
204 |
|
|
eval `echo $arg_spec |\ |
205 |
|
|
sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
206 |
|
|
|
207 |
|
|
# parse option specification string |
208 |
|
|
eval `echo h.$opt_spec |\ |
209 |
|
|
sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
210 |
|
|
|
211 |
|
|
# interate over argument line |
212 |
|
|
opt_PREV='' |
213 |
|
|
while [ $# -gt 0 ]; do |
214 |
|
|
# special option stops processing |
215 |
|
|
if [ ".$1" = ".--" ]; then |
216 |
|
|
shift |
217 |
|
|
break |
218 |
|
|
fi |
219 |
|
|
|
220 |
|
|
# determine option and argument |
221 |
|
|
opt_ARG_OK=no |
222 |
|
|
if [ ".$opt_PREV" != . ]; then |
223 |
|
|
# merge previous seen option with argument |
224 |
|
|
opt_OPT="$opt_PREV" |
225 |
|
|
opt_ARG="$1" |
226 |
|
|
opt_ARG_OK=yes |
227 |
|
|
opt_PREV='' |
228 |
|
|
else |
229 |
|
|
# split argument into option and argument |
230 |
|
|
case "$1" in |
231 |
|
|
-[a-zA-Z0-9]*) |
232 |
|
|
eval `echo "x$1" |\ |
233 |
|
|
sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
234 |
|
|
-e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
235 |
|
|
;; |
236 |
|
|
-[a-zA-Z0-9]) |
237 |
|
|
opt_OPT=`echo "x$1" | cut -c3-` |
238 |
|
|
opt_ARG='' |
239 |
|
|
;; |
240 |
|
|
*) |
241 |
|
|
break |
242 |
|
|
;; |
243 |
|
|
esac |
244 |
|
|
fi |
245 |
|
|
|
246 |
|
|
# eat up option |
247 |
|
|
shift |
248 |
|
|
|
249 |
|
|
# determine whether option needs an argument |
250 |
|
|
eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
251 |
|
|
if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then |
252 |
|
|
if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then |
253 |
|
|
opt_PREV="$opt_OPT" |
254 |
|
|
continue |
255 |
|
|
fi |
256 |
|
|
fi |
257 |
|
|
|
258 |
|
|
# process option |
259 |
|
|
case $opt_MODE in |
260 |
|
|
'.' ) |
261 |
|
|
# boolean option |
262 |
|
|
eval "opt_${opt_OPT}=yes" |
263 |
|
|
;; |
264 |
|
|
':' ) |
265 |
|
|
# option with argument (multiple occurances override) |
266 |
|
|
eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
267 |
|
|
;; |
268 |
|
|
'+' ) |
269 |
|
|
# option with argument (multiple occurances append) |
270 |
|
|
eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" |
271 |
|
|
;; |
272 |
|
|
* ) |
273 |
|
|
echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2 |
274 |
|
|
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 |
275 |
|
|
exit 1 |
276 |
|
|
;; |
277 |
|
|
esac |
278 |
|
|
done |
279 |
|
|
if [ ".$opt_PREV" != . ]; then |
280 |
|
|
echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2 |
281 |
|
|
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 |
282 |
|
|
exit 1 |
283 |
|
|
fi |
284 |
|
|
|
285 |
|
|
# process help option |
286 |
|
|
if [ ".$opt_h" = .yes ]; then |
287 |
|
|
echo "Usage: $toolcmdhelp $str_usage" |
288 |
|
|
exit 0 |
289 |
|
|
fi |
290 |
|
|
|
291 |
|
|
# complain about incorrect number of arguments |
292 |
|
|
case $arg_MODE in |
293 |
|
|
'=' ) |
294 |
|
|
if [ $# -ne $arg_NUMS ]; then |
295 |
|
|
echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
296 |
|
|
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 |
297 |
|
|
exit 1 |
298 |
|
|
fi |
299 |
|
|
;; |
300 |
|
|
'+' ) |
301 |
|
|
if [ $# -lt $arg_NUMS ]; then |
302 |
|
|
echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
303 |
|
|
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 |
304 |
|
|
exit 1 |
305 |
|
|
fi |
306 |
|
|
;; |
307 |
|
|
esac |
308 |
|
|
|
309 |
|
|
# establish a temporary file on request |
310 |
|
|
if [ ".$gen_tmpfile" = .yes ]; then |
311 |
|
|
if [ ".$TMPDIR" != . ]; then |
312 |
|
|
tmpdir="$TMPDIR" |
313 |
|
|
elif [ ".$TEMPDIR" != . ]; then |
314 |
|
|
tmpdir="$TEMPDIR" |
315 |
|
|
else |
316 |
|
|
tmpdir="/tmp" |
317 |
|
|
fi |
318 |
|
|
tmpfile="$tmpdir/.shtool.$$" |
319 |
|
|
rm -f $tmpfile >/dev/null 2>&1 |
320 |
|
|
touch $tmpfile |
321 |
|
|
chmod 600 $tmpfile |
322 |
|
|
fi |
323 |
|
|
|
324 |
|
|
## |
325 |
|
|
## DISPATCH INTO SCRIPT BODY |
326 |
|
|
## |
327 |
|
|
|
328 |
|
|
case $tool in |
329 |
|
|
|
330 |
|
|
install ) |
331 |
|
|
## |
332 |
|
|
## install -- Install a program, script or datafile |
333 |
|
|
## Copyright (c) 1997-2001 Ralf S. Engelschall <rse@engelschall.com> |
334 |
|
|
## Originally written for shtool |
335 |
|
|
## |
336 |
|
|
|
337 |
|
|
# determine source(s) and destination |
338 |
|
|
argc=$# |
339 |
|
|
srcs="" |
340 |
|
|
while [ $# -gt 1 ]; do |
341 |
|
|
srcs="$srcs $1" |
342 |
|
|
shift |
343 |
|
|
done |
344 |
|
|
dstpath="$1" |
345 |
|
|
|
346 |
|
|
# type check for destination |
347 |
|
|
dstisdir=0 |
348 |
|
|
if [ -d $dstpath ]; then |
349 |
|
|
dstpath=`echo "$dstpath" | sed -e 's:/$::'` |
350 |
|
|
dstisdir=1 |
351 |
|
|
fi |
352 |
|
|
|
353 |
|
|
# consistency check for destination |
354 |
|
|
if [ $argc -gt 2 -a $dstisdir = 0 ]; then |
355 |
|
|
echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2 |
356 |
|
|
exit 1 |
357 |
|
|
fi |
358 |
|
|
|
359 |
|
|
# iterate over all source(s) |
360 |
|
|
for src in $srcs; do |
361 |
|
|
dst=$dstpath |
362 |
|
|
|
363 |
|
|
# if destination is a directory, append the input filename |
364 |
|
|
if [ $dstisdir = 1 ]; then |
365 |
|
|
dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'` |
366 |
|
|
dst="$dst/$dstfile" |
367 |
|
|
fi |
368 |
|
|
|
369 |
|
|
# check for correct arguments |
370 |
|
|
if [ ".$src" = ".$dst" ]; then |
371 |
|
|
echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2 |
372 |
|
|
continue |
373 |
|
|
fi |
374 |
|
|
if [ -d "$src" ]; then |
375 |
|
|
echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2 |
376 |
|
|
continue |
377 |
|
|
fi |
378 |
|
|
|
379 |
|
|
# make a temp file name in the destination directory |
380 |
|
|
dsttmp=`echo $dst |\ |
381 |
|
|
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \ |
382 |
|
|
-e "s;\$;/#INST@$$#;"` |
383 |
|
|
|
384 |
|
|
# verbosity |
385 |
|
|
if [ ".$opt_v" = .yes ]; then |
386 |
|
|
echo "$src -> $dst" 1>&2 |
387 |
|
|
fi |
388 |
|
|
|
389 |
|
|
# copy or move the file name to the temp name |
390 |
|
|
# (because we might be not allowed to change the source) |
391 |
|
|
if [ ".$opt_C" = .yes ]; then |
392 |
|
|
opt_c=yes |
393 |
|
|
fi |
394 |
|
|
if [ ".$opt_c" = .yes ]; then |
395 |
|
|
if [ ".$opt_t" = .yes ]; then |
396 |
|
|
echo "cp $src $dsttmp" 1>&2 |
397 |
|
|
fi |
398 |
|
|
cp $src $dsttmp || exit $? |
399 |
|
|
else |
400 |
|
|
if [ ".$opt_t" = .yes ]; then |
401 |
|
|
echo "mv $src $dsttmp" 1>&2 |
402 |
|
|
fi |
403 |
|
|
mv $src $dsttmp || exit $? |
404 |
|
|
fi |
405 |
|
|
|
406 |
|
|
# adjust the target file |
407 |
|
|
if [ ".$opt_e" != . ]; then |
408 |
|
|
sed='sed' |
409 |
|
|
for e in $opt_e; do |
410 |
|
|
sed="$sed -e '$e'" |
411 |
|
|
done |
412 |
|
|
cp $dsttmp $dsttmp.old |
413 |
|
|
eval "$sed <$dsttmp.old >$dsttmp" || exit $? |
414 |
|
|
rm -f $dsttmp.old |
415 |
|
|
fi |
416 |
|
|
if [ ".$opt_s" = .yes ]; then |
417 |
|
|
if [ ".$opt_t" = .yes ]; then |
418 |
|
|
echo "strip $dsttmp" 1>&2 |
419 |
|
|
fi |
420 |
|
|
strip $dsttmp || exit $? |
421 |
|
|
fi |
422 |
|
|
if [ ".$opt_o" != . ]; then |
423 |
|
|
if [ ".$opt_t" = .yes ]; then |
424 |
|
|
echo "chown $opt_o $dsttmp" 1>&2 |
425 |
|
|
fi |
426 |
|
|
chown $opt_o $dsttmp || exit $? |
427 |
|
|
fi |
428 |
|
|
if [ ".$opt_g" != . ]; then |
429 |
|
|
if [ ".$opt_t" = .yes ]; then |
430 |
|
|
echo "chgrp $opt_g $dsttmp" 1>&2 |
431 |
|
|
fi |
432 |
|
|
chgrp $opt_g $dsttmp || exit $? |
433 |
|
|
fi |
434 |
|
|
if [ ".$opt_m" != ".-" ]; then |
435 |
|
|
if [ ".$opt_t" = .yes ]; then |
436 |
|
|
echo "chmod $opt_m $dsttmp" 1>&2 |
437 |
|
|
fi |
438 |
|
|
chmod $opt_m $dsttmp || exit $? |
439 |
|
|
fi |
440 |
|
|
|
441 |
|
|
# determine whether to do a quick install |
442 |
|
|
# (has to be done _after_ the strip was already done) |
443 |
|
|
quick=no |
444 |
|
|
if [ ".$opt_C" = .yes ]; then |
445 |
|
|
if [ -r $dst ]; then |
446 |
|
|
if cmp -s $src $dst; then |
447 |
|
|
quick=yes |
448 |
|
|
fi |
449 |
|
|
fi |
450 |
|
|
fi |
451 |
|
|
|
452 |
|
|
# finally, install the file to the real destination |
453 |
|
|
if [ $quick = yes ]; then |
454 |
|
|
if [ ".$opt_t" = .yes ]; then |
455 |
|
|
echo "rm -f $dsttmp" 1>&2 |
456 |
|
|
fi |
457 |
|
|
rm -f $dsttmp |
458 |
|
|
else |
459 |
|
|
if [ ".$opt_t" = .yes ]; then |
460 |
|
|
echo "rm -f $dst && mv $dsttmp $dst" 1>&2 |
461 |
|
|
fi |
462 |
|
|
rm -f $dst && mv $dsttmp $dst |
463 |
|
|
fi |
464 |
|
|
done |
465 |
|
|
;; |
466 |
|
|
|
467 |
|
|
mkdir ) |
468 |
|
|
## |
469 |
|
|
## mkdir -- Make one or more directories |
470 |
|
|
## Copyright (c) 1996-2001 Ralf S. Engelschall <rse@engelschall.com> |
471 |
|
|
## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu> |
472 |
|
|
## Cleaned up and enhanced for shtool |
473 |
|
|
## |
474 |
|
|
|
475 |
|
|
errstatus=0 |
476 |
|
|
for p in ${1+"$@"}; do |
477 |
|
|
# if the directory already exists... |
478 |
|
|
if [ -d "$p" ]; then |
479 |
|
|
if [ ".$opt_f" = .no -a ".$opt_p" = .no ]; then |
480 |
|
|
echo "$msgprefix:Error: directory already exists: $p" 1>&2 |
481 |
|
|
errstatus=1 |
482 |
|
|
break |
483 |
|
|
else |
484 |
|
|
continue |
485 |
|
|
fi |
486 |
|
|
fi |
487 |
|
|
# if the directory has to be created... |
488 |
|
|
if [ ".$opt_p" = .no ]; then |
489 |
|
|
if [ ".$opt_t" = .yes ]; then |
490 |
|
|
echo "mkdir $p" 1>&2 |
491 |
|
|
fi |
492 |
|
|
mkdir $p || errstatus=$? |
493 |
|
|
else |
494 |
|
|
# the smart situation |
495 |
|
|
set fnord `echo ":$p" |\ |
496 |
|
|
sed -e 's/^:\//%/' \ |
497 |
|
|
-e 's/^://' \ |
498 |
|
|
-e 's/\// /g' \ |
499 |
|
|
-e 's/^%/\//'` |
500 |
|
|
shift |
501 |
|
|
pathcomp='' |
502 |
|
|
for d in ${1+"$@"}; do |
503 |
|
|
pathcomp="$pathcomp$d" |
504 |
|
|
case "$pathcomp" in |
505 |
|
|
-* ) pathcomp="./$pathcomp" ;; |
506 |
|
|
esac |
507 |
|
|
if [ ! -d "$pathcomp" ]; then |
508 |
|
|
if [ ".$opt_t" = .yes ]; then |
509 |
|
|
echo "mkdir $pathcomp" 1>&2 |
510 |
|
|
fi |
511 |
|
|
mkdir $pathcomp || errstatus=$? |
512 |
|
|
if [ ".$opt_m" != . ]; then |
513 |
|
|
if [ ".$opt_t" = .yes ]; then |
514 |
|
|
echo "chmod $opt_m $pathcomp" 1>&2 |
515 |
|
|
fi |
516 |
|
|
chmod $opt_m $pathcomp || errstatus=$? |
517 |
|
|
fi |
518 |
|
|
fi |
519 |
|
|
pathcomp="$pathcomp/" |
520 |
|
|
done |
521 |
|
|
fi |
522 |
|
|
done |
523 |
|
|
exit $errstatus |
524 |
|
|
;; |
525 |
|
|
|
526 |
|
|
mkshadow ) |
527 |
|
|
## |
528 |
|
|
## mkshadow -- Make a shadow tree through symbolic links |
529 |
|
|
## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com> |
530 |
|
|
## Originally written for Apache |
531 |
|
|
## |
532 |
|
|
|
533 |
|
|
# source and destination directory |
534 |
|
|
src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
535 |
|
|
dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
536 |
|
|
|
537 |
|
|
# check whether source exists |
538 |
|
|
if [ ! -d $src ]; then |
539 |
|
|
echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2 |
540 |
|
|
exit 1 |
541 |
|
|
fi |
542 |
|
|
|
543 |
|
|
# determine if one of the paths is an absolute path, |
544 |
|
|
# because then we have to use an absolute symlink |
545 |
|
|
oneisabs=0 |
546 |
|
|
case $src in |
547 |
|
|
/* ) oneisabs=1 ;; |
548 |
|
|
esac |
549 |
|
|
case $dst in |
550 |
|
|
/* ) oneisabs=1 ;; |
551 |
|
|
esac |
552 |
|
|
|
553 |
|
|
# determine reverse directory for destination directory |
554 |
|
|
dstrevdir='' |
555 |
|
|
if [ $oneisabs = 0 ]; then |
556 |
|
|
# derive reverse path from forward path |
557 |
|
|
pwd=`pwd` |
558 |
|
|
OIFS="$IFS"; IFS='/' |
559 |
|
|
for pe in $dst; do |
560 |
|
|
if [ "x$pe" = "x.." ]; then |
561 |
|
|
OIFS2="$IFS"; IFS="$DIFS" |
562 |
|
|
eval `echo "$pwd" |\ |
563 |
|
|
sed -e 's:\([^/]*\)$:; dir="\1":' \ |
564 |
|
|
-e 's:^\(.*\)/[^/]*;:pwd="\1";:'\ |
565 |
|
|
-e 's:^;:pwd="";:'` |
566 |
|
|
dstrevdir="$dir/$dstrevdir" |
567 |
|
|
IFS="$OIFS2" |
568 |
|
|
else |
569 |
|
|
dstrevdir="../$dstrevdir" |
570 |
|
|
fi |
571 |
|
|
done |
572 |
|
|
IFS="$OIFS" |
573 |
|
|
else |
574 |
|
|
src="`cd $src; pwd`"; |
575 |
|
|
fi |
576 |
|
|
|
577 |
|
|
# create directory tree at destination |
578 |
|
|
if [ ! -d $dst ]; then |
579 |
|
|
if [ ".$opt_t" = .yes ]; then |
580 |
|
|
echo "mkdir $dst" 1>&2 |
581 |
|
|
fi |
582 |
|
|
mkdir $dst |
583 |
|
|
fi |
584 |
|
|
if [ ".$opt_a" = .yes ]; then |
585 |
|
|
DIRS=`cd $src; find . -type d -print |\ |
586 |
|
|
sed -e '/^\.$/d' -e 's:^\./::'` |
587 |
|
|
else |
588 |
|
|
DIRS=`cd $src; find . -type d -print |\ |
589 |
|
|
sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'` |
590 |
|
|
fi |
591 |
|
|
for dir in $DIRS; do |
592 |
|
|
if [ ".$opt_t" = .yes ]; then |
593 |
|
|
echo "mkdir $dst/$dir" 1>&2 |
594 |
|
|
fi |
595 |
|
|
mkdir $dst/$dir |
596 |
|
|
done |
597 |
|
|
|
598 |
|
|
# fill directory tree with symlinks to files |
599 |
|
|
if [ ".$opt_a" = .yes ]; then |
600 |
|
|
FILES="`cd $src; find . -depth -print |\ |
601 |
|
|
sed -e 's/^\.\///'`" |
602 |
|
|
else |
603 |
|
|
FILES="`cd $src; find . -depth -print |\ |
604 |
|
|
sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \ |
605 |
|
|
-e '/\.cvsignore$/d' -e '/\/CVS/d' \ |
606 |
|
|
-e '/\/\.#/d' -e '/\.orig$/d' \ |
607 |
|
|
-e 's/^\.\///'`" |
608 |
|
|
fi |
609 |
|
|
for file in $FILES; do |
610 |
|
|
# don't use `-type f' above for find because of symlinks |
611 |
|
|
if [ -d "$src/$file" ]; then |
612 |
|
|
continue |
613 |
|
|
fi |
614 |
|
|
basename=`echo $file | sed -e 's:^.*/::'` |
615 |
|
|
dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'` |
616 |
|
|
from=`echo "$src/$file" | sed -e 's/^\.\///'` |
617 |
|
|
to="$dst/$dir$basename" |
618 |
|
|
if [ $oneisabs = 0 ]; then |
619 |
|
|
if [ ".$dir" != . ]; then |
620 |
|
|
subdir=`echo $dir | sed -e 's:/$::'` |
621 |
|
|
# derive reverse path from forward path |
622 |
|
|
revdir='' |
623 |
|
|
OIFS="$IFS"; IFS='/' |
624 |
|
|
for pe in $subdir; do |
625 |
|
|
revdir="../$revdir" |
626 |
|
|
done |
627 |
|
|
IFS="$OIFS" |
628 |
|
|
# finalize from |
629 |
|
|
from="$revdir$from" |
630 |
|
|
fi |
631 |
|
|
from="$dstrevdir$from" |
632 |
|
|
fi |
633 |
|
|
if [ ".$opt_v" = .yes ]; then |
634 |
|
|
echo " $to" 1>&2 |
635 |
|
|
fi |
636 |
|
|
if [ ".$opt_t" = .yes ]; then |
637 |
|
|
echo "ln -s $from $to" 1>&2 |
638 |
|
|
fi |
639 |
|
|
ln -s $from $to |
640 |
|
|
done |
641 |
|
|
;; |
642 |
|
|
|
643 |
|
|
esac |
644 |
|
|
|
645 |
|
|
exit 0 |
646 |
|
|
|
647 |
|
|
##EOF## |