Blame install-sh

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