roentgen b75cab
#!/bin/sh
roentgen b75cab
# install - install a program, script, or datafile
roentgen b75cab
roentgen b75cab
scriptversion=2006-10-14.15
roentgen b75cab
roentgen b75cab
# This originates from X11R5 (mit/util/scripts/install.sh), which was
roentgen b75cab
# later released in X11R6 (xc/config/util/install.sh) with the
roentgen b75cab
# following copyright and license.
roentgen b75cab
#
roentgen b75cab
# Copyright (C) 1994 X Consortium
roentgen b75cab
#
roentgen b75cab
# Permission is hereby granted, free of charge, to any person obtaining a copy
roentgen b75cab
# of this software and associated documentation files (the "Software"), to
roentgen b75cab
# deal in the Software without restriction, including without limitation the
roentgen b75cab
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
roentgen b75cab
# sell copies of the Software, and to permit persons to whom the Software is
roentgen b75cab
# furnished to do so, subject to the following conditions:
roentgen b75cab
#
roentgen b75cab
# The above copyright notice and this permission notice shall be included in
roentgen b75cab
# all copies or substantial portions of the Software.
roentgen b75cab
#
roentgen b75cab
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
roentgen b75cab
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
roentgen b75cab
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
roentgen b75cab
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
roentgen b75cab
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
roentgen b75cab
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
roentgen b75cab
#
roentgen b75cab
# Except as contained in this notice, the name of the X Consortium shall not
roentgen b75cab
# be used in advertising or otherwise to promote the sale, use or other deal-
roentgen b75cab
# ings in this Software without prior written authorization from the X Consor-
roentgen b75cab
# tium.
roentgen b75cab
#
roentgen b75cab
#
roentgen b75cab
# FSF changes to this file are in the public domain.
roentgen b75cab
#
roentgen b75cab
# Calling this script install-sh is preferred over install.sh, to prevent
roentgen b75cab
# `make' implicit rules from creating a file called install from it
roentgen b75cab
# when there is no Makefile.
roentgen b75cab
#
roentgen b75cab
# This script is compatible with the BSD install script, but was written
roentgen b75cab
# from scratch.
roentgen b75cab
roentgen b75cab
nl='
roentgen b75cab
'
roentgen b75cab
IFS=" ""	$nl"
roentgen b75cab
roentgen b75cab
# set DOITPROG to echo to test this script
roentgen b75cab
roentgen b75cab
# Don't use :- since 4.3BSD and earlier shells don't like it.
roentgen b75cab
doit="${DOITPROG-}"
roentgen b75cab
if test -z "$doit"; then
roentgen b75cab
  doit_exec=exec
roentgen b75cab
else
roentgen b75cab
  doit_exec=$doit
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
# Put in absolute file names if you don't have them in your path;
roentgen b75cab
# or use environment vars.
roentgen b75cab
roentgen b75cab
mvprog="${MVPROG-mv}"
roentgen b75cab
cpprog="${CPPROG-cp}"
roentgen b75cab
chmodprog="${CHMODPROG-chmod}"
roentgen b75cab
chownprog="${CHOWNPROG-chown}"
roentgen b75cab
chgrpprog="${CHGRPPROG-chgrp}"
roentgen b75cab
stripprog="${STRIPPROG-strip}"
roentgen b75cab
rmprog="${RMPROG-rm}"
roentgen b75cab
mkdirprog="${MKDIRPROG-mkdir}"
roentgen b75cab
roentgen b75cab
posix_glob=
roentgen b75cab
posix_mkdir=
roentgen b75cab
roentgen b75cab
# Desired mode of installed file.
roentgen b75cab
mode=0755
roentgen b75cab
roentgen b75cab
chmodcmd=$chmodprog
roentgen b75cab
chowncmd=
roentgen b75cab
chgrpcmd=
roentgen b75cab
stripcmd=
roentgen b75cab
rmcmd="$rmprog -f"
roentgen b75cab
mvcmd="$mvprog"
roentgen b75cab
src=
roentgen b75cab
dst=
roentgen b75cab
dir_arg=
roentgen b75cab
dstarg=
roentgen b75cab
no_target_directory=
roentgen b75cab
roentgen b75cab
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
roentgen b75cab
   or: $0 [OPTION]... SRCFILES... DIRECTORY
roentgen b75cab
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
roentgen b75cab
   or: $0 [OPTION]... -d DIRECTORIES...
