137
122
-d) dir_arg=true;;
139
124
-g) chgrpcmd="$chgrpprog $2"
142
127
--help) echo "$usage"; exit $?;;
147
'* | *'*'* | *'?'* | *'['*)
148
echo "$0: invalid mode: $mode" >&2
131
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
132
echo "$0: invalid mode: $mode" >&2
153
137
-o) chowncmd="$chownprog $2"
156
140
-s) stripcmd=$stripprog;;
159
# Protect names problematic for 'test' and other utilities.
161
-* | [=\(\)!]) dst_arg=./$dst_arg;;
143
is_target_a_directory=always
145
# Protect names problematic for 'test' and other utilities.
147
-* | [=\(\)!]) dst_arg=./$dst_arg;;
165
-T) no_target_directory=true;;
151
-T) is_target_a_directory=never;;
167
153
--version) echo "$0 $scriptversion"; exit $?;;
172
-*) echo "$0: invalid option: $1" >&2
158
-*) echo "$0: invalid option: $1" >&2
166
# We allow the use of options -d and -T together, by making -d
167
# take the precedence; this is for compatibility with GNU install.
169
if test -n "$dir_arg"; then
170
if test -n "$dst_arg"; then
171
echo "$0: target directory not allowed when installing a directory." >&2
180
176
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
181
177
# When -d is used, all remaining arguments are directories to create.
182
178
# When -t is used, the destination is already specified.
269
274
# If destination is a directory, append the input filename; won't work
270
275
# if double slashes aren't ignored.
271
276
if test -d "$dst"; then
272
if test -n "$no_target_directory"; then
273
echo "$0: $dst_arg: Is a directory" >&2
277
if test "$is_target_a_directory" = never; then
278
echo "$0: $dst_arg: Is a directory" >&2
277
282
dst=$dstdir/`basename "$src"`
280
# Prefer dirname, but fall back on a substitute if dirname fails.
282
(dirname "$dst") 2>/dev/null ||
283
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
284
X"$dst" : 'X\(//\)[^/]' \| \
285
X"$dst" : 'X\(//\)$' \| \
286
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
288
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
285
dstdir=`dirname "$dst"`
307
286
test -d "$dstdir"
314
293
if test $dstdir_status != 0; then
315
294
case $posix_mkdir in
317
# Create intermediate dirs using mode 755 as modified by the umask.
318
# This is like FreeBSD 'install' as of 1997-10-28.
320
case $stripcmd.$umask in
321
# Optimize common cases.
322
*[2367][2367]) mkdir_umask=$umask;;
323
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
326
mkdir_umask=`expr $umask + 22 \
327
- $umask % 100 % 40 + $umask % 20 \
328
- $umask % 10 % 4 + $umask % 2
330
*) mkdir_umask=$umask,go-w;;
333
# With -d, create the new directory with the user-specified mode.
334
# Otherwise, rely on $mkdir_umask.
335
if test -n "$dir_arg"; then
344
# POSIX mkdir -p sets u+wx bits regardless of umask, which
345
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
348
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
349
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
351
if (umask $mkdir_umask &&
352
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
354
if test -z "$dir_arg" || {
355
# Check for POSIX incompatibilities with -m.
356
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
357
# other-writable bit of parent directory when it shouldn't.
358
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
359
ls_ld_tmpdir=`ls -ld "$tmpdir"`
360
case $ls_ld_tmpdir in
361
d????-?r-*) different_mode=700;;
362
d????-?--*) different_mode=755;;
365
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
366
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
367
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
372
rmdir "$tmpdir/d" "$tmpdir"
374
# Remove any dirs left behind by ancient mkdir implementations.
375
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
296
# Create intermediate dirs using mode 755 as modified by the umask.
297
# This is like FreeBSD 'install' as of 1997-10-28.
299
case $stripcmd.$umask in
300
# Optimize common cases.
301
*[2367][2367]) mkdir_umask=$umask;;
302
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
305
mkdir_umask=`expr $umask + 22 \
306
- $umask % 100 % 40 + $umask % 20 \
307
- $umask % 10 % 4 + $umask % 2
309
*) mkdir_umask=$umask,go-w;;
312
# With -d, create the new directory with the user-specified mode.
313
# Otherwise, rely on $mkdir_umask.
314
if test -n "$dir_arg"; then
323
# POSIX mkdir -p sets u+wx bits regardless of umask, which
324
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
327
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
328
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
330
if (umask $mkdir_umask &&
331
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
333
if test -z "$dir_arg" || {
334
# Check for POSIX incompatibilities with -m.
335
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
336
# other-writable bit of parent directory when it shouldn't.
337
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
338
ls_ld_tmpdir=`ls -ld "$tmpdir"`
339
case $ls_ld_tmpdir in
340
d????-?r-*) different_mode=700;;
341
d????-?--*) different_mode=755;;
344
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
345
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
346
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
351
rmdir "$tmpdir/d" "$tmpdir"
353
# Remove any dirs left behind by ancient mkdir implementations.
354
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
382
361
$posix_mkdir && (
383
umask $mkdir_umask &&
384
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
362
umask $mkdir_umask &&
363
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
391
370
# directory the slow way, step by step, checking for races as we go.
395
[-=\(\)!]*) prefix='./';;
374
[-=\(\)!]*) prefix='./';;
399
eval "$initialize_posix_glob"
404
381
set fnord $dstdir
413
test X"$d" = X && continue
390
test X"$d" = X && continue
416
if test -d "$prefix"; then
419
if $posix_mkdir; then
420
(umask=$mkdir_umask &&
421
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
422
# Don't fail if two instances are running concurrently.
423
test -d "$prefix" || exit 1
426
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
429
prefixes="$prefixes '$qprefix'"
393
if test -d "$prefix"; then
396
if $posix_mkdir; then
397
(umask=$mkdir_umask &&
398
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
399
# Don't fail if two instances are running concurrently.
400
test -d "$prefix" || exit 1
403
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
406
prefixes="$prefixes '$qprefix'"
435
412
if test -n "$prefixes"; then
436
# Don't fail if two instances are running concurrently.
437
(umask $mkdir_umask &&
438
eval "\$doit_exec \$mkdirprog $prefixes") ||
439
test -d "$dstdir" || exit 1
440
obsolete_mkdir_used=true
413
# Don't fail if two instances are running concurrently.
414
(umask $mkdir_umask &&
415
eval "\$doit_exec \$mkdirprog $prefixes") ||
416
test -d "$dstdir" || exit 1
417
obsolete_mkdir_used=true
493
467
# to itself, or perhaps because mv is so ancient that it does not
496
# Now remove or move aside any old file at destination location.
497
# We try this two ways since rm can't unlink itself on some
498
# systems and the destination file might be busy for other
499
# reasons. In this case, the final cleanup might fail but the new
500
# file should still install successfully.
503
$doit $rmcmd -f "$dst" 2>/dev/null ||
504
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
505
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
507
{ echo "$0: cannot unlink or rename $dst" >&2
470
# Now remove or move aside any old file at destination location.
471
# We try this two ways since rm can't unlink itself on some
472
# systems and the destination file might be busy for other
473
# reasons. In this case, the final cleanup might fail but the new
474
# file should still install successfully.
477
$doit $rmcmd -f "$dst" 2>/dev/null ||
478
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
479
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
481
{ echo "$0: cannot unlink or rename $dst" >&2
512
# Now rename the file to the real destination.
513
$doit $mvcmd "$dsttmp" "$dst"
486
# Now rename the file to the real destination.
487
$doit $mvcmd "$dsttmp" "$dst"