| 1 |
|
#!/bin/sh |
| 2 |
|
# install - install a program, script, or datafile |
| 3 |
|
|
| 4 |
< |
scriptversion=2016-01-11.22; # UTC |
| 4 |
> |
scriptversion=2018-03-11.20; # UTC |
| 5 |
|
|
| 6 |
|
# This originates from X11R5 (mit/util/scripts/install.sh), which was |
| 7 |
|
# later released in X11R6 (xc/config/util/install.sh) with the |
| 271 |
|
fi |
| 272 |
|
dst=$dst_arg |
| 273 |
|
|
| 274 |
< |
# If destination is a directory, append the input filename; won't work |
| 275 |
< |
# if double slashes aren't ignored. |
| 274 |
> |
# If destination is a directory, append the input filename. |
| 275 |
|
if test -d "$dst"; then |
| 276 |
|
if test "$is_target_a_directory" = never; then |
| 277 |
|
echo "$0: $dst_arg: Is a directory" >&2 |
| 278 |
|
exit 1 |
| 279 |
|
fi |
| 280 |
|
dstdir=$dst |
| 281 |
< |
dst=$dstdir/`basename "$src"` |
| 281 |
> |
dstbase=`basename "$src"` |
| 282 |
> |
case $dst in |
| 283 |
> |
*/) dst=$dst$dstbase;; |
| 284 |
> |
*) dst=$dst/$dstbase;; |
| 285 |
> |
esac |
| 286 |
|
dstdir_status=0 |
| 287 |
|
else |
| 288 |
|
dstdir=`dirname "$dst"` |
| 291 |
|
fi |
| 292 |
|
fi |
| 293 |
|
|
| 294 |
+ |
case $dstdir in |
| 295 |
+ |
*/) dstdirslash=$dstdir;; |
| 296 |
+ |
*) dstdirslash=$dstdir/;; |
| 297 |
+ |
esac |
| 298 |
+ |
|
| 299 |
|
obsolete_mkdir_used=false |
| 300 |
|
|
| 301 |
|
if test $dstdir_status != 0; then |
| 332 |
|
# is incompatible with FreeBSD 'install' when (umask & 300) != 0. |
| 333 |
|
;; |
| 334 |
|
*) |
| 335 |
+ |
# Note that $RANDOM variable is not portable (e.g. dash); Use it |
| 336 |
+ |
# here however when possible just to lower collision chance. |
| 337 |
|
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ |
| 328 |
– |
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 |
| 338 |
|
|
| 339 |
+ |
trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 |
| 340 |
+ |
|
| 341 |
+ |
# Because "mkdir -p" follows existing symlinks and we likely work |
| 342 |
+ |
# directly in world-writeable /tmp, make sure that the '$tmpdir' |
| 343 |
+ |
# directory is successfully created first before we actually test |
| 344 |
+ |
# 'mkdir -p' feature. |
| 345 |
|
if (umask $mkdir_umask && |
| 346 |
< |
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 |
| 346 |
> |
$mkdirprog $mkdir_mode "$tmpdir" && |
| 347 |
> |
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 |
| 348 |
|
then |
| 349 |
|
if test -z "$dir_arg" || { |
| 350 |
|
# Check for POSIX incompatibilities with -m. |
| 351 |
|
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or |
| 352 |
|
# other-writable bit of parent directory when it shouldn't. |
| 353 |
|
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory. |
| 354 |
< |
ls_ld_tmpdir=`ls -ld "$tmpdir"` |
| 354 |
> |
test_tmpdir="$tmpdir/a" |
| 355 |
> |
ls_ld_tmpdir=`ls -ld "$test_tmpdir"` |
| 356 |
|
case $ls_ld_tmpdir in |
| 357 |
|
d????-?r-*) different_mode=700;; |
| 358 |
|
d????-?--*) different_mode=755;; |
| 359 |
|
*) false;; |
| 360 |
|
esac && |
| 361 |
< |
$mkdirprog -m$different_mode -p -- "$tmpdir" && { |
| 362 |
< |
ls_ld_tmpdir_1=`ls -ld "$tmpdir"` |
| 361 |
> |
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && { |
| 362 |
> |
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` |
| 363 |
|
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" |
| 364 |
|
} |
| 365 |
|
} |
| 366 |
|
then posix_mkdir=: |
| 367 |
|
fi |
| 368 |
< |
rmdir "$tmpdir/d" "$tmpdir" |
| 368 |
> |
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" |
| 369 |
|
else |
| 370 |
|
# Remove any dirs left behind by ancient mkdir implementations. |
| 371 |
< |
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null |
| 371 |
> |
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null |
| 372 |
|
fi |
| 373 |
|
trap '' 0;; |
| 374 |
|
esac;; |
| 444 |
|
else |
| 445 |
|
|
| 446 |
|
# Make a couple of temp file names in the proper directory. |
| 447 |
< |
dsttmp=$dstdir/_inst.$$_ |
| 448 |
< |
rmtmp=$dstdir/_rm.$$_ |
| 447 |
> |
dsttmp=${dstdirslash}_inst.$$_ |
| 448 |
> |
rmtmp=${dstdirslash}_rm.$$_ |
| 449 |
|
|
| 450 |
|
# Trap to clean up those temp files at exit. |
| 451 |
|
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 |
| 510 |
|
done |
| 511 |
|
|
| 512 |
|
# Local variables: |
| 513 |
< |
# eval: (add-hook 'write-file-hooks 'time-stamp) |
| 513 |
> |
# eval: (add-hook 'before-save-hook 'time-stamp) |
| 514 |
|
# time-stamp-start: "scriptversion=" |
| 515 |
|
# time-stamp-format: "%:y-%02m-%02d.%02H" |
| 516 |
|
# time-stamp-time-zone: "UTC0" |