roentgen b75cab
roentgen b75cab
In the 1st form, copy SRCFILE to DSTFILE.
roentgen b75cab
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
roentgen b75cab
In the 4th, create DIRECTORIES.
roentgen b75cab
roentgen b75cab
Options:
roentgen b75cab
-c         (ignored)
roentgen b75cab
-d         create directories instead of installing files.
roentgen b75cab
-g GROUP   $chgrpprog installed files to GROUP.
roentgen b75cab
-m MODE    $chmodprog installed files to MODE.
roentgen b75cab
-o USER    $chownprog installed files to USER.
roentgen b75cab
-s         $stripprog installed files.
roentgen b75cab
-t DIRECTORY  install into DIRECTORY.
roentgen b75cab
-T         report an error if DSTFILE is a directory.
roentgen b75cab
--help     display this help and exit.
roentgen b75cab
--version  display version info and exit.
roentgen b75cab
roentgen b75cab
Environment variables override the default commands:
roentgen b75cab
  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
roentgen b75cab
"
roentgen b75cab
roentgen b75cab
while test $# -ne 0; do
roentgen b75cab
  case $1 in
roentgen b75cab
    -c) shift
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    -d) dir_arg=true
roentgen b75cab
        shift
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    -g) chgrpcmd="$chgrpprog $2"
roentgen b75cab
        shift
roentgen b75cab
        shift
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    --help) echo "$usage"; exit $?;;
roentgen b75cab
roentgen b75cab
    -m) mode=$2
roentgen b75cab
        shift
roentgen b75cab
        shift
roentgen b75cab
	case $mode in
roentgen b75cab
	  *' '* | *'	'* | *'
roentgen b75cab
'*	  | *'*'* | *'?'* | *'['*)
roentgen b75cab
	    echo "$0: invalid mode: $mode" >&2
roentgen b75cab
	    exit 1;;
roentgen b75cab
	esac
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    -o) chowncmd="$chownprog $2"
roentgen b75cab
        shift
roentgen b75cab
        shift
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    -s) stripcmd=$stripprog
roentgen b75cab
        shift
roentgen b75cab
        continue;;
roentgen b75cab
roentgen b75cab
    -t) dstarg=$2
roentgen b75cab
	shift
roentgen b75cab
	shift
roentgen b75cab
	continue;;
roentgen b75cab
roentgen b75cab
    -T) no_target_directory=true
roentgen b75cab
	shift
roentgen b75cab
	continue;;
roentgen b75cab
roentgen b75cab
    --version) echo "$0 $scriptversion"; exit $?;;
roentgen b75cab
roentgen b75cab
    --)	shift
roentgen b75cab
	break;;
roentgen b75cab
roentgen b75cab
    -*)	echo "$0: invalid option: $1" >&2
roentgen b75cab
	exit 1;;
roentgen b75cab
roentgen b75cab
    *)  break;;
roentgen b75cab
  esac
roentgen b75cab
done
roentgen b75cab
roentgen b75cab
if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
roentgen b75cab
  # When -d is used, all remaining arguments are directories to create.
roentgen b75cab
  # When -t is used, the destination is already specified.
roentgen b75cab
  # Otherwise, the last argument is the destination.  Remove it from $@.
roentgen b75cab
  for arg
roentgen b75cab
  do
roentgen b75cab
    if test -n "$dstarg"; then
roentgen b75cab
      # $@ is not empty: it contains at least $arg.
roentgen b75cab
      set fnord "$@" "$dstarg"
roentgen b75cab
      shift # fnord
roentgen b75cab
    fi
roentgen b75cab
    shift # arg
roentgen b75cab
    dstarg=$arg
roentgen b75cab
  done
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
if test $# -eq 0; then
roentgen b75cab
  if test -z "$dir_arg"; then
roentgen b75cab
    echo "$0: no input file specified." >&2
roentgen b75cab
    exit 1
roentgen b75cab
  fi
roentgen b75cab
  # It's OK to call `install-sh -d' without argument.
roentgen b75cab
  # This can happen when creating conditional directories.
roentgen b75cab
  exit 0
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
if test -z "$dir_arg"; then
roentgen b75cab
  trap '(exit $?); exit' 1 2 13 15
roentgen b75cab
roentgen b75cab
  # Set umask so as not to create temps with too-generous modes.
roentgen b75cab
  # However, 'strip' requires both read and write access to temps.
roentgen b75cab
  case $mode in
roentgen b75cab
    # Optimize common cases.
roentgen b75cab
    *644) cp_umask=133;;
roentgen b75cab
    *755) cp_umask=22;;
roentgen b75cab
roentgen b75cab
    *[0-7])
roentgen b75cab
      if test -z "$stripcmd"; then
roentgen b75cab
	u_plus_rw=
roentgen b75cab
      else
roentgen b75cab
	u_plus_rw='% 200'
