Home | History | Annotate | Line # | Download | only in conftools
install-sh revision 1.1.1.2.14.2
      1           1.1  tron #!/bin/sh
      2           1.1  tron # install - install a program, script, or datafile
      3       1.1.1.2   spz 
      4  1.1.1.2.14.2   snj scriptversion=2013-12-25.23; # UTC
      5       1.1.1.2   spz 
      6       1.1.1.2   spz # This originates from X11R5 (mit/util/scripts/install.sh), which was
      7       1.1.1.2   spz # later released in X11R6 (xc/config/util/install.sh) with the
      8       1.1.1.2   spz # following copyright and license.
      9       1.1.1.2   spz #
     10       1.1.1.2   spz # Copyright (C) 1994 X Consortium
     11       1.1.1.2   spz #
     12       1.1.1.2   spz # Permission is hereby granted, free of charge, to any person obtaining a copy
     13       1.1.1.2   spz # of this software and associated documentation files (the "Software"), to
     14       1.1.1.2   spz # deal in the Software without restriction, including without limitation the
     15       1.1.1.2   spz # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     16       1.1.1.2   spz # sell copies of the Software, and to permit persons to whom the Software is
     17       1.1.1.2   spz # furnished to do so, subject to the following conditions:
     18       1.1.1.2   spz #
     19       1.1.1.2   spz # The above copyright notice and this permission notice shall be included in
     20       1.1.1.2   spz # all copies or substantial portions of the Software.
     21       1.1.1.2   spz #
     22       1.1.1.2   spz # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     23       1.1.1.2   spz # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     24       1.1.1.2   spz # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     25       1.1.1.2   spz # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     26       1.1.1.2   spz # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
     27       1.1.1.2   spz # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     28       1.1.1.2   spz #
     29       1.1.1.2   spz # Except as contained in this notice, the name of the X Consortium shall not
     30       1.1.1.2   spz # be used in advertising or otherwise to promote the sale, use or other deal-
     31       1.1.1.2   spz # ings in this Software without prior written authorization from the X Consor-
     32       1.1.1.2   spz # tium.
     33           1.1  tron #
     34           1.1  tron #
     35       1.1.1.2   spz # FSF changes to this file are in the public domain.
     36           1.1  tron #
     37           1.1  tron # Calling this script install-sh is preferred over install.sh, to prevent
     38  1.1.1.2.14.1   snj # 'make' implicit rules from creating a file called install from it
     39           1.1  tron # when there is no Makefile.
     40           1.1  tron #
     41           1.1  tron # This script is compatible with the BSD install script, but was written
     42       1.1.1.2   spz # from scratch.
     43           1.1  tron 
     44  1.1.1.2.14.2   snj tab='	'
     45       1.1.1.2   spz nl='
     46       1.1.1.2   spz '
     47  1.1.1.2.14.2   snj IFS=" $tab$nl"
     48           1.1  tron 
     49  1.1.1.2.14.2   snj # Set DOITPROG to "echo" to test this script.
     50           1.1  tron 
     51       1.1.1.2   spz doit=${DOITPROG-}
     52  1.1.1.2.14.2   snj doit_exec=${doit:-exec}
     53       1.1.1.2   spz 
     54       1.1.1.2   spz # Put in absolute file names if you don't have them in your path;
     55       1.1.1.2   spz # or use environment vars.
     56           1.1  tron 
     57       1.1.1.2   spz chgrpprog=${CHGRPPROG-chgrp}
     58       1.1.1.2   spz chmodprog=${CHMODPROG-chmod}
     59       1.1.1.2   spz chownprog=${CHOWNPROG-chown}
     60       1.1.1.2   spz cmpprog=${CMPPROG-cmp}
     61       1.1.1.2   spz cpprog=${CPPROG-cp}
     62       1.1.1.2   spz mkdirprog=${MKDIRPROG-mkdir}
     63       1.1.1.2   spz mvprog=${MVPROG-mv}
     64       1.1.1.2   spz rmprog=${RMPROG-rm}
     65       1.1.1.2   spz stripprog=${STRIPPROG-strip}
     66       1.1.1.2   spz 
     67       1.1.1.2   spz posix_mkdir=
     68           1.1  tron 
     69       1.1.1.2   spz # Desired mode of installed file.
     70       1.1.1.2   spz mode=0755
     71           1.1  tron 
     72       1.1.1.2   spz chgrpcmd=
     73       1.1.1.2   spz chmodcmd=$chmodprog
     74       1.1.1.2   spz chowncmd=
     75       1.1.1.2   spz mvcmd=$mvprog
     76           1.1  tron rmcmd="$rmprog -f"
     77       1.1.1.2   spz stripcmd=
     78           1.1  tron 
     79       1.1.1.2   spz src=
     80       1.1.1.2   spz dst=
     81       1.1.1.2   spz dir_arg=
     82       1.1.1.2   spz dst_arg=
     83           1.1  tron 
     84       1.1.1.2   spz copy_on_change=false
     85  1.1.1.2.14.2   snj is_target_a_directory=possibly
     86           1.1  tron 
     87       1.1.1.2   spz usage="\
     88       1.1.1.2   spz Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
     89       1.1.1.2   spz    or: $0 [OPTION]... SRCFILES... DIRECTORY
     90       1.1.1.2   spz    or: $0 [OPTION]... -t DIRECTORY SRCFILES...
     91       1.1.1.2   spz    or: $0 [OPTION]... -d DIRECTORIES...
     92           1.1  tron 
     93       1.1.1.2   spz In the 1st form, copy SRCFILE to DSTFILE.
     94       1.1.1.2   spz In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
     95       1.1.1.2   spz In the 4th, create DIRECTORIES.
     96           1.1  tron 
     97       1.1.1.2   spz Options:
     98       1.1.1.2   spz      --help     display this help and exit.
     99       1.1.1.2   spz      --version  display version info and exit.
    100           1.1  tron 
    101       1.1.1.2   spz   -c            (ignored)
    102       1.1.1.2   spz   -C            install only if different (preserve the last data modification time)
    103       1.1.1.2   spz   -d            create directories instead of installing files.
    104       1.1.1.2   spz   -g GROUP      $chgrpprog installed files to GROUP.
    105       1.1.1.2   spz   -m MODE       $chmodprog installed files to MODE.
    106       1.1.1.2   spz   -o USER       $chownprog installed files to USER.
    107       1.1.1.2   spz   -s            $stripprog installed files.
    108       1.1.1.2   spz   -t DIRECTORY  install into DIRECTORY.
    109       1.1.1.2   spz   -T            report an error if DSTFILE is a directory.
    110           1.1  tron 
    111       1.1.1.2   spz Environment variables override the default commands:
    112       1.1.1.2   spz   CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
    113       1.1.1.2   spz   RMPROG STRIPPROG
    114       1.1.1.2   spz "
    115           1.1  tron 
    116       1.1.1.2   spz while test $# -ne 0; do
    117       1.1.1.2   spz   case $1 in
    118       1.1.1.2   spz     -c) ;;
    119           1.1  tron 
    120       1.1.1.2   spz     -C) copy_on_change=true;;
    121           1.1  tron 
    122       1.1.1.2   spz     -d) dir_arg=true;;
    123           1.1  tron 
    124       1.1.1.2   spz     -g) chgrpcmd="$chgrpprog $2"
    125  1.1.1.2.14.2   snj         shift;;
    126           1.1  tron 
    127       1.1.1.2   spz     --help) echo "$usage"; exit $?;;
    128           1.1  tron 
    129       1.1.1.2   spz     -m) mode=$2
    130  1.1.1.2.14.2   snj         case $mode in
    131  1.1.1.2.14.2   snj           *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
    132  1.1.1.2.14.2   snj             echo "$0: invalid mode: $mode" >&2
    133  1.1.1.2.14.2   snj             exit 1;;
    134  1.1.1.2.14.2   snj         esac
    135  1.1.1.2.14.2   snj         shift;;
    136           1.1  tron 
    137       1.1.1.2   spz     -o) chowncmd="$chownprog $2"
    138  1.1.1.2.14.2   snj         shift;;
    139           1.1  tron 
    140       1.1.1.2   spz     -s) stripcmd=$stripprog;;
    141           1.1  tron 
    142  1.1.1.2.14.2   snj     -t)
    143  1.1.1.2.14.2   snj         is_target_a_directory=always
    144  1.1.1.2.14.2   snj         dst_arg=$2
    145  1.1.1.2.14.2   snj         # Protect names problematic for 'test' and other utilities.
    146  1.1.1.2.14.2   snj         case $dst_arg in
    147  1.1.1.2.14.2   snj           -* | [=\(\)!]) dst_arg=./$dst_arg;;
    148  1.1.1.2.14.2   snj         esac
    149  1.1.1.2.14.2   snj         shift;;
    150       1.1.1.2   spz 
    151  1.1.1.2.14.2   snj     -T) is_target_a_directory=never;;
    152       1.1.1.2   spz 
    153       1.1.1.2   spz     --version) echo "$0 $scriptversion"; exit $?;;
    154       1.1.1.2   spz 
    155  1.1.1.2.14.2   snj     --) shift
    156  1.1.1.2.14.2   snj         break;;
    157       1.1.1.2   spz 
    158  1.1.1.2.14.2   snj     -*) echo "$0: invalid option: $1" >&2
    159  1.1.1.2.14.2   snj         exit 1;;
    160           1.1  tron 
    161       1.1.1.2   spz     *)  break;;
    162       1.1.1.2   spz   esac
    163       1.1.1.2   spz   shift
    164       1.1.1.2   spz done
    165           1.1  tron 
    166  1.1.1.2.14.2   snj # We allow the use of options -d and -T together, by making -d
    167  1.1.1.2.14.2   snj # take the precedence; this is for compatibility with GNU install.
    168  1.1.1.2.14.2   snj 
    169  1.1.1.2.14.2   snj if test -n "$dir_arg"; then
    170  1.1.1.2.14.2   snj   if test -n "$dst_arg"; then
    171  1.1.1.2.14.2   snj     echo "$0: target directory not allowed when installing a directory." >&2
    172  1.1.1.2.14.2   snj     exit 1
    173  1.1.1.2.14.2   snj   fi
    174  1.1.1.2.14.2   snj fi
    175  1.1.1.2.14.2   snj 
    176       1.1.1.2   spz if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
    177       1.1.1.2   spz   # When -d is used, all remaining arguments are directories to create.
    178       1.1.1.2   spz   # When -t is used, the destination is already specified.
    179       1.1.1.2   spz   # Otherwise, the last argument is the destination.  Remove it from $@.
    180       1.1.1.2   spz   for arg
    181       1.1.1.2   spz   do
    182       1.1.1.2   spz     if test -n "$dst_arg"; then
    183       1.1.1.2   spz       # $@ is not empty: it contains at least $arg.
    184       1.1.1.2   spz       set fnord "$@" "$dst_arg"
    185       1.1.1.2   spz       shift # fnord
    186       1.1.1.2   spz     fi
    187       1.1.1.2   spz     shift # arg
    188       1.1.1.2   spz     dst_arg=$arg
    189  1.1.1.2.14.1   snj     # Protect names problematic for 'test' and other utilities.
    190  1.1.1.2.14.1   snj     case $dst_arg in
    191  1.1.1.2.14.1   snj       -* | [=\(\)!]) dst_arg=./$dst_arg;;
    192  1.1.1.2.14.1   snj     esac
    193       1.1.1.2   spz   done
    194       1.1.1.2   spz fi
    195           1.1  tron 
    196       1.1.1.2   spz if test $# -eq 0; then
    197       1.1.1.2   spz   if test -z "$dir_arg"; then
    198       1.1.1.2   spz     echo "$0: no input file specified." >&2
    199       1.1.1.2   spz     exit 1
    200       1.1.1.2   spz   fi
    201  1.1.1.2.14.1   snj   # It's OK to call 'install-sh -d' without argument.
    202       1.1.1.2   spz   # This can happen when creating conditional directories.
    203       1.1.1.2   spz   exit 0
    204       1.1.1.2   spz fi
    205           1.1  tron 
    206       1.1.1.2   spz if test -z "$dir_arg"; then
    207  1.1.1.2.14.2   snj   if test $# -gt 1 || test "$is_target_a_directory" = always; then
    208  1.1.1.2.14.2   snj     if test ! -d "$dst_arg"; then
    209  1.1.1.2.14.2   snj       echo "$0: $dst_arg: Is not a directory." >&2
    210  1.1.1.2.14.2   snj       exit 1
    211  1.1.1.2.14.2   snj     fi
    212  1.1.1.2.14.2   snj   fi
    213  1.1.1.2.14.2   snj fi
    214  1.1.1.2.14.2   snj 
    215  1.1.1.2.14.2   snj if test -z "$dir_arg"; then
    216  1.1.1.2.14.1   snj   do_exit='(exit $ret); exit $ret'
    217  1.1.1.2.14.1   snj   trap "ret=129; $do_exit" 1
    218  1.1.1.2.14.1   snj   trap "ret=130; $do_exit" 2
    219  1.1.1.2.14.1   snj   trap "ret=141; $do_exit" 13
    220  1.1.1.2.14.1   snj   trap "ret=143; $do_exit" 15
    221           1.1  tron 
    222       1.1.1.2   spz   # Set umask so as not to create temps with too-generous modes.
    223       1.1.1.2   spz   # However, 'strip' requires both read and write access to temps.
    224       1.1.1.2   spz   case $mode in
    225       1.1.1.2   spz     # Optimize common cases.
    226       1.1.1.2   spz     *644) cp_umask=133;;
    227       1.1.1.2   spz     *755) cp_umask=22;;
    228       1.1.1.2   spz 
    229       1.1.1.2   spz     *[0-7])
    230       1.1.1.2   spz       if test -z "$stripcmd"; then
    231  1.1.1.2.14.2   snj         u_plus_rw=
    232       1.1.1.2   spz       else
    233  1.1.1.2.14.2   snj         u_plus_rw='% 200'
    234       1.1.1.2   spz       fi
    235       1.1.1.2   spz       cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
    236       1.1.1.2   spz     *)
    237       1.1.1.2   spz       if test -z "$stripcmd"; then
    238  1.1.1.2.14.2   snj         u_plus_rw=
    239       1.1.1.2   spz       else
    240  1.1.1.2.14.2   snj         u_plus_rw=,u+rw
    241       1.1.1.2   spz       fi
    242       1.1.1.2   spz       cp_umask=$mode$u_plus_rw;;
    243       1.1.1.2   spz   esac
    244       1.1.1.2   spz fi
    245           1.1  tron 
    246       1.1.1.2   spz for src
    247       1.1.1.2   spz do
    248  1.1.1.2.14.1   snj   # Protect names problematic for 'test' and other utilities.
    249       1.1.1.2   spz   case $src in
    250  1.1.1.2.14.1   snj     -* | [=\(\)!]) src=./$src;;
    251       1.1.1.2   spz   esac
    252       1.1.1.2   spz 
    253       1.1.1.2   spz   if test -n "$dir_arg"; then
    254       1.1.1.2   spz     dst=$src
    255       1.1.1.2   spz     dstdir=$dst
    256       1.1.1.2   spz     test -d "$dstdir"
    257       1.1.1.2   spz     dstdir_status=$?
    258       1.1.1.2   spz   else
    259       1.1.1.2   spz 
    260       1.1.1.2   spz     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
    261       1.1.1.2   spz     # might cause directories to be created, which would be especially bad
    262       1.1.1.2   spz     # if $src (and thus $dsttmp) contains '*'.
    263       1.1.1.2   spz     if test ! -f "$src" && test ! -d "$src"; then
    264       1.1.1.2   spz       echo "$0: $src does not exist." >&2
    265       1.1.1.2   spz       exit 1
    266       1.1.1.2   spz     fi
    267       1.1.1.2   spz 
    268       1.1.1.2   spz     if test -z "$dst_arg"; then
    269       1.1.1.2   spz       echo "$0: no destination specified." >&2
    270       1.1.1.2   spz       exit 1
    271       1.1.1.2   spz     fi
    272       1.1.1.2   spz     dst=$dst_arg
    273           1.1  tron 
    274       1.1.1.2   spz     # If destination is a directory, append the input filename; won't work
    275       1.1.1.2   spz     # if double slashes aren't ignored.
    276       1.1.1.2   spz     if test -d "$dst"; then
    277  1.1.1.2.14.2   snj       if test "$is_target_a_directory" = never; then
    278  1.1.1.2.14.2   snj         echo "$0: $dst_arg: Is a directory" >&2
    279  1.1.1.2.14.2   snj         exit 1
    280       1.1.1.2   spz       fi
    281       1.1.1.2   spz       dstdir=$dst
    282       1.1.1.2   spz       dst=$dstdir/`basename "$src"`
    283       1.1.1.2   spz       dstdir_status=0
    284       1.1.1.2   spz     else
    285  1.1.1.2.14.2   snj       dstdir=`dirname "$dst"`
    286       1.1.1.2   spz       test -d "$dstdir"
    287       1.1.1.2   spz       dstdir_status=$?
    288       1.1.1.2   spz     fi
    289       1.1.1.2   spz   fi
    290       1.1.1.2   spz 
    291       1.1.1.2   spz   obsolete_mkdir_used=false
    292       1.1.1.2   spz 
    293       1.1.1.2   spz   if test $dstdir_status != 0; then
    294       1.1.1.2   spz     case $posix_mkdir in
    295       1.1.1.2   spz       '')
    296  1.1.1.2.14.2   snj         # Create intermediate dirs using mode 755 as modified by the umask.
    297  1.1.1.2.14.2   snj         # This is like FreeBSD 'install' as of 1997-10-28.
    298  1.1.1.2.14.2   snj         umask=`umask`
    299  1.1.1.2.14.2   snj         case $stripcmd.$umask in
    300  1.1.1.2.14.2   snj           # Optimize common cases.
    301  1.1.1.2.14.2   snj           *[2367][2367]) mkdir_umask=$umask;;
    302  1.1.1.2.14.2   snj           .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
    303  1.1.1.2.14.2   snj 
    304  1.1.1.2.14.2   snj           *[0-7])
    305  1.1.1.2.14.2   snj             mkdir_umask=`expr $umask + 22 \
    306  1.1.1.2.14.2   snj               - $umask % 100 % 40 + $umask % 20 \
    307  1.1.1.2.14.2   snj               - $umask % 10 % 4 + $umask % 2
    308  1.1.1.2.14.2   snj             `;;
    309  1.1.1.2.14.2   snj           *) mkdir_umask=$umask,go-w;;
    310  1.1.1.2.14.2   snj         esac
    311  1.1.1.2.14.2   snj 
    312  1.1.1.2.14.2   snj         # With -d, create the new directory with the user-specified mode.
    313  1.1.1.2.14.2   snj         # Otherwise, rely on $mkdir_umask.
    314  1.1.1.2.14.2   snj         if test -n "$dir_arg"; then
    315  1.1.1.2.14.2   snj           mkdir_mode=-m$mode
    316  1.1.1.2.14.2   snj         else
    317  1.1.1.2.14.2   snj           mkdir_mode=
    318  1.1.1.2.14.2   snj         fi
    319  1.1.1.2.14.2   snj 
    320  1.1.1.2.14.2   snj         posix_mkdir=false
    321  1.1.1.2.14.2   snj         case $umask in
    322  1.1.1.2.14.2   snj           *[123567][0-7][0-7])
    323  1.1.1.2.14.2   snj             # POSIX mkdir -p sets u+wx bits regardless of umask, which
    324  1.1.1.2.14.2   snj             # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
    325  1.1.1.2.14.2   snj             ;;
    326  1.1.1.2.14.2   snj           *)
    327  1.1.1.2.14.2   snj             tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
    328  1.1.1.2.14.2   snj             trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
    329  1.1.1.2.14.2   snj 
    330  1.1.1.2.14.2   snj             if (umask $mkdir_umask &&
    331  1.1.1.2.14.2   snj                 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
    332  1.1.1.2.14.2   snj             then
    333  1.1.1.2.14.2   snj               if test -z "$dir_arg" || {
    334  1.1.1.2.14.2   snj                    # Check for POSIX incompatibilities with -m.
    335  1.1.1.2.14.2   snj                    # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
    336  1.1.1.2.14.2   snj                    # other-writable bit of parent directory when it shouldn't.
    337  1.1.1.2.14.2   snj                    # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
    338  1.1.1.2.14.2   snj                    ls_ld_tmpdir=`ls -ld "$tmpdir"`
    339  1.1.1.2.14.2   snj                    case $ls_ld_tmpdir in
    340  1.1.1.2.14.2   snj                      d????-?r-*) different_mode=700;;
    341  1.1.1.2.14.2   snj                      d????-?--*) different_mode=755;;
    342  1.1.1.2.14.2   snj                      *) false;;
    343  1.1.1.2.14.2   snj                    esac &&
    344  1.1.1.2.14.2   snj                    $mkdirprog -m$different_mode -p -- "$tmpdir" && {
    345  1.1.1.2.14.2   snj                      ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
    346  1.1.1.2.14.2   snj                      test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
    347  1.1.1.2.14.2   snj                    }
    348  1.1.1.2.14.2   snj                  }
    349  1.1.1.2.14.2   snj               then posix_mkdir=:
    350  1.1.1.2.14.2   snj               fi
    351  1.1.1.2.14.2   snj               rmdir "$tmpdir/d" "$tmpdir"
    352  1.1.1.2.14.2   snj             else
    353  1.1.1.2.14.2   snj               # Remove any dirs left behind by ancient mkdir implementations.
    354  1.1.1.2.14.2   snj               rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
    355  1.1.1.2.14.2   snj             fi
    356  1.1.1.2.14.2   snj             trap '' 0;;
    357  1.1.1.2.14.2   snj         esac;;
    358       1.1.1.2   spz     esac
    359           1.1  tron 
    360       1.1.1.2   spz     if
    361       1.1.1.2   spz       $posix_mkdir && (
    362  1.1.1.2.14.2   snj         umask $mkdir_umask &&
    363  1.1.1.2.14.2   snj         $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
    364       1.1.1.2   spz       )
    365       1.1.1.2   spz     then :
    366       1.1.1.2   spz     else
    367       1.1.1.2   spz 
    368       1.1.1.2   spz       # The umask is ridiculous, or mkdir does not conform to POSIX,
    369       1.1.1.2   spz       # or it failed possibly due to a race condition.  Create the
    370       1.1.1.2   spz       # directory the slow way, step by step, checking for races as we go.
    371       1.1.1.2   spz 
    372       1.1.1.2   spz       case $dstdir in
    373  1.1.1.2.14.2   snj         /*) prefix='/';;
    374  1.1.1.2.14.2   snj         [-=\(\)!]*) prefix='./';;
    375  1.1.1.2.14.2   snj         *)  prefix='';;
    376       1.1.1.2   spz       esac
    377       1.1.1.2   spz 
    378       1.1.1.2   spz       oIFS=$IFS
    379       1.1.1.2   spz       IFS=/
    380  1.1.1.2.14.2   snj       set -f
    381       1.1.1.2   spz       set fnord $dstdir
    382       1.1.1.2   spz       shift
    383  1.1.1.2.14.2   snj       set +f
    384       1.1.1.2   spz       IFS=$oIFS
    385       1.1.1.2   spz 
    386       1.1.1.2   spz       prefixes=
    387       1.1.1.2   spz 
    388       1.1.1.2   spz       for d
    389       1.1.1.2   spz       do
    390  1.1.1.2.14.2   snj         test X"$d" = X && continue
    391       1.1.1.2   spz 
    392  1.1.1.2.14.2   snj         prefix=$prefix$d
    393  1.1.1.2.14.2   snj         if test -d "$prefix"; then
    394  1.1.1.2.14.2   snj           prefixes=
    395  1.1.1.2.14.2   snj         else
    396  1.1.1.2.14.2   snj           if $posix_mkdir; then
    397  1.1.1.2.14.2   snj             (umask=$mkdir_umask &&
    398  1.1.1.2.14.2   snj              $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
    399  1.1.1.2.14.2   snj             # Don't fail if two instances are running concurrently.
    400  1.1.1.2.14.2   snj             test -d "$prefix" || exit 1
    401  1.1.1.2.14.2   snj           else
    402  1.1.1.2.14.2   snj             case $prefix in
    403  1.1.1.2.14.2   snj               *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
    404  1.1.1.2.14.2   snj               *) qprefix=$prefix;;
    405  1.1.1.2.14.2   snj             esac
    406  1.1.1.2.14.2   snj             prefixes="$prefixes '$qprefix'"
    407  1.1.1.2.14.2   snj           fi
    408  1.1.1.2.14.2   snj         fi
    409  1.1.1.2.14.2   snj         prefix=$prefix/
    410       1.1.1.2   spz       done
    411           1.1  tron 
    412       1.1.1.2   spz       if test -n "$prefixes"; then
    413  1.1.1.2.14.2   snj         # Don't fail if two instances are running concurrently.
    414  1.1.1.2.14.2   snj         (umask $mkdir_umask &&
    415  1.1.1.2.14.2   snj          eval "\$doit_exec \$mkdirprog $prefixes") ||
    416  1.1.1.2.14.2   snj           test -d "$dstdir" || exit 1
    417  1.1.1.2.14.2   snj         obsolete_mkdir_used=true
    418       1.1.1.2   spz       fi
    419       1.1.1.2   spz     fi
    420       1.1.1.2   spz   fi
    421       1.1.1.2   spz 
    422       1.1.1.2   spz   if test -n "$dir_arg"; then
    423       1.1.1.2   spz     { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
    424       1.1.1.2   spz     { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
    425       1.1.1.2   spz     { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
    426       1.1.1.2   spz       test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
    427       1.1.1.2   spz   else
    428       1.1.1.2   spz 
    429       1.1.1.2   spz     # Make a couple of temp file names in the proper directory.
    430       1.1.1.2   spz     dsttmp=$dstdir/_inst.$$_
    431       1.1.1.2   spz     rmtmp=$dstdir/_rm.$$_
    432       1.1.1.2   spz 
    433       1.1.1.2   spz     # Trap to clean up those temp files at exit.
    434       1.1.1.2   spz     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
    435       1.1.1.2   spz 
    436       1.1.1.2   spz     # Copy the file name to the temp name.
    437       1.1.1.2   spz     (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
    438       1.1.1.2   spz 
    439       1.1.1.2   spz     # and set any options; do chmod last to preserve setuid bits.
    440       1.1.1.2   spz     #
    441       1.1.1.2   spz     # If any of these fail, we abort the whole thing.  If we want to
    442       1.1.1.2   spz     # ignore errors from any of these, just make sure not to ignore
    443       1.1.1.2   spz     # errors from the above "$doit $cpprog $src $dsttmp" command.
    444       1.1.1.2   spz     #
    445       1.1.1.2   spz     { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
    446       1.1.1.2   spz     { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
    447       1.1.1.2   spz     { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
    448       1.1.1.2   spz     { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
    449       1.1.1.2   spz 
    450       1.1.1.2   spz     # If -C, don't bother to copy if it wouldn't change the file.
    451       1.1.1.2   spz     if $copy_on_change &&
    452  1.1.1.2.14.2   snj        old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
    453  1.1.1.2.14.2   snj        new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
    454  1.1.1.2.14.2   snj        set -f &&
    455       1.1.1.2   spz        set X $old && old=:$2:$4:$5:$6 &&
    456       1.1.1.2   spz        set X $new && new=:$2:$4:$5:$6 &&
    457  1.1.1.2.14.2   snj        set +f &&
    458       1.1.1.2   spz        test "$old" = "$new" &&
    459       1.1.1.2   spz        $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
    460       1.1.1.2   spz     then
    461       1.1.1.2   spz       rm -f "$dsttmp"
    462       1.1.1.2   spz     else
    463       1.1.1.2   spz       # Rename the file to the real destination.
    464       1.1.1.2   spz       $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
    465       1.1.1.2   spz 
    466       1.1.1.2   spz       # The rename failed, perhaps because mv can't rename something else
    467       1.1.1.2   spz       # to itself, or perhaps because mv is so ancient that it does not
    468       1.1.1.2   spz       # support -f.
    469       1.1.1.2   spz       {
    470  1.1.1.2.14.2   snj         # Now remove or move aside any old file at destination location.
    471  1.1.1.2.14.2   snj         # We try this two ways since rm can't unlink itself on some
    472  1.1.1.2.14.2   snj         # systems and the destination file might be busy for other
    473  1.1.1.2.14.2   snj         # reasons.  In this case, the final cleanup might fail but the new
    474  1.1.1.2.14.2   snj         # file should still install successfully.
    475  1.1.1.2.14.2   snj         {
    476  1.1.1.2.14.2   snj           test ! -f "$dst" ||
    477  1.1.1.2.14.2   snj           $doit $rmcmd -f "$dst" 2>/dev/null ||
    478  1.1.1.2.14.2   snj           { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
    479  1.1.1.2.14.2   snj             { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
    480  1.1.1.2.14.2   snj           } ||
    481  1.1.1.2.14.2   snj           { echo "$0: cannot unlink or rename $dst" >&2
    482  1.1.1.2.14.2   snj             (exit 1); exit 1
    483  1.1.1.2.14.2   snj           }
    484  1.1.1.2.14.2   snj         } &&
    485       1.1.1.2   spz 
    486  1.1.1.2.14.2   snj         # Now rename the file to the real destination.
    487  1.1.1.2.14.2   snj         $doit $mvcmd "$dsttmp" "$dst"
    488       1.1.1.2   spz       }
    489       1.1.1.2   spz     fi || exit 1
    490           1.1  tron 
    491       1.1.1.2   spz     trap '' 0
    492       1.1.1.2   spz   fi
    493       1.1.1.2   spz done
    494           1.1  tron 
    495       1.1.1.2   spz # Local variables:
    496       1.1.1.2   spz # eval: (add-hook 'write-file-hooks 'time-stamp)
    497       1.1.1.2   spz # time-stamp-start: "scriptversion="
    498       1.1.1.2   spz # time-stamp-format: "%:y-%02m-%02d.%02H"
    499       1.1.1.2   spz # time-stamp-time-zone: "UTC"
    500       1.1.1.2   spz # time-stamp-end: "; # UTC"
    501       1.1.1.2   spz # End:
    502