install-sh revision 9aa228fd
19aa228fdSmrg#!/bin/sh
29aa228fdSmrg# install - install a program, script, or datafile
39aa228fdSmrg
49aa228fdSmrgscriptversion=2006-10-14.15
59aa228fdSmrg
69aa228fdSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was
79aa228fdSmrg# later released in X11R6 (xc/config/util/install.sh) with the
89aa228fdSmrg# following copyright and license.
99aa228fdSmrg#
109aa228fdSmrg# Copyright (C) 1994 X Consortium
119aa228fdSmrg#
129aa228fdSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy
139aa228fdSmrg# of this software and associated documentation files (the "Software"), to
149aa228fdSmrg# deal in the Software without restriction, including without limitation the
159aa228fdSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
169aa228fdSmrg# sell copies of the Software, and to permit persons to whom the Software is
179aa228fdSmrg# furnished to do so, subject to the following conditions:
189aa228fdSmrg#
199aa228fdSmrg# The above copyright notice and this permission notice shall be included in
209aa228fdSmrg# all copies or substantial portions of the Software.
219aa228fdSmrg#
229aa228fdSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
239aa228fdSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
249aa228fdSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
259aa228fdSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
269aa228fdSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
279aa228fdSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
289aa228fdSmrg#
299aa228fdSmrg# Except as contained in this notice, the name of the X Consortium shall not
309aa228fdSmrg# be used in advertising or otherwise to promote the sale, use or other deal-
319aa228fdSmrg# ings in this Software without prior written authorization from the X Consor-
329aa228fdSmrg# tium.
339aa228fdSmrg#
349aa228fdSmrg#
359aa228fdSmrg# FSF changes to this file are in the public domain.
369aa228fdSmrg#
379aa228fdSmrg# Calling this script install-sh is preferred over install.sh, to prevent
389aa228fdSmrg# `make' implicit rules from creating a file called install from it
399aa228fdSmrg# when there is no Makefile.
409aa228fdSmrg#
419aa228fdSmrg# This script is compatible with the BSD install script, but was written
429aa228fdSmrg# from scratch.
439aa228fdSmrg
449aa228fdSmrgnl='
459aa228fdSmrg'
469aa228fdSmrgIFS=" ""	$nl"
479aa228fdSmrg
489aa228fdSmrg# set DOITPROG to echo to test this script
499aa228fdSmrg
509aa228fdSmrg# Don't use :- since 4.3BSD and earlier shells don't like it.
519aa228fdSmrgdoit="${DOITPROG-}"
529aa228fdSmrgif test -z "$doit"; then
539aa228fdSmrg  doit_exec=exec
549aa228fdSmrgelse
559aa228fdSmrg  doit_exec=$doit
569aa228fdSmrgfi
579aa228fdSmrg
589aa228fdSmrg# Put in absolute file names if you don't have them in your path;
599aa228fdSmrg# or use environment vars.
609aa228fdSmrg
619aa228fdSmrgmvprog="${MVPROG-mv}"
629aa228fdSmrgcpprog="${CPPROG-cp}"
639aa228fdSmrgchmodprog="${CHMODPROG-chmod}"
649aa228fdSmrgchownprog="${CHOWNPROG-chown}"
659aa228fdSmrgchgrpprog="${CHGRPPROG-chgrp}"
669aa228fdSmrgstripprog="${STRIPPROG-strip}"
679aa228fdSmrgrmprog="${RMPROG-rm}"
689aa228fdSmrgmkdirprog="${MKDIRPROG-mkdir}"
699aa228fdSmrg
709aa228fdSmrgposix_glob=
719aa228fdSmrgposix_mkdir=
729aa228fdSmrg
739aa228fdSmrg# Desired mode of installed file.
749aa228fdSmrgmode=0755
759aa228fdSmrg
769aa228fdSmrgchmodcmd=$chmodprog
779aa228fdSmrgchowncmd=
789aa228fdSmrgchgrpcmd=
799aa228fdSmrgstripcmd=
809aa228fdSmrgrmcmd="$rmprog -f"
819aa228fdSmrgmvcmd="$mvprog"
829aa228fdSmrgsrc=
839aa228fdSmrgdst=
849aa228fdSmrgdir_arg=
859aa228fdSmrgdstarg=
869aa228fdSmrgno_target_directory=
879aa228fdSmrg
889aa228fdSmrgusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
899aa228fdSmrg   or: $0 [OPTION]... SRCFILES... DIRECTORY
909aa228fdSmrg   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
919aa228fdSmrg   or: $0 [OPTION]... -d DIRECTORIES...
929aa228fdSmrg
939aa228fdSmrgIn the 1st form, copy SRCFILE to DSTFILE.
949aa228fdSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
959aa228fdSmrgIn the 4th, create DIRECTORIES.
969aa228fdSmrg
979aa228fdSmrgOptions:
989aa228fdSmrg-c         (ignored)
999aa228fdSmrg-d         create directories instead of installing files.
1009aa228fdSmrg-g GROUP   $chgrpprog installed files to GROUP.
1019aa228fdSmrg-m MODE    $chmodprog installed files to MODE.
1029aa228fdSmrg-o USER    $chownprog installed files to USER.
1039aa228fdSmrg-s         $stripprog installed files.
1049aa228fdSmrg-t DIRECTORY  install into DIRECTORY.
1059aa228fdSmrg-T         report an error if DSTFILE is a directory.
1069aa228fdSmrg--help     display this help and exit.
1079aa228fdSmrg--version  display version info and exit.
1089aa228fdSmrg
1099aa228fdSmrgEnvironment variables override the default commands:
1109aa228fdSmrg  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
1119aa228fdSmrg"
1129aa228fdSmrg
1139aa228fdSmrgwhile test $# -ne 0; do
1149aa228fdSmrg  case $1 in
1159aa228fdSmrg    -c) shift
1169aa228fdSmrg        continue;;
1179aa228fdSmrg
1189aa228fdSmrg    -d) dir_arg=true
1199aa228fdSmrg        shift
1209aa228fdSmrg        continue;;
1219aa228fdSmrg
1229aa228fdSmrg    -g) chgrpcmd="$chgrpprog $2"
1239aa228fdSmrg        shift
1249aa228fdSmrg        shift
1259aa228fdSmrg        continue;;
1269aa228fdSmrg
1279aa228fdSmrg    --help) echo "$usage"; exit $?;;
1289aa228fdSmrg
1299aa228fdSmrg    -m) mode=$2
1309aa228fdSmrg        shift
1319aa228fdSmrg        shift
1329aa228fdSmrg	case $mode in
1339aa228fdSmrg	  *' '* | *'	'* | *'
1349aa228fdSmrg'*	  | *'*'* | *'?'* | *'['*)
1359aa228fdSmrg	    echo "$0: invalid mode: $mode" >&2
1369aa228fdSmrg	    exit 1;;
1379aa228fdSmrg	esac
1389aa228fdSmrg        continue;;
1399aa228fdSmrg
1409aa228fdSmrg    -o) chowncmd="$chownprog $2"
1419aa228fdSmrg        shift
1429aa228fdSmrg        shift
1439aa228fdSmrg        continue;;
1449aa228fdSmrg
1459aa228fdSmrg    -s) stripcmd=$stripprog
1469aa228fdSmrg        shift
1479aa228fdSmrg        continue;;
1489aa228fdSmrg
1499aa228fdSmrg    -t) dstarg=$2
1509aa228fdSmrg	shift
1519aa228fdSmrg	shift
1529aa228fdSmrg	continue;;
1539aa228fdSmrg
1549aa228fdSmrg    -T) no_target_directory=true
1559aa228fdSmrg	shift
1569aa228fdSmrg	continue;;
1579aa228fdSmrg
1589aa228fdSmrg    --version) echo "$0 $scriptversion"; exit $?;;
1599aa228fdSmrg
1609aa228fdSmrg    --)	shift
1619aa228fdSmrg	break;;
1629aa228fdSmrg
1639aa228fdSmrg    -*)	echo "$0: invalid option: $1" >&2
1649aa228fdSmrg	exit 1;;
1659aa228fdSmrg
1669aa228fdSmrg    *)  break;;
1679aa228fdSmrg  esac
1689aa228fdSmrgdone
1699aa228fdSmrg
1709aa228fdSmrgif test $# -ne 0 && test -z "$dir_arg$dstarg"; then
1719aa228fdSmrg  # When -d is used, all remaining arguments are directories to create.
1729aa228fdSmrg  # When -t is used, the destination is already specified.
1739aa228fdSmrg  # Otherwise, the last argument is the destination.  Remove it from $@.
1749aa228fdSmrg  for arg
1759aa228fdSmrg  do
1769aa228fdSmrg    if test -n "$dstarg"; then
1779aa228fdSmrg      # $@ is not empty: it contains at least $arg.
1789aa228fdSmrg      set fnord "$@" "$dstarg"
1799aa228fdSmrg      shift # fnord
1809aa228fdSmrg    fi
1819aa228fdSmrg    shift # arg
1829aa228fdSmrg    dstarg=$arg
1839aa228fdSmrg  done
1849aa228fdSmrgfi
1859aa228fdSmrg
1869aa228fdSmrgif test $# -eq 0; then
1879aa228fdSmrg  if test -z "$dir_arg"; then
1889aa228fdSmrg    echo "$0: no input file specified." >&2
1899aa228fdSmrg    exit 1
1909aa228fdSmrg  fi
1919aa228fdSmrg  # It's OK to call `install-sh -d' without argument.
1929aa228fdSmrg  # This can happen when creating conditional directories.
1939aa228fdSmrg  exit 0
1949aa228fdSmrgfi
1959aa228fdSmrg
1969aa228fdSmrgif test -z "$dir_arg"; then
1979aa228fdSmrg  trap '(exit $?); exit' 1 2 13 15
1989aa228fdSmrg
1999aa228fdSmrg  # Set umask so as not to create temps with too-generous modes.
2009aa228fdSmrg  # However, 'strip' requires both read and write access to temps.
2019aa228fdSmrg  case $mode in
2029aa228fdSmrg    # Optimize common cases.
2039aa228fdSmrg    *644) cp_umask=133;;
2049aa228fdSmrg    *755) cp_umask=22;;
2059aa228fdSmrg
2069aa228fdSmrg    *[0-7])
2079aa228fdSmrg      if test -z "$stripcmd"; then
2089aa228fdSmrg	u_plus_rw=
2099aa228fdSmrg      else
2109aa228fdSmrg	u_plus_rw='% 200'
2119aa228fdSmrg      fi
2129aa228fdSmrg      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
2139aa228fdSmrg    *)
2149aa228fdSmrg      if test -z "$stripcmd"; then
2159aa228fdSmrg	u_plus_rw=
2169aa228fdSmrg      else
2179aa228fdSmrg	u_plus_rw=,u+rw
2189aa228fdSmrg      fi
2199aa228fdSmrg      cp_umask=$mode$u_plus_rw;;
2209aa228fdSmrg  esac
2219aa228fdSmrgfi
2229aa228fdSmrg
2239aa228fdSmrgfor src
2249aa228fdSmrgdo
2259aa228fdSmrg  # Protect names starting with `-'.
2269aa228fdSmrg  case $src in
2279aa228fdSmrg    -*) src=./$src ;;
2289aa228fdSmrg  esac
2299aa228fdSmrg
2309aa228fdSmrg  if test -n "$dir_arg"; then
2319aa228fdSmrg    dst=$src
2329aa228fdSmrg    dstdir=$dst
2339aa228fdSmrg    test -d "$dstdir"
2349aa228fdSmrg    dstdir_status=$?
2359aa228fdSmrg  else
2369aa228fdSmrg
2379aa228fdSmrg    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
2389aa228fdSmrg    # might cause directories to be created, which would be especially bad
2399aa228fdSmrg    # if $src (and thus $dsttmp) contains '*'.
2409aa228fdSmrg    if test ! -f "$src" && test ! -d "$src"; then
2419aa228fdSmrg      echo "$0: $src does not exist." >&2
2429aa228fdSmrg      exit 1
2439aa228fdSmrg    fi
2449aa228fdSmrg
2459aa228fdSmrg    if test -z "$dstarg"; then
2469aa228fdSmrg      echo "$0: no destination specified." >&2
2479aa228fdSmrg      exit 1
2489aa228fdSmrg    fi
2499aa228fdSmrg
2509aa228fdSmrg    dst=$dstarg
2519aa228fdSmrg    # Protect names starting with `-'.
2529aa228fdSmrg    case $dst in
2539aa228fdSmrg      -*) dst=./$dst ;;
2549aa228fdSmrg    esac
2559aa228fdSmrg
2569aa228fdSmrg    # If destination is a directory, append the input filename; won't work
2579aa228fdSmrg    # if double slashes aren't ignored.
2589aa228fdSmrg    if test -d "$dst"; then
2599aa228fdSmrg      if test -n "$no_target_directory"; then
2609aa228fdSmrg	echo "$0: $dstarg: Is a directory" >&2
2619aa228fdSmrg	exit 1
2629aa228fdSmrg      fi
2639aa228fdSmrg      dstdir=$dst
2649aa228fdSmrg      dst=$dstdir/`basename "$src"`
2659aa228fdSmrg      dstdir_status=0
2669aa228fdSmrg    else
2679aa228fdSmrg      # Prefer dirname, but fall back on a substitute if dirname fails.
2689aa228fdSmrg      dstdir=`
2699aa228fdSmrg	(dirname "$dst") 2>/dev/null ||
2709aa228fdSmrg	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
2719aa228fdSmrg	     X"$dst" : 'X\(//\)[^/]' \| \
2729aa228fdSmrg	     X"$dst" : 'X\(//\)$' \| \
2739aa228fdSmrg	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
2749aa228fdSmrg	echo X"$dst" |
2759aa228fdSmrg	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
2769aa228fdSmrg		   s//\1/
2779aa228fdSmrg		   q
2789aa228fdSmrg		 }
2799aa228fdSmrg		 /^X\(\/\/\)[^/].*/{
2809aa228fdSmrg		   s//\1/
2819aa228fdSmrg		   q
2829aa228fdSmrg		 }
2839aa228fdSmrg		 /^X\(\/\/\)$/{
2849aa228fdSmrg		   s//\1/
2859aa228fdSmrg		   q
2869aa228fdSmrg		 }
2879aa228fdSmrg		 /^X\(\/\).*/{
2889aa228fdSmrg		   s//\1/
2899aa228fdSmrg		   q
2909aa228fdSmrg		 }
2919aa228fdSmrg		 s/.*/./; q'
2929aa228fdSmrg      `
2939aa228fdSmrg
2949aa228fdSmrg      test -d "$dstdir"
2959aa228fdSmrg      dstdir_status=$?
2969aa228fdSmrg    fi
2979aa228fdSmrg  fi
2989aa228fdSmrg
2999aa228fdSmrg  obsolete_mkdir_used=false
3009aa228fdSmrg
3019aa228fdSmrg  if test $dstdir_status != 0; then
3029aa228fdSmrg    case $posix_mkdir in
3039aa228fdSmrg      '')
3049aa228fdSmrg	# Create intermediate dirs using mode 755 as modified by the umask.
3059aa228fdSmrg	# This is like FreeBSD 'install' as of 1997-10-28.
3069aa228fdSmrg	umask=`umask`
3079aa228fdSmrg	case $stripcmd.$umask in
3089aa228fdSmrg	  # Optimize common cases.
3099aa228fdSmrg	  *[2367][2367]) mkdir_umask=$umask;;
3109aa228fdSmrg	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
3119aa228fdSmrg
3129aa228fdSmrg	  *[0-7])
3139aa228fdSmrg	    mkdir_umask=`expr $umask + 22 \
3149aa228fdSmrg	      - $umask % 100 % 40 + $umask % 20 \
3159aa228fdSmrg	      - $umask % 10 % 4 + $umask % 2
3169aa228fdSmrg	    `;;
3179aa228fdSmrg	  *) mkdir_umask=$umask,go-w;;
3189aa228fdSmrg	esac
3199aa228fdSmrg
3209aa228fdSmrg	# With -d, create the new directory with the user-specified mode.
3219aa228fdSmrg	# Otherwise, rely on $mkdir_umask.
3229aa228fdSmrg	if test -n "$dir_arg"; then
3239aa228fdSmrg	  mkdir_mode=-m$mode
3249aa228fdSmrg	else
3259aa228fdSmrg	  mkdir_mode=
3269aa228fdSmrg	fi
3279aa228fdSmrg
3289aa228fdSmrg	posix_mkdir=false
3299aa228fdSmrg	case $umask in
3309aa228fdSmrg	  *[123567][0-7][0-7])
3319aa228fdSmrg	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
3329aa228fdSmrg	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
3339aa228fdSmrg	    ;;
3349aa228fdSmrg	  *)
3359aa228fdSmrg	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
3369aa228fdSmrg	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
3379aa228fdSmrg
3389aa228fdSmrg	    if (umask $mkdir_umask &&
3399aa228fdSmrg		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
3409aa228fdSmrg	    then
3419aa228fdSmrg	      if test -z "$dir_arg" || {
3429aa228fdSmrg		   # Check for POSIX incompatibilities with -m.
3439aa228fdSmrg		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
3449aa228fdSmrg		   # other-writeable bit of parent directory when it shouldn't.
3459aa228fdSmrg		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
3469aa228fdSmrg		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
3479aa228fdSmrg		   case $ls_ld_tmpdir in
3489aa228fdSmrg		     d????-?r-*) different_mode=700;;
3499aa228fdSmrg		     d????-?--*) different_mode=755;;
3509aa228fdSmrg		     *) false;;
3519aa228fdSmrg		   esac &&
3529aa228fdSmrg		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
3539aa228fdSmrg		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
3549aa228fdSmrg		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
3559aa228fdSmrg		   }
3569aa228fdSmrg		 }
3579aa228fdSmrg	      then posix_mkdir=:
3589aa228fdSmrg	      fi
3599aa228fdSmrg	      rmdir "$tmpdir/d" "$tmpdir"
3609aa228fdSmrg	    else
3619aa228fdSmrg	      # Remove any dirs left behind by ancient mkdir implementations.
3629aa228fdSmrg	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
3639aa228fdSmrg	    fi
3649aa228fdSmrg	    trap '' 0;;
3659aa228fdSmrg	esac;;
3669aa228fdSmrg    esac
3679aa228fdSmrg
3689aa228fdSmrg    if
3699aa228fdSmrg      $posix_mkdir && (
3709aa228fdSmrg	umask $mkdir_umask &&
3719aa228fdSmrg	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
3729aa228fdSmrg      )
3739aa228fdSmrg    then :
3749aa228fdSmrg    else
3759aa228fdSmrg
3769aa228fdSmrg      # The umask is ridiculous, or mkdir does not conform to POSIX,
3779aa228fdSmrg      # or it failed possibly due to a race condition.  Create the
3789aa228fdSmrg      # directory the slow way, step by step, checking for races as we go.
3799aa228fdSmrg
3809aa228fdSmrg      case $dstdir in
3819aa228fdSmrg	/*) prefix=/ ;;
3829aa228fdSmrg	-*) prefix=./ ;;
3839aa228fdSmrg	*)  prefix= ;;
3849aa228fdSmrg      esac
3859aa228fdSmrg
3869aa228fdSmrg      case $posix_glob in
3879aa228fdSmrg        '')
3889aa228fdSmrg	  if (set -f) 2>/dev/null; then
3899aa228fdSmrg	    posix_glob=true
3909aa228fdSmrg	  else
3919aa228fdSmrg	    posix_glob=false
3929aa228fdSmrg	  fi ;;
3939aa228fdSmrg      esac
3949aa228fdSmrg
3959aa228fdSmrg      oIFS=$IFS
3969aa228fdSmrg      IFS=/
3979aa228fdSmrg      $posix_glob && set -f
3989aa228fdSmrg      set fnord $dstdir
3999aa228fdSmrg      shift
4009aa228fdSmrg      $posix_glob && set +f
4019aa228fdSmrg      IFS=$oIFS
4029aa228fdSmrg
4039aa228fdSmrg      prefixes=
4049aa228fdSmrg
4059aa228fdSmrg      for d
4069aa228fdSmrg      do
4079aa228fdSmrg	test -z "$d" && continue
4089aa228fdSmrg
4099aa228fdSmrg	prefix=$prefix$d
4109aa228fdSmrg	if test -d "$prefix"; then
4119aa228fdSmrg	  prefixes=
4129aa228fdSmrg	else
4139aa228fdSmrg	  if $posix_mkdir; then
4149aa228fdSmrg	    (umask=$mkdir_umask &&
4159aa228fdSmrg	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
4169aa228fdSmrg	    # Don't fail if two instances are running concurrently.
4179aa228fdSmrg	    test -d "$prefix" || exit 1
4189aa228fdSmrg	  else
4199aa228fdSmrg	    case $prefix in
4209aa228fdSmrg	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
4219aa228fdSmrg	      *) qprefix=$prefix;;
4229aa228fdSmrg	    esac
4239aa228fdSmrg	    prefixes="$prefixes '$qprefix'"
4249aa228fdSmrg	  fi
4259aa228fdSmrg	fi
4269aa228fdSmrg	prefix=$prefix/
4279aa228fdSmrg      done
4289aa228fdSmrg
4299aa228fdSmrg      if test -n "$prefixes"; then
4309aa228fdSmrg	# Don't fail if two instances are running concurrently.
4319aa228fdSmrg	(umask $mkdir_umask &&
4329aa228fdSmrg	 eval "\$doit_exec \$mkdirprog $prefixes") ||
4339aa228fdSmrg	  test -d "$dstdir" || exit 1
4349aa228fdSmrg	obsolete_mkdir_used=true
4359aa228fdSmrg      fi
4369aa228fdSmrg    fi
4379aa228fdSmrg  fi
4389aa228fdSmrg
4399aa228fdSmrg  if test -n "$dir_arg"; then
4409aa228fdSmrg    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
4419aa228fdSmrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
4429aa228fdSmrg    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
4439aa228fdSmrg      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
4449aa228fdSmrg  else
4459aa228fdSmrg
4469aa228fdSmrg    # Make a couple of temp file names in the proper directory.
4479aa228fdSmrg    dsttmp=$dstdir/_inst.$$_
4489aa228fdSmrg    rmtmp=$dstdir/_rm.$$_
4499aa228fdSmrg
4509aa228fdSmrg    # Trap to clean up those temp files at exit.
4519aa228fdSmrg    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
4529aa228fdSmrg
4539aa228fdSmrg    # Copy the file name to the temp name.
4549aa228fdSmrg    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
4559aa228fdSmrg
4569aa228fdSmrg    # and set any options; do chmod last to preserve setuid bits.
4579aa228fdSmrg    #
4589aa228fdSmrg    # If any of these fail, we abort the whole thing.  If we want to
4599aa228fdSmrg    # ignore errors from any of these, just make sure not to ignore
4609aa228fdSmrg    # errors from the above "$doit $cpprog $src $dsttmp" command.
4619aa228fdSmrg    #
4629aa228fdSmrg    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
4639aa228fdSmrg      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
4649aa228fdSmrg      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
4659aa228fdSmrg      && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
4669aa228fdSmrg
4679aa228fdSmrg    # Now rename the file to the real destination.
4689aa228fdSmrg    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
4699aa228fdSmrg      || {
4709aa228fdSmrg	   # The rename failed, perhaps because mv can't rename something else
4719aa228fdSmrg	   # to itself, or perhaps because mv is so ancient that it does not
4729aa228fdSmrg	   # support -f.
4739aa228fdSmrg
4749aa228fdSmrg	   # Now remove or move aside any old file at destination location.
4759aa228fdSmrg	   # We try this two ways since rm can't unlink itself on some
4769aa228fdSmrg	   # systems and the destination file might be busy for other
4779aa228fdSmrg	   # reasons.  In this case, the final cleanup might fail but the new
4789aa228fdSmrg	   # file should still install successfully.
4799aa228fdSmrg	   {
4809aa228fdSmrg	     if test -f "$dst"; then
4819aa228fdSmrg	       $doit $rmcmd -f "$dst" 2>/dev/null \
4829aa228fdSmrg	       || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
4839aa228fdSmrg		     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
4849aa228fdSmrg	       || {
4859aa228fdSmrg		 echo "$0: cannot unlink or rename $dst" >&2
4869aa228fdSmrg		 (exit 1); exit 1
4879aa228fdSmrg	       }
4889aa228fdSmrg	     else
4899aa228fdSmrg	       :
4909aa228fdSmrg	     fi
4919aa228fdSmrg	   } &&
4929aa228fdSmrg
4939aa228fdSmrg	   # Now rename the file to the real destination.
4949aa228fdSmrg	   $doit $mvcmd "$dsttmp" "$dst"
4959aa228fdSmrg	 }
4969aa228fdSmrg    } || exit 1
4979aa228fdSmrg
4989aa228fdSmrg    trap '' 0
4999aa228fdSmrg  fi
5009aa228fdSmrgdone
5019aa228fdSmrg
5029aa228fdSmrg# Local variables:
5039aa228fdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
5049aa228fdSmrg# time-stamp-start: "scriptversion="
5059aa228fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
5069aa228fdSmrg# time-stamp-end: "$"
5079aa228fdSmrg# End:
508