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