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