roentgen b75cab
      fi
roentgen b75cab
      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
roentgen b75cab
    *)
roentgen b75cab
      if test -z "$stripcmd"; then
roentgen b75cab
	u_plus_rw=
roentgen b75cab
      else
roentgen b75cab
	u_plus_rw=,u+rw
roentgen b75cab
      fi
roentgen b75cab
      cp_umask=$mode$u_plus_rw;;
roentgen b75cab
  esac
roentgen b75cab
fi
roentgen b75cab
roentgen b75cab
for src
roentgen b75cab
do
roentgen b75cab
  # Protect names starting with `-'.
roentgen b75cab
  case $src in
roentgen b75cab
    -*) src=./$src ;;
roentgen b75cab
  esac
roentgen b75cab
roentgen b75cab
  if test -n "$dir_arg"; then
roentgen b75cab
    dst=$src
roentgen b75cab
    dstdir=$dst
roentgen b75cab
    test -d "$dstdir"
roentgen b75cab
    dstdir_status=$?
roentgen b75cab
  else
roentgen b75cab
roentgen b75cab
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
roentgen b75cab
    # might cause directories to be created, which would be especially bad
roentgen b75cab
    # if $src (and thus $dsttmp) contains '*'.
roentgen b75cab
    if test ! -f "$src" && test ! -d "$src"; then
roentgen b75cab
      echo "$0: $src does not exist." >&2
roentgen b75cab
      exit 1
roentgen b75cab
    fi
roentgen b75cab
roentgen b75cab
    if test -z "$dstarg"; then
roentgen b75cab
      echo "$0: no destination specified." >&2
roentgen b75cab
      exit 1
roentgen b75cab
    fi
roentgen b75cab
roentgen b75cab
    dst=$dstarg
roentgen b75cab
    # Protect names starting with `-'.
roentgen b75cab
    case $dst in
roentgen b75cab
      -*) dst=./$dst ;;
roentgen b75cab
    esac
roentgen b75cab
roentgen b75cab
    # If destination is a directory, append the input filename; won't work
roentgen b75cab
    # if double slashes aren't ignored.
roentgen b75cab
    if test -d "$dst"; then
roentgen b75cab
      if test -n "$no_target_directory"; then
roentgen b75cab
	echo "$0: $dstarg: Is a directory" >&2
roentgen b75cab
	exit 1
roentgen b75cab
      fi
roentgen b75cab
      dstdir=$dst
roentgen b75cab
      dst=$dstdir/`basename "$src"`
roentgen b75cab
      dstdir_status=0
roentgen b75cab
    else
roentgen b75cab
      # Prefer dirname, but fall back on a substitute if dirname fails.
roentgen b75cab
      dstdir=`
roentgen b75cab
	(dirname "$dst") 2>/dev/null ||
roentgen b75cab
	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
roentgen b75cab
	     X"$dst" : 'X\(//\)[^/]' \| \
roentgen b75cab
	     X"$dst" : 'X\(//\)$' \| \
roentgen b75cab
	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
roentgen b75cab
	echo X"$dst" |
roentgen b75cab
	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
roentgen b75cab
		   s//\1/
roentgen b75cab
		   q
roentgen b75cab
		 }
roentgen b75cab
		 /^X\(\/\/\)[^/].*/{
roentgen b75cab
		   s//\1/
roentgen b75cab
		   q
roentgen b75cab
		 }
roentgen b75cab
		 /^X\(\/\/\)$/{
roentgen b75cab
		   s//\1/
roentgen b75cab
		   q
roentgen b75cab
		 }
roentgen b75cab
		 /^X\(\/\).*/{
roentgen b75cab
		   s//\1/
roentgen b75cab
		   q
roentgen b75cab
		 }
roentgen b75cab
		 s/.*/./; q'
roentgen b75cab
      `
roentgen b75cab
roentgen b75cab
      test -d "$dstdir"
roentgen b75cab
      dstdir_status=$?
roentgen b75cab
    fi
roentgen b75cab
  fi
roentgen b75cab
roentgen b75cab
  obsolete_mkdir_used=false
roentgen b75cab
roentgen b75cab
  if test $dstdir_status != 0; then
roentgen b75cab
    case $posix_mkdir in
roentgen b75cab
      '')
roentgen b75cab
	# Create intermediate dirs using mode 755 as modified by the umask.
roentgen b75cab
	# This is like FreeBSD 'install' as of 1997-10-28.
roentgen b75cab
	umask=`umask`
roentgen b75cab
	case $stripcmd.$umask in
roentgen b75cab
	  # Optimize common cases.
roentgen b75cab
	  *[2367][2367]) mkdir_umask=$umask;;
