ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/install-sh
(Generate patch)

Comparing:
ircd-hybrid-7.3/install-sh (file contents), Revision 1094 by michael, Sun Jun 13 10:09:34 2010 UTC vs.
ircd-hybrid/trunk/install-sh (file contents), Revision 8757 by michael, Tue Jan 1 14:38:49 2019 UTC

# Line 1 | Line 1
1   #!/bin/sh
2   # install - install a program, script, or datafile
3  
4 < scriptversion=2010-02-06.18; # 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
# Line 35 | Line 35 | scriptversion=2010-02-06.18; # UTC
35   # FSF changes to this file are in the public domain.
36   #
37   # Calling this script install-sh is preferred over install.sh, to prevent
38 < # `make' implicit rules from creating a file called install from it
38 > # 'make' implicit rules from creating a file called install from it
39   # when there is no Makefile.
40   #
41   # This script is compatible with the BSD install script, but was written
42   # from scratch.
43  
44 + tab='   '
45   nl='
46   '
47 < IFS=" ""        $nl"
47 > IFS=" $tab$nl"
48  
49 < # set DOITPROG to echo to test this script
49 > # Set DOITPROG to "echo" to test this script.
50  
50 # Don't use :- since 4.3BSD and earlier shells don't like it.
51   doit=${DOITPROG-}
52 < if test -z "$doit"; then
53 <  doit_exec=exec
54 < else
55 <  doit_exec=$doit
56 < fi
52 > doit_exec=${doit:-exec}
53  
54   # Put in absolute file names if you don't have them in your path;
55   # or use environment vars.
# Line 68 | Line 64 | mvprog=${MVPROG-mv}
64   rmprog=${RMPROG-rm}
65   stripprog=${STRIPPROG-strip}
66  
71 posix_glob='?'
72 initialize_posix_glob='
73  test "$posix_glob" != "?" || {
74    if (set -f) 2>/dev/null; then
75      posix_glob=
76    else
77      posix_glob=:
78    fi
79  }
80 '
81
67   posix_mkdir=
68  
69   # Desired mode of installed file.
# Line 97 | Line 82 | dir_arg=
82   dst_arg=
83  
84   copy_on_change=false
85 < no_target_directory=
85 > is_target_a_directory=possibly
86  
87   usage="\
88   Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
# Line 137 | Line 122 | while test $# -ne 0; do
122      -d) dir_arg=true;;
123  
124      -g) chgrpcmd="$chgrpprog $2"
125 <        shift;;
125 >        shift;;
126  
127      --help) echo "$usage"; exit $?;;
128  
129      -m) mode=$2
130 <        case $mode in
131 <          *' '* | *'    '* | *'
132 < '*        | *'*'* | *'?'* | *'['*)
133 <            echo "$0: invalid mode: $mode" >&2
134 <            exit 1;;
135 <        esac
151 <        shift;;
130 >        case $mode in
131 >          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
132 >            echo "$0: invalid mode: $mode" >&2
133 >            exit 1;;
134 >        esac
135 >        shift;;
136  
137      -o) chowncmd="$chownprog $2"
138 <        shift;;
138 >        shift;;
139  
140      -s) stripcmd=$stripprog;;
141  
142 <    -t) dst_arg=$2
143 <        shift;;
142 >    -t)
143 >        is_target_a_directory=always
144 >        dst_arg=$2
145 >        # Protect names problematic for 'test' and other utilities.
146 >        case $dst_arg in
147 >          -* | [=\(\)!]) dst_arg=./$dst_arg;;
148 >        esac
149 >        shift;;
150  
151 <    -T) no_target_directory=true;;
151 >    -T) is_target_a_directory=never;;
152  
153      --version) echo "$0 $scriptversion"; exit $?;;
154  
155 <    --) shift
156 <        break;;
155 >    --) shift
156 >        break;;
157  
158 <    -*) echo "$0: invalid option: $1" >&2
159 <        exit 1;;
158 >    -*) echo "$0: invalid option: $1" >&2
159 >        exit 1;;
160  
161      *)  break;;
162    esac
163    shift
164   done
165  
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.
168 +
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
172 +    exit 1
173 +  fi
174 + fi
175 +
176   if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
177    # When -d is used, all remaining arguments are directories to create.
178    # When -t is used, the destination is already specified.
# Line 186 | Line 186 | if test $# -ne 0 && test -z "$dir_arg$ds
186      fi
187      shift # arg
188      dst_arg=$arg
189 +    # Protect names problematic for 'test' and other utilities.
190 +    case $dst_arg in
191 +      -* | [=\(\)!]) dst_arg=./$dst_arg;;
192 +    esac
193    done
194   fi
195  
# Line 194 | Line 198 | if test $# -eq 0; then
198      echo "$0: no input file specified." >&2
199      exit 1
200    fi
201 <  # It's OK to call `install-sh -d' without argument.
201 >  # It's OK to call 'install-sh -d' without argument.
202    # This can happen when creating conditional directories.
203    exit 0
204   fi
205  
206   if test -z "$dir_arg"; then
207 +  if test $# -gt 1 || test "$is_target_a_directory" = always; then
208 +    if test ! -d "$dst_arg"; then
209 +      echo "$0: $dst_arg: Is not a directory." >&2
210 +      exit 1
211 +    fi
212 +  fi
213 + fi
214 +
215 + if test -z "$dir_arg"; then
216    do_exit='(exit $ret); exit $ret'
217    trap "ret=129; $do_exit" 1
218    trap "ret=130; $do_exit" 2
# Line 215 | Line 228 | if test -z "$dir_arg"; then
228  
229      *[0-7])
230        if test -z "$stripcmd"; then
231 <        u_plus_rw=
231 >        u_plus_rw=
232        else
233 <        u_plus_rw='% 200'
233 >        u_plus_rw='% 200'
234        fi
235        cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
236      *)
237        if test -z "$stripcmd"; then
238 <        u_plus_rw=
238 >        u_plus_rw=
239        else
240 <        u_plus_rw=,u+rw
240 >        u_plus_rw=,u+rw
241        fi
242        cp_umask=$mode$u_plus_rw;;
243    esac
# Line 232 | Line 245 | fi
245  
246   for src
247   do
248 <  # Protect names starting with `-'.
248 >  # Protect names problematic for 'test' and other utilities.
249    case $src in
250 <    -*) src=./$src;;
250 >    -* | [=\(\)!]) src=./$src;;
251    esac
252  
253    if test -n "$dir_arg"; then
# Line 256 | Line 269 | do
269        echo "$0: no destination specified." >&2
270        exit 1
271      fi
259
272      dst=$dst_arg
261    # Protect names starting with `-'.
262    case $dst in
263      -*) dst=./$dst;;
264    esac
273  
274 <    # If destination is a directory, append the input filename; won't work
267 <    # 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 -n "$no_target_directory"; then
277 <        echo "$0: $dst_arg: Is a directory" >&2
278 <        exit 1
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 <      # Prefer dirname, but fall back on a substitute if dirname fails.
278 <      dstdir=`
279 <        (dirname "$dst") 2>/dev/null ||
280 <        expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
281 <             X"$dst" : 'X\(//\)[^/]' \| \
282 <             X"$dst" : 'X\(//\)$' \| \
283 <             X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
284 <        echo X"$dst" |
285 <            sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
286 <                   s//\1/
287 <                   q
288 <                 }
289 <                 /^X\(\/\/\)[^/].*/{
290 <                   s//\1/
291 <                   q
292 <                 }
293 <                 /^X\(\/\/\)$/{
294 <                   s//\1/
295 <                   q
296 <                 }
297 <                 /^X\(\/\).*/{
298 <                   s//\1/
299 <                   q
300 <                 }
301 <                 s/.*/./; q'
302 <      `
303 <
288 >      dstdir=`dirname "$dst"`
289        test -d "$dstdir"
290        dstdir_status=$?
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
302      case $posix_mkdir in
303        '')
304 <        # Create intermediate dirs using mode 755 as modified by the umask.
305 <        # This is like FreeBSD 'install' as of 1997-10-28.
306 <        umask=`umask`
307 <        case $stripcmd.$umask in
308 <          # Optimize common cases.
309 <          *[2367][2367]) mkdir_umask=$umask;;
310 <          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
311 <
312 <          *[0-7])
313 <            mkdir_umask=`expr $umask + 22 \
314 <              - $umask % 100 % 40 + $umask % 20 \
315 <              - $umask % 10 % 4 + $umask % 2
316 <            `;;
317 <          *) mkdir_umask=$umask,go-w;;
318 <        esac
319 <
320 <        # With -d, create the new directory with the user-specified mode.
321 <        # Otherwise, rely on $mkdir_umask.
322 <        if test -n "$dir_arg"; then
323 <          mkdir_mode=-m$mode
324 <        else
325 <          mkdir_mode=
326 <        fi
327 <
328 <        posix_mkdir=false
329 <        case $umask in
330 <          *[123567][0-7][0-7])
331 <            # POSIX mkdir -p sets u+wx bits regardless of umask, which
332 <            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
333 <            ;;
334 <          *)
335 <            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
336 <            trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
337 <
338 <            if (umask $mkdir_umask &&
339 <                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
340 <            then
341 <              if test -z "$dir_arg" || {
342 <                   # Check for POSIX incompatibilities with -m.
343 <                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
344 <                   # other-writeable bit of parent directory when it shouldn't.
345 <                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
346 <                   ls_ld_tmpdir=`ls -ld "$tmpdir"`
347 <                   case $ls_ld_tmpdir in
348 <                     d????-?r-*) different_mode=700;;
349 <                     d????-?--*) different_mode=755;;
350 <                     *) false;;
351 <                   esac &&
352 <                   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
353 <                     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
354 <                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
355 <                   }
356 <                 }
357 <              then posix_mkdir=:
358 <              fi
359 <              rmdir "$tmpdir/d" "$tmpdir"
360 <            else
361 <              # Remove any dirs left behind by ancient mkdir implementations.
362 <              rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
363 <            fi
364 <            trap '' 0;;
365 <        esac;;
304 >        # Create intermediate dirs using mode 755 as modified by the umask.
305 >        # This is like FreeBSD 'install' as of 1997-10-28.
306 >        umask=`umask`
307 >        case $stripcmd.$umask in
308 >          # Optimize common cases.
309 >          *[2367][2367]) mkdir_umask=$umask;;
310 >          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
311 >
312 >          *[0-7])
313 >            mkdir_umask=`expr $umask + 22 \
314 >              - $umask % 100 % 40 + $umask % 20 \
315 >              - $umask % 10 % 4 + $umask % 2
316 >            `;;
317 >          *) mkdir_umask=$umask,go-w;;
318 >        esac
319 >
320 >        # With -d, create the new directory with the user-specified mode.
321 >        # Otherwise, rely on $mkdir_umask.
322 >        if test -n "$dir_arg"; then
323 >          mkdir_mode=-m$mode
324 >        else
325 >          mkdir_mode=
326 >        fi
327 >
328 >        posix_mkdir=false
329 >        case $umask in
330 >          *[123567][0-7][0-7])
331 >            # POSIX mkdir -p sets u+wx bits regardless of umask, which
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-$$
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 >                $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 >                   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 -- "$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/a/b" "$tmpdir/a" "$tmpdir"
369 >            else
370 >              # Remove any dirs left behind by ancient mkdir implementations.
371 >              rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
372 >            fi
373 >            trap '' 0;;
374 >        esac;;
375      esac
376  
377      if
378        $posix_mkdir && (
379 <        umask $mkdir_umask &&
380 <        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
379 >        umask $mkdir_umask &&
380 >        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
381        )
382      then :
383      else
# Line 388 | Line 387 | do
387        # directory the slow way, step by step, checking for races as we go.
388  
389        case $dstdir in
390 <        /*) prefix='/';;
391 <        -*) prefix='./';;
392 <        *)  prefix='';;
390 >        /*) prefix='/';;
391 >        [-=\(\)!]*) prefix='./';;
392 >        *)  prefix='';;
393        esac
394  
396      eval "$initialize_posix_glob"
397
395        oIFS=$IFS
396        IFS=/
397 <      $posix_glob set -f
397 >      set -f
398        set fnord $dstdir
399        shift
400 <      $posix_glob set +f
400 >      set +f
401        IFS=$oIFS
402  
403        prefixes=
404  
405        for d
406        do
407 <        test -z "$d" && continue
407 >        test X"$d" = X && continue
408  
409 <        prefix=$prefix$d
410 <        if test -d "$prefix"; then
411 <          prefixes=
412 <        else
413 <          if $posix_mkdir; then
414 <            (umask=$mkdir_umask &&
415 <             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
416 <            # Don't fail if two instances are running concurrently.
417 <            test -d "$prefix" || exit 1
418 <          else
419 <            case $prefix in
420 <              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
421 <              *) qprefix=$prefix;;
422 <            esac
423 <            prefixes="$prefixes '$qprefix'"
424 <          fi
425 <        fi
426 <        prefix=$prefix/
409 >        prefix=$prefix$d
410 >        if test -d "$prefix"; then
411 >          prefixes=
412 >        else
413 >          if $posix_mkdir; then
414 >            (umask=$mkdir_umask &&
415 >             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
416 >            # Don't fail if two instances are running concurrently.
417 >            test -d "$prefix" || exit 1
418 >          else
419 >            case $prefix in
420 >              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
421 >              *) qprefix=$prefix;;
422 >            esac
423 >            prefixes="$prefixes '$qprefix'"
424 >          fi
425 >        fi
426 >        prefix=$prefix/
427        done
428  
429        if test -n "$prefixes"; then
430 <        # Don't fail if two instances are running concurrently.
431 <        (umask $mkdir_umask &&
432 <         eval "\$doit_exec \$mkdirprog $prefixes") ||
433 <          test -d "$dstdir" || exit 1
434 <        obsolete_mkdir_used=true
430 >        # Don't fail if two instances are running concurrently.
431 >        (umask $mkdir_umask &&
432 >         eval "\$doit_exec \$mkdirprog $prefixes") ||
433 >          test -d "$dstdir" || exit 1
434 >        obsolete_mkdir_used=true
435        fi
436      fi
437    fi
# Line 447 | Line 444 | do
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
# Line 469 | Line 466 | do
466  
467      # If -C, don't bother to copy if it wouldn't change the file.
468      if $copy_on_change &&
469 <       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
470 <       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
471 <
475 <       eval "$initialize_posix_glob" &&
476 <       $posix_glob set -f &&
469 >       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
470 >       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
471 >       set -f &&
472         set X $old && old=:$2:$4:$5:$6 &&
473         set X $new && new=:$2:$4:$5:$6 &&
474 <       $posix_glob set +f &&
480 <
474 >       set +f &&
475         test "$old" = "$new" &&
476         $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
477      then
# Line 490 | Line 484 | do
484        # to itself, or perhaps because mv is so ancient that it does not
485        # support -f.
486        {
487 <        # Now remove or move aside any old file at destination location.
488 <        # We try this two ways since rm can't unlink itself on some
489 <        # systems and the destination file might be busy for other
490 <        # reasons.  In this case, the final cleanup might fail but the new
491 <        # file should still install successfully.
492 <        {
493 <          test ! -f "$dst" ||
494 <          $doit $rmcmd -f "$dst" 2>/dev/null ||
495 <          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
496 <            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
497 <          } ||
498 <          { echo "$0: cannot unlink or rename $dst" >&2
499 <            (exit 1); exit 1
500 <          }
501 <        } &&
487 >        # Now remove or move aside any old file at destination location.
488 >        # We try this two ways since rm can't unlink itself on some
489 >        # systems and the destination file might be busy for other
490 >        # reasons.  In this case, the final cleanup might fail but the new
491 >        # file should still install successfully.
492 >        {
493 >          test ! -f "$dst" ||
494 >          $doit $rmcmd -f "$dst" 2>/dev/null ||
495 >          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
496 >            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
497 >          } ||
498 >          { echo "$0: cannot unlink or rename $dst" >&2
499 >            (exit 1); exit 1
500 >          }
501 >        } &&
502  
503 <        # Now rename the file to the real destination.
504 <        $doit $mvcmd "$dsttmp" "$dst"
503 >        # Now rename the file to the real destination.
504 >        $doit $mvcmd "$dsttmp" "$dst"
505        }
506      fi || exit 1
507  
# Line 516 | Line 510 | do
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: "UTC"
516 > # time-stamp-time-zone: "UTC0"
517   # time-stamp-end: "; # UTC"
518   # End:

Comparing:
ircd-hybrid-7.3/install-sh (property svn:eol-style), Revision 1094 by michael, Sun Jun 13 10:09:34 2010 UTC vs.
ircd-hybrid/trunk/install-sh (property svn:eol-style), Revision 8757 by michael, Tue Jan 1 14:38:49 2019 UTC

# Line 0 | Line 1
1 + native

Diff Legend

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