Blame config/install-sh

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