roentgen b75cab
	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
roentgen b75cab
roentgen b75cab
	  *[0-7])
roentgen b75cab
	    mkdir_umask=`expr $umask + 22 \
roentgen b75cab
	      - $umask % 100 % 40 + $umask % 20 \
roentgen b75cab
	      - $umask % 10 % 4 + $umask % 2
roentgen b75cab
	    `;;
roentgen b75cab
	  *) mkdir_umask=$umask,go-w;;
roentgen b75cab
	esac
roentgen b75cab
roentgen b75cab
	# With -d, create the new directory with the user-specified mode.
roentgen b75cab
	# Otherwise, rely on $mkdir_umask.
roentgen b75cab
	if test -n "$dir_arg"; then
roentgen b75cab
	  mkdir_mode=-m$mode
roentgen b75cab
	else
roentgen b75cab
	  mkdir_mode=
roentgen b75cab
	fi
roentgen b75cab
roentgen b75cab
	posix_mkdir=false
roentgen b75cab
	case $umask in
roentgen b75cab
	  *[123567][0-7][0-7])
roentgen b75cab
	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
roentgen b75cab
	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
roentgen b75cab
	    ;;
roentgen b75cab
	  *)
roentgen b75cab
	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
roentgen b75cab
	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
roentgen b75cab
roentgen b75cab
	    if (umask $mkdir_umask &&
roentgen b75cab
		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
roentgen b75cab
	    then
roentgen b75cab
	      if test -z "$dir_arg" || {
roentgen b75cab
		   # Check for POSIX incompatibilities with -m.
roentgen b75cab
		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
roentgen b75cab
		   # other-writeable bit of parent directory when it shouldn't.
roentgen b75cab
		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
roentgen b75cab
		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
roentgen b75cab
		   case $ls_ld_tmpdir in
roentgen b75cab
		     d????-?r-*) different_mode=700;;
roentgen b75cab
		     d????-?--*) different_mode=755;;
roentgen b75cab
		     *) false;;
roentgen b75cab
		   esac &&
roentgen b75cab
		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
roentgen b75cab
		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
roentgen b75cab
		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
roentgen b75cab
		   }
roentgen b75cab
		 }
roentgen b75cab
	      then posix_mkdir=:
roentgen b75cab
	      fi
roentgen b75cab
	      rmdir "$tmpdir/d" "$tmpdir"
roentgen b75cab
	    else
roentgen b75cab
	      # Remove any dirs left behind by ancient mkdir implementations.
roentgen b75cab
	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
roentgen b75cab
	    fi
roentgen b75cab
	    trap '' 0;;
roentgen b75cab
	esac;;
roentgen b75cab
    esac
roentgen b75cab
roentgen b75cab
    if
roentgen b75cab
      $posix_mkdir && (
roentgen b75cab
	umask $mkdir_umask &&
roentgen b75cab
	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
roentgen b75cab
      )
roentgen b75cab
    then :
roentgen b75cab
    else
roentgen b75cab
roentgen b75cab
      # The umask is ridiculous, or mkdir does not conform to POSIX,
roentgen b75cab
      # or it failed possibly due to a race condition.  Create the
roentgen b75cab
      # directory the slow way, step by step, checking for races as we go.
roentgen b75cab
roentgen b75cab
      case $dstdir in
