ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.1.x/install-sh
(Generate patch)

Comparing hopm/branches/1.1.x/install-sh (file contents):
Revision 8552 by michael, Sat Sep 22 20:56:36 2018 UTC vs.
Revision 10103 by michael, Sun Jun 12 08:35:13 2022 UTC

# Line 1 | Line 1
1   #!/bin/sh
2   # install - install a program, script, or datafile
3  
4 < scriptversion=2016-01-11.22; # UTC
4 > scriptversion=2020-11-14.01; # 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
# Line 69 | Line 69 | posix_mkdir=
69   # Desired mode of installed file.
70   mode=0755
71  
72 + # Create dirs (including intermediate dirs) using mode 755.
73 + # This is like GNU 'install' as of coreutils 8.32 (2020).
74 + mkdir_umask=22
75 +
76 + backupsuffix=
77   chgrpcmd=
78   chmodcmd=$chmodprog
79   chowncmd=
# Line 99 | Line 104 | Options:
104       --version  display version info and exit.
105  
106    -c            (ignored)
107 <  -C            install only if different (preserve the last data modification time)
107 >  -C            install only if different (preserve data modification time)
108    -d            create directories instead of installing files.
109    -g GROUP      $chgrpprog installed files to GROUP.
110    -m MODE       $chmodprog installed files to MODE.
111    -o USER       $chownprog installed files to USER.
112 +  -p            pass -p to $cpprog.
113    -s            $stripprog installed files.
114 +  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
115    -t DIRECTORY  install into DIRECTORY.
116    -T            report an error if DSTFILE is a directory.
117  
118   Environment variables override the default commands:
119    CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
120    RMPROG STRIPPROG
121 +
122 + By default, rm is invoked with -f; when overridden with RMPROG,
123 + it's up to you to specify -f if you want it.
124 +
125 + If -S is not specified, no backups are attempted.
126 +
127 + Email bug reports to bug-automake@gnu.org.
128 + Automake home page: https://www.gnu.org/software/automake/
129   "
130  
131   while test $# -ne 0; do
# Line 137 | Line 152 | while test $# -ne 0; do
152      -o) chowncmd="$chownprog $2"
153          shift;;
154  
155 +    -p) cpprog="$cpprog -p";;
156 +
157      -s) stripcmd=$stripprog;;
158  
159 +    -S) backupsuffix="$2"
160 +        shift;;
161 +
162      -t)
163          is_target_a_directory=always
164          dst_arg=$2
# Line 255 | Line 275 | do
275      dstdir=$dst
276      test -d "$dstdir"
277      dstdir_status=$?
278 +    # Don't chown directories that already exist.
279 +    if test $dstdir_status = 0; then
280 +      chowncmd=""
281 +    fi
282    else
283  
284      # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# Line 271 | Line 295 | do
295      fi
296      dst=$dst_arg
297  
298 <    # If destination is a directory, append the input filename; won't work
275 <    # if double slashes aren't ignored.
298 >    # If destination is a directory, append the input filename.
299      if test -d "$dst"; then
300        if test "$is_target_a_directory" = never; then
301          echo "$0: $dst_arg: Is a directory" >&2
302          exit 1
303        fi
304        dstdir=$dst
305 <      dst=$dstdir/`basename "$src"`
305 >      dstbase=`basename "$src"`
306 >      case $dst in
307 >        */) dst=$dst$dstbase;;
308 >        *)  dst=$dst/$dstbase;;
309 >      esac
310        dstdir_status=0
311      else
312        dstdir=`dirname "$dst"`
# Line 288 | Line 315 | do
315      fi
316    fi
317  
318 +  case $dstdir in
319 +    */) dstdirslash=$dstdir;;
320 +    *)  dstdirslash=$dstdir/;;
321 +  esac
322 +
323    obsolete_mkdir_used=false
324  
325    if test $dstdir_status != 0; then
326      case $posix_mkdir in
327        '')
296        # Create intermediate dirs using mode 755 as modified by the umask.
297        # This is like FreeBSD 'install' as of 1997-10-28.
298        umask=`umask`
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;;
303
304          *[0-7])
305            mkdir_umask=`expr $umask + 22 \
306              - $umask % 100 % 40 + $umask % 20 \
307              - $umask % 10 % 4 + $umask % 2
308            `;;
309          *) mkdir_umask=$umask,go-w;;
310        esac
311
328          # With -d, create the new directory with the user-specified mode.
329          # Otherwise, rely on $mkdir_umask.
330          if test -n "$dir_arg"; then
# Line 318 | Line 334 | do
334          fi
335  
336          posix_mkdir=false
337 <        case $umask in
338 <          *[123567][0-7][0-7])
339 <            # POSIX mkdir -p sets u+wx bits regardless of umask, which
340 <            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
341 <            ;;
342 <          *)
343 <            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
344 <            trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
345 <
346 <            if (umask $mkdir_umask &&
347 <                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/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"`
355 <                   case $ls_ld_tmpdir in
356 <                     d????-?r-*) different_mode=700;;
357 <                     d????-?--*) different_mode=755;;
358 <                     *) false;;
359 <                   esac &&
360 <                   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
361 <                     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
362 <                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
363 <                   }
364 <                 }
365 <              then posix_mkdir=:
366 <              fi
367 <              rmdir "$tmpdir/d" "$tmpdir"
368 <            else
369 <              # Remove any dirs left behind by ancient mkdir implementations.
370 <              rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
371 <            fi
372 <            trap '' 0;;
373 <        esac;;
337 >        # The $RANDOM variable is not portable (e.g., dash).  Use it
338 >        # here however when possible just to lower collision chance.
339 >        tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
340 >
341 >        trap '
342 >          ret=$?
343 >          rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
344 >          exit $ret
345 >        ' 0
346 >
347 >        # Because "mkdir -p" follows existing symlinks and we likely work
348 >        # directly in world-writeable /tmp, make sure that the '$tmpdir'
349 >        # directory is successfully created first before we actually test
350 >        # 'mkdir -p'.
351 >        if (umask $mkdir_umask &&
352 >            $mkdirprog $mkdir_mode "$tmpdir" &&
353 >            exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
354 >        then
355 >          if test -z "$dir_arg" || {
356 >               # Check for POSIX incompatibilities with -m.
357 >               # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
358 >               # other-writable bit of parent directory when it shouldn't.
359 >               # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
360 >               test_tmpdir="$tmpdir/a"
361 >               ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
362 >               case $ls_ld_tmpdir in
363 >                 d????-?r-*) different_mode=700;;
364 >                 d????-?--*) different_mode=755;;
365 >                 *) false;;
366 >               esac &&
367 >               $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
368 >                 ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
369 >                 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
370 >               }
371 >             }
372 >          then posix_mkdir=:
373 >          fi
374 >          rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
375 >        else
376 >          # Remove any dirs left behind by ancient mkdir implementations.
377 >          rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
378 >        fi
379 >        trap '' 0;;
380      esac
381  
382      if
# Line 365 | Line 387 | do
387      then :
388      else
389  
390 <      # The umask is ridiculous, or mkdir does not conform to POSIX,
390 >      # mkdir does not conform to POSIX,
391        # or it failed possibly due to a race condition.  Create the
392        # directory the slow way, step by step, checking for races as we go.
393  
# Line 394 | Line 416 | do
416            prefixes=
417          else
418            if $posix_mkdir; then
419 <            (umask=$mkdir_umask &&
419 >            (umask $mkdir_umask &&
420               $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
421              # Don't fail if two instances are running concurrently.
422              test -d "$prefix" || exit 1
# Line 427 | Line 449 | do
449    else
450  
451      # Make a couple of temp file names in the proper directory.
452 <    dsttmp=$dstdir/_inst.$$_
453 <    rmtmp=$dstdir/_rm.$$_
452 >    dsttmp=${dstdirslash}_inst.$$_
453 >    rmtmp=${dstdirslash}_rm.$$_
454  
455      # Trap to clean up those temp files at exit.
456      trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
457  
458      # Copy the file name to the temp name.
459 <    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
459 >    (umask $cp_umask &&
460 >     { test -z "$stripcmd" || {
461 >         # Create $dsttmp read-write so that cp doesn't create it read-only,
462 >         # which would cause strip to fail.
463 >         if test -z "$doit"; then
464 >           : >"$dsttmp" # No need to fork-exec 'touch'.
465 >         else
466 >           $doit touch "$dsttmp"
467 >         fi
468 >       }
469 >     } &&
470 >     $doit_exec $cpprog "$src" "$dsttmp") &&
471  
472      # and set any options; do chmod last to preserve setuid bits.
473      #
# Line 460 | Line 493 | do
493      then
494        rm -f "$dsttmp"
495      else
496 +      # If $backupsuffix is set, and the file being installed
497 +      # already exists, attempt a backup.  Don't worry if it fails,
498 +      # e.g., if mv doesn't support -f.
499 +      if test -n "$backupsuffix" && test -f "$dst"; then
500 +        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
501 +      fi
502 +
503        # Rename the file to the real destination.
504        $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
505  
# Line 474 | Line 514 | do
514          # file should still install successfully.
515          {
516            test ! -f "$dst" ||
517 <          $doit $rmcmd -f "$dst" 2>/dev/null ||
517 >          $doit $rmcmd "$dst" 2>/dev/null ||
518            { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
519 <            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
519 >            { $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
520            } ||
521            { echo "$0: cannot unlink or rename $dst" >&2
522              (exit 1); exit 1
# Line 493 | Line 533 | do
533   done
534  
535   # Local variables:
536 < # eval: (add-hook 'write-file-hooks 'time-stamp)
536 > # eval: (add-hook 'before-save-hook 'time-stamp)
537   # time-stamp-start: "scriptversion="
538   # time-stamp-format: "%:y-%02m-%02d.%02H"
539   # time-stamp-time-zone: "UTC0"

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)