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