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