Blame install-sh

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