roentgen b75cab
	/*) prefix=/ ;;
roentgen b75cab
	-*) prefix=./ ;;
roentgen b75cab
	*)  prefix= ;;
roentgen b75cab
      esac
roentgen b75cab
roentgen b75cab
      case $posix_glob in
roentgen b75cab
        '')
roentgen b75cab
	  if (set -f) 2>/dev/null; then
roentgen b75cab
	    posix_glob=true
roentgen b75cab
	  else
roentgen b75cab
	    posix_glob=false
roentgen b75cab
	  fi ;;
roentgen b75cab
      esac
roentgen b75cab
roentgen b75cab
      oIFS=$IFS
roentgen b75cab
      IFS=/
roentgen b75cab
      $posix_glob && set -f
roentgen b75cab
      set fnord $dstdir
roentgen b75cab
      shift
roentgen b75cab
      $posix_glob && set +f
roentgen b75cab
      IFS=$oIFS
roentgen b75cab
roentgen b75cab
      prefixes=
roentgen b75cab
roentgen b75cab
      for d
roentgen b75cab
      do
roentgen b75cab
	test -z "$d" && continue
roentgen b75cab
roentgen b75cab
	prefix=$prefix$d
roentgen b75cab
	if test -d "$prefix"; then
roentgen b75cab
	  prefixes=
roentgen b75cab
	else
roentgen b75cab
	  if $posix_mkdir; then
roentgen b75cab
	    (umask=$mkdir_umask &&
roentgen b75cab
	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
roentgen b75cab
	    # Don't fail if two instances are running concurrently.
roentgen b75cab
	    test -d "$prefix" || exit 1
roentgen b75cab
	  else
roentgen b75cab
	    case $prefix in
roentgen b75cab
	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
roentgen b75cab
	      *) qprefix=$prefix;;
roentgen b75cab
	    esac
roentgen b75cab
	    prefixes="$prefixes '$qprefix'"
roentgen b75cab
	  fi
roentgen b75cab
	fi
roentgen b75cab
	prefix=$prefix/
roentgen b75cab
      done
roentgen b75cab
roentgen b75cab
      if test -n "$prefixes"; then
roentgen b75cab
	# Don't fail if two instances are running concurrently.
roentgen b75cab
	(umask $mkdir_umask &&
roentgen b75cab
	 eval "\$doit_exec \$mkdirprog $prefixes") ||
roentgen b75cab
	  test -d "$dstdir" || exit 1
roentgen b75cab
	obsolete_mkdir_used=true
roentgen b75cab
      fi
roentgen b75cab
    fi
roentgen b75cab
  fi
roentgen b75cab
roentgen b75cab
  if test -n "$dir_arg"; then
roentgen b75cab
    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
roentgen b75cab
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
roentgen b75cab
    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
roentgen b75cab
      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
roentgen b75cab
  else
roentgen b75cab
roentgen b75cab
    # Make a couple of temp file names in the proper directory.
roentgen b75cab
    dsttmp=$dstdir/_inst.$$_
roentgen b75cab
    rmtmp=$dstdir/_rm.$$_
roentgen b75cab
roentgen b75cab
    # Trap to clean up those temp files at exit.
roentgen b75cab
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
roentgen b75cab
roentgen b75cab
    # Copy the file name to the temp name.
roentgen b75cab
    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
roentgen b75cab
roentgen b75cab
    # and set any options; do chmod last to preserve setuid bits.
roentgen b75cab
    #
roentgen b75cab
    # If any of these fail, we abort the whole thing.  If we want to
roentgen b75cab
    # ignore errors from any of these, just make sure not to ignore
roentgen b75cab
    # errors from the above "$doit $cpprog $src $dsttmp" command.
roentgen b75cab
    #
roentgen b75cab
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
roentgen b75cab
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
roentgen b75cab
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
roentgen b75cab
      && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
roentgen b75cab
roentgen b75cab
    # Now rename the file to the real destination.
roentgen b75cab
    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
roentgen b75cab
      || {
roentgen b75cab
	   # The rename failed, perhaps because mv can't rename something else
roentgen b75cab
	   # to itself, or perhaps because mv is so ancient that it does not
roentgen b75cab
	   # support -f.
roentgen b75cab
roentgen b75cab
	   # Now remove or move aside any old file at destination location.
roentgen b75cab
	   # We try this two ways since rm can't unlink itself on some
roentgen b75cab
	   # systems and the destination file might be busy for other
roentgen b75cab
	   # reasons.  In this case, the final cleanup might fail but the new
roentgen b75cab
	   # file should still install successfully.
roentgen b75cab
	   {
roentgen b75cab
	     if test -f "$dst"; then
roentgen b75cab
	       $doit $rmcmd -f "$dst" 2>/dev/null \
roentgen b75cab
	       || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
roentgen b75cab
		     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
roentgen b75cab
	       || {
roentgen b75cab
		 echo "$0: cannot unlink or rename $dst" >&2
roentgen b75cab
		 (exit 1); exit 1
roentgen b75cab
	       }
roentgen b75cab
	     else
roentgen b75cab
	       :
roentgen b75cab
	     fi
roentgen b75cab
	   } &&
roentgen b75cab
roentgen b75cab
	   # Now rename the file to the real destination.
roentgen b75cab
	   $doit $mvcmd "$dsttmp" "$dst"
roentgen b75cab
	 }
roentgen b75cab
    } || exit 1
roentgen b75cab
roentgen b75cab
    trap '' 0
roentgen b75cab
  fi
roentgen b75cab
done
roentgen b75cab
roentgen b75cab
# Local variables:
roentgen b75cab
# eval: (add-hook 'write-file-hooks 'time-stamp)
roentgen b75cab
# time-stamp-start: "scriptversion="
roentgen b75cab
# time-stamp-format: "%:y-%02m-%02d.%02H"
roentgen b75cab
# time-stamp-end: "$"
roentgen b75cab
# End: