install-sh revision 93493779
16c321187Smrg#!/bin/sh
26c321187Smrg# install - install a program, script, or datafile
36c321187Smrg
493493779Smrgscriptversion=2009-04-28.21; # UTC
56c321187Smrg
66c321187Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was
76c321187Smrg# later released in X11R6 (xc/config/util/install.sh) with the
86c321187Smrg# following copyright and license.
96c321187Smrg#
106c321187Smrg# Copyright (C) 1994 X Consortium
116c321187Smrg#
126c321187Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy
136c321187Smrg# of this software and associated documentation files (the "Software"), to
146c321187Smrg# deal in the Software without restriction, including without limitation the
156c321187Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
166c321187Smrg# sell copies of the Software, and to permit persons to whom the Software is
176c321187Smrg# furnished to do so, subject to the following conditions:
186c321187Smrg#
196c321187Smrg# The above copyright notice and this permission notice shall be included in
206c321187Smrg# all copies or substantial portions of the Software.
216c321187Smrg#
226c321187Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
236c321187Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
246c321187Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
256c321187Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
266c321187Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
276c321187Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
286c321187Smrg#
296c321187Smrg# Except as contained in this notice, the name of the X Consortium shall not
306c321187Smrg# be used in advertising or otherwise to promote the sale, use or other deal-
316c321187Smrg# ings in this Software without prior written authorization from the X Consor-
326c321187Smrg# tium.
336c321187Smrg#
346c321187Smrg#
356c321187Smrg# FSF changes to this file are in the public domain.
366c321187Smrg#
376c321187Smrg# Calling this script install-sh is preferred over install.sh, to prevent
386c321187Smrg# `make' implicit rules from creating a file called install from it
396c321187Smrg# when there is no Makefile.
406c321187Smrg#
416c321187Smrg# This script is compatible with the BSD install script, but was written
426c321187Smrg# from scratch.
436c321187Smrg
446c321187Smrgnl='
456c321187Smrg'
466c321187SmrgIFS=" ""	$nl"
476c321187Smrg
486c321187Smrg# set DOITPROG to echo to test this script
496c321187Smrg
506c321187Smrg# Don't use :- since 4.3BSD and earlier shells don't like it.
5193493779Smrgdoit=${DOITPROG-}
526c321187Smrgif test -z "$doit"; then
536c321187Smrg  doit_exec=exec
546c321187Smrgelse
556c321187Smrg  doit_exec=$doit
566c321187Smrgfi
576c321187Smrg
586c321187Smrg# Put in absolute file names if you don't have them in your path;
596c321187Smrg# or use environment vars.
606c321187Smrg
6193493779Smrgchgrpprog=${CHGRPPROG-chgrp}
6293493779Smrgchmodprog=${CHMODPROG-chmod}
6393493779Smrgchownprog=${CHOWNPROG-chown}
6493493779Smrgcmpprog=${CMPPROG-cmp}
6593493779Smrgcpprog=${CPPROG-cp}
6693493779Smrgmkdirprog=${MKDIRPROG-mkdir}
6793493779Smrgmvprog=${MVPROG-mv}
6893493779Smrgrmprog=${RMPROG-rm}
6993493779Smrgstripprog=${STRIPPROG-strip}
7093493779Smrg
7193493779Smrgposix_glob='?'
7293493779Smrginitialize_posix_glob='
7393493779Smrg  test "$posix_glob" != "?" || {
7493493779Smrg    if (set -f) 2>/dev/null; then
7593493779Smrg      posix_glob=
7693493779Smrg    else
7793493779Smrg      posix_glob=:
7893493779Smrg    fi
7993493779Smrg  }
8093493779Smrg'
816c321187Smrg
826c321187Smrgposix_mkdir=
836c321187Smrg
846c321187Smrg# Desired mode of installed file.
856c321187Smrgmode=0755
866c321187Smrg
8793493779Smrgchgrpcmd=
886c321187Smrgchmodcmd=$chmodprog
896c321187Smrgchowncmd=
9093493779Smrgmvcmd=$mvprog
916c321187Smrgrmcmd="$rmprog -f"
9293493779Smrgstripcmd=
9393493779Smrg
946c321187Smrgsrc=
956c321187Smrgdst=
966c321187Smrgdir_arg=
9793493779Smrgdst_arg=
9893493779Smrg
9993493779Smrgcopy_on_change=false
1006c321187Smrgno_target_directory=
1016c321187Smrg
10293493779Smrgusage="\
10393493779SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
1046c321187Smrg   or: $0 [OPTION]... SRCFILES... DIRECTORY
1056c321187Smrg   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
1066c321187Smrg   or: $0 [OPTION]... -d DIRECTORIES...
1076c321187Smrg
1086c321187SmrgIn the 1st form, copy SRCFILE to DSTFILE.
1096c321187SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
1106c321187SmrgIn the 4th, create DIRECTORIES.
1116c321187Smrg
1126c321187SmrgOptions:
11393493779Smrg     --help     display this help and exit.
11493493779Smrg     --version  display version info and exit.
11593493779Smrg
11693493779Smrg  -c            (ignored)
11793493779Smrg  -C            install only if different (preserve the last data modification time)
11893493779Smrg  -d            create directories instead of installing files.
11993493779Smrg  -g GROUP      $chgrpprog installed files to GROUP.
12093493779Smrg  -m MODE       $chmodprog installed files to MODE.
12193493779Smrg  -o USER       $chownprog installed files to USER.
12293493779Smrg  -s            $stripprog installed files.
12393493779Smrg  -t DIRECTORY  install into DIRECTORY.
12493493779Smrg  -T            report an error if DSTFILE is a directory.
1256c321187Smrg
1266c321187SmrgEnvironment variables override the default commands:
12793493779Smrg  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
12893493779Smrg  RMPROG STRIPPROG
1296c321187Smrg"
1306c321187Smrg
1316c321187Smrgwhile test $# -ne 0; do
1326c321187Smrg  case $1 in
13393493779Smrg    -c) ;;
13493493779Smrg
13593493779Smrg    -C) copy_on_change=true;;
1366c321187Smrg
13793493779Smrg    -d) dir_arg=true;;
1386c321187Smrg
1396c321187Smrg    -g) chgrpcmd="$chgrpprog $2"
14093493779Smrg	shift;;
1416c321187Smrg
1426c321187Smrg    --help) echo "$usage"; exit $?;;
1436c321187Smrg
1446c321187Smrg    -m) mode=$2
1456c321187Smrg	case $mode in
1466c321187Smrg	  *' '* | *'	'* | *'
1476c321187Smrg'*	  | *'*'* | *'?'* | *'['*)
1486c321187Smrg	    echo "$0: invalid mode: $mode" >&2
1496c321187Smrg	    exit 1;;
1506c321187Smrg	esac
15193493779Smrg	shift;;
1526c321187Smrg
1536c321187Smrg    -o) chowncmd="$chownprog $2"
15493493779Smrg	shift;;
1556c321187Smrg
15693493779Smrg    -s) stripcmd=$stripprog;;
1576c321187Smrg
15893493779Smrg    -t) dst_arg=$2
15993493779Smrg	shift;;
1606c321187Smrg
16193493779Smrg    -T) no_target_directory=true;;
1626c321187Smrg
1636c321187Smrg    --version) echo "$0 $scriptversion"; exit $?;;
1646c321187Smrg
1656c321187Smrg    --)	shift
1666c321187Smrg	break;;
1676c321187Smrg
1686c321187Smrg    -*)	echo "$0: invalid option: $1" >&2
1696c321187Smrg	exit 1;;
1706c321187Smrg
1716c321187Smrg    *)  break;;
1726c321187Smrg  esac
17393493779Smrg  shift
1746c321187Smrgdone
1756c321187Smrg
17693493779Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
1776c321187Smrg  # When -d is used, all remaining arguments are directories to create.
1786c321187Smrg  # When -t is used, the destination is already specified.
1796c321187Smrg  # Otherwise, the last argument is the destination.  Remove it from $@.
1806c321187Smrg  for arg
1816c321187Smrg  do
18293493779Smrg    if test -n "$dst_arg"; then
1836c321187Smrg      # $@ is not empty: it contains at least $arg.
18493493779Smrg      set fnord "$@" "$dst_arg"
1856c321187Smrg      shift # fnord
1866c321187Smrg    fi
1876c321187Smrg    shift # arg
18893493779Smrg    dst_arg=$arg
1896c321187Smrg  done
1906c321187Smrgfi
1916c321187Smrg
1926c321187Smrgif test $# -eq 0; then
1936c321187Smrg  if test -z "$dir_arg"; then
1946c321187Smrg    echo "$0: no input file specified." >&2
1956c321187Smrg    exit 1
1966c321187Smrg  fi
1976c321187Smrg  # It's OK to call `install-sh -d' without argument.
1986c321187Smrg  # This can happen when creating conditional directories.
1996c321187Smrg  exit 0
2006c321187Smrgfi
2016c321187Smrg
2026c321187Smrgif test -z "$dir_arg"; then
2036c321187Smrg  trap '(exit $?); exit' 1 2 13 15
2046c321187Smrg
2056c321187Smrg  # Set umask so as not to create temps with too-generous modes.
2066c321187Smrg  # However, 'strip' requires both read and write access to temps.
2076c321187Smrg  case $mode in
2086c321187Smrg    # Optimize common cases.
2096c321187Smrg    *644) cp_umask=133;;
2106c321187Smrg    *755) cp_umask=22;;
2116c321187Smrg
2126c321187Smrg    *[0-7])
2136c321187Smrg      if test -z "$stripcmd"; then
2146c321187Smrg	u_plus_rw=
2156c321187Smrg      else
2166c321187Smrg	u_plus_rw='% 200'
2176c321187Smrg      fi
2186c321187Smrg      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
2196c321187Smrg    *)
2206c321187Smrg      if test -z "$stripcmd"; then
2216c321187Smrg	u_plus_rw=
2226c321187Smrg      else
2236c321187Smrg	u_plus_rw=,u+rw
2246c321187Smrg      fi
2256c321187Smrg      cp_umask=$mode$u_plus_rw;;
2266c321187Smrg  esac
2276c321187Smrgfi
2286c321187Smrg
2296c321187Smrgfor src
2306c321187Smrgdo
2316c321187Smrg  # Protect names starting with `-'.
2326c321187Smrg  case $src in
23393493779Smrg    -*) src=./$src;;
2346c321187Smrg  esac
2356c321187Smrg
2366c321187Smrg  if test -n "$dir_arg"; then
2376c321187Smrg    dst=$src
2386c321187Smrg    dstdir=$dst
2396c321187Smrg    test -d "$dstdir"
2406c321187Smrg    dstdir_status=$?
2416c321187Smrg  else
2426c321187Smrg
2436c321187Smrg    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
2446c321187Smrg    # might cause directories to be created, which would be especially bad
2456c321187Smrg    # if $src (and thus $dsttmp) contains '*'.
2466c321187Smrg    if test ! -f "$src" && test ! -d "$src"; then
2476c321187Smrg      echo "$0: $src does not exist." >&2
2486c321187Smrg      exit 1
2496c321187Smrg    fi
2506c321187Smrg
25193493779Smrg    if test -z "$dst_arg"; then
2526c321187Smrg      echo "$0: no destination specified." >&2
2536c321187Smrg      exit 1
2546c321187Smrg    fi
2556c321187Smrg
25693493779Smrg    dst=$dst_arg
2576c321187Smrg    # Protect names starting with `-'.
2586c321187Smrg    case $dst in
25993493779Smrg      -*) dst=./$dst;;
2606c321187Smrg    esac
2616c321187Smrg
2626c321187Smrg    # If destination is a directory, append the input filename; won't work
2636c321187Smrg    # if double slashes aren't ignored.
2646c321187Smrg    if test -d "$dst"; then
2656c321187Smrg      if test -n "$no_target_directory"; then
26693493779Smrg	echo "$0: $dst_arg: Is a directory" >&2
2676c321187Smrg	exit 1
2686c321187Smrg      fi
2696c321187Smrg      dstdir=$dst
2706c321187Smrg      dst=$dstdir/`basename "$src"`
2716c321187Smrg      dstdir_status=0
2726c321187Smrg    else
2736c321187Smrg      # Prefer dirname, but fall back on a substitute if dirname fails.
2746c321187Smrg      dstdir=`
2756c321187Smrg	(dirname "$dst") 2>/dev/null ||
2766c321187Smrg	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
2776c321187Smrg	     X"$dst" : 'X\(//\)[^/]' \| \
2786c321187Smrg	     X"$dst" : 'X\(//\)$' \| \
2796c321187Smrg	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
2806c321187Smrg	echo X"$dst" |
2816c321187Smrg	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
2826c321187Smrg		   s//\1/
2836c321187Smrg		   q
2846c321187Smrg		 }
2856c321187Smrg		 /^X\(\/\/\)[^/].*/{
2866c321187Smrg		   s//\1/
2876c321187Smrg		   q
2886c321187Smrg		 }
2896c321187Smrg		 /^X\(\/\/\)$/{
2906c321187Smrg		   s//\1/
2916c321187Smrg		   q
2926c321187Smrg		 }
2936c321187Smrg		 /^X\(\/\).*/{
2946c321187Smrg		   s//\1/
2956c321187Smrg		   q
2966c321187Smrg		 }
2976c321187Smrg		 s/.*/./; q'
2986c321187Smrg      `
2996c321187Smrg
3006c321187Smrg      test -d "$dstdir"
3016c321187Smrg      dstdir_status=$?
3026c321187Smrg    fi
3036c321187Smrg  fi
3046c321187Smrg
3056c321187Smrg  obsolete_mkdir_used=false
3066c321187Smrg
3076c321187Smrg  if test $dstdir_status != 0; then
3086c321187Smrg    case $posix_mkdir in
3096c321187Smrg      '')
3106c321187Smrg	# Create intermediate dirs using mode 755 as modified by the umask.
3116c321187Smrg	# This is like FreeBSD 'install' as of 1997-10-28.
3126c321187Smrg	umask=`umask`
3136c321187Smrg	case $stripcmd.$umask in
3146c321187Smrg	  # Optimize common cases.
3156c321187Smrg	  *[2367][2367]) mkdir_umask=$umask;;
3166c321187Smrg	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
3176c321187Smrg
3186c321187Smrg	  *[0-7])
3196c321187Smrg	    mkdir_umask=`expr $umask + 22 \
3206c321187Smrg	      - $umask % 100 % 40 + $umask % 20 \
3216c321187Smrg	      - $umask % 10 % 4 + $umask % 2
3226c321187Smrg	    `;;
3236c321187Smrg	  *) mkdir_umask=$umask,go-w;;
3246c321187Smrg	esac
3256c321187Smrg
3266c321187Smrg	# With -d, create the new directory with the user-specified mode.
3276c321187Smrg	# Otherwise, rely on $mkdir_umask.
3286c321187Smrg	if test -n "$dir_arg"; then
3296c321187Smrg	  mkdir_mode=-m$mode
3306c321187Smrg	else
3316c321187Smrg	  mkdir_mode=
3326c321187Smrg	fi
3336c321187Smrg
3346c321187Smrg	posix_mkdir=false
3356c321187Smrg	case $umask in
3366c321187Smrg	  *[123567][0-7][0-7])
3376c321187Smrg	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
3386c321187Smrg	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
3396c321187Smrg	    ;;
3406c321187Smrg	  *)
3416c321187Smrg	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
3426c321187Smrg	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
3436c321187Smrg
3446c321187Smrg	    if (umask $mkdir_umask &&
3456c321187Smrg		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
3466c321187Smrg	    then
3476c321187Smrg	      if test -z "$dir_arg" || {
3486c321187Smrg		   # Check for POSIX incompatibilities with -m.
3496c321187Smrg		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
3506c321187Smrg		   # other-writeable bit of parent directory when it shouldn't.
3516c321187Smrg		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
3526c321187Smrg		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
3536c321187Smrg		   case $ls_ld_tmpdir in
3546c321187Smrg		     d????-?r-*) different_mode=700;;
3556c321187Smrg		     d????-?--*) different_mode=755;;
3566c321187Smrg		     *) false;;
3576c321187Smrg		   esac &&
3586c321187Smrg		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
3596c321187Smrg		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
3606c321187Smrg		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
3616c321187Smrg		   }
3626c321187Smrg		 }
3636c321187Smrg	      then posix_mkdir=:
3646c321187Smrg	      fi
3656c321187Smrg	      rmdir "$tmpdir/d" "$tmpdir"
3666c321187Smrg	    else
3676c321187Smrg	      # Remove any dirs left behind by ancient mkdir implementations.
3686c321187Smrg	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
3696c321187Smrg	    fi
3706c321187Smrg	    trap '' 0;;
3716c321187Smrg	esac;;
3726c321187Smrg    esac
3736c321187Smrg
3746c321187Smrg    if
3756c321187Smrg      $posix_mkdir && (
3766c321187Smrg	umask $mkdir_umask &&
3776c321187Smrg	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
3786c321187Smrg      )
3796c321187Smrg    then :
3806c321187Smrg    else
3816c321187Smrg
3826c321187Smrg      # The umask is ridiculous, or mkdir does not conform to POSIX,
3836c321187Smrg      # or it failed possibly due to a race condition.  Create the
3846c321187Smrg      # directory the slow way, step by step, checking for races as we go.
3856c321187Smrg
3866c321187Smrg      case $dstdir in
38793493779Smrg	/*) prefix='/';;
38893493779Smrg	-*) prefix='./';;
38993493779Smrg	*)  prefix='';;
3906c321187Smrg      esac
3916c321187Smrg
39293493779Smrg      eval "$initialize_posix_glob"
3936c321187Smrg
3946c321187Smrg      oIFS=$IFS
3956c321187Smrg      IFS=/
39693493779Smrg      $posix_glob set -f
3976c321187Smrg      set fnord $dstdir
3986c321187Smrg      shift
39993493779Smrg      $posix_glob set +f
4006c321187Smrg      IFS=$oIFS
4016c321187Smrg
4026c321187Smrg      prefixes=
4036c321187Smrg
4046c321187Smrg      for d
4056c321187Smrg      do
4066c321187Smrg	test -z "$d" && continue
4076c321187Smrg
4086c321187Smrg	prefix=$prefix$d
4096c321187Smrg	if test -d "$prefix"; then
4106c321187Smrg	  prefixes=
4116c321187Smrg	else
4126c321187Smrg	  if $posix_mkdir; then
4136c321187Smrg	    (umask=$mkdir_umask &&
4146c321187Smrg	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
4156c321187Smrg	    # Don't fail if two instances are running concurrently.
4166c321187Smrg	    test -d "$prefix" || exit 1
4176c321187Smrg	  else
4186c321187Smrg	    case $prefix in
4196c321187Smrg	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
4206c321187Smrg	      *) qprefix=$prefix;;
4216c321187Smrg	    esac
4226c321187Smrg	    prefixes="$prefixes '$qprefix'"
4236c321187Smrg	  fi
4246c321187Smrg	fi
4256c321187Smrg	prefix=$prefix/
4266c321187Smrg      done
4276c321187Smrg
4286c321187Smrg      if test -n "$prefixes"; then
4296c321187Smrg	# Don't fail if two instances are running concurrently.
4306c321187Smrg	(umask $mkdir_umask &&
4316c321187Smrg	 eval "\$doit_exec \$mkdirprog $prefixes") ||
4326c321187Smrg	  test -d "$dstdir" || exit 1
4336c321187Smrg	obsolete_mkdir_used=true
4346c321187Smrg      fi
4356c321187Smrg    fi
4366c321187Smrg  fi
4376c321187Smrg
4386c321187Smrg  if test -n "$dir_arg"; then
4396c321187Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
4406c321187Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
4416c321187Smrg    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
4426c321187Smrg      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
4436c321187Smrg  else
4446c321187Smrg
4456c321187Smrg    # Make a couple of temp file names in the proper directory.
4466c321187Smrg    dsttmp=$dstdir/_inst.$$_
4476c321187Smrg    rmtmp=$dstdir/_rm.$$_
4486c321187Smrg
4496c321187Smrg    # Trap to clean up those temp files at exit.
4506c321187Smrg    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
4516c321187Smrg
4526c321187Smrg    # Copy the file name to the temp name.
4536c321187Smrg    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
4546c321187Smrg
4556c321187Smrg    # and set any options; do chmod last to preserve setuid bits.
4566c321187Smrg    #
4576c321187Smrg    # If any of these fail, we abort the whole thing.  If we want to
4586c321187Smrg    # ignore errors from any of these, just make sure not to ignore
4596c321187Smrg    # errors from the above "$doit $cpprog $src $dsttmp" command.
4606c321187Smrg    #
46193493779Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
46293493779Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
46393493779Smrg    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
46493493779Smrg    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
46593493779Smrg
46693493779Smrg    # If -C, don't bother to copy if it wouldn't change the file.
46793493779Smrg    if $copy_on_change &&
46893493779Smrg       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
46993493779Smrg       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
47093493779Smrg
47193493779Smrg       eval "$initialize_posix_glob" &&
47293493779Smrg       $posix_glob set -f &&
47393493779Smrg       set X $old && old=:$2:$4:$5:$6 &&
47493493779Smrg       set X $new && new=:$2:$4:$5:$6 &&
47593493779Smrg       $posix_glob set +f &&
47693493779Smrg
47793493779Smrg       test "$old" = "$new" &&
47893493779Smrg       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
47993493779Smrg    then
48093493779Smrg      rm -f "$dsttmp"
48193493779Smrg    else
48293493779Smrg      # Rename the file to the real destination.
48393493779Smrg      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
48493493779Smrg
48593493779Smrg      # The rename failed, perhaps because mv can't rename something else
48693493779Smrg      # to itself, or perhaps because mv is so ancient that it does not
48793493779Smrg      # support -f.
48893493779Smrg      {
48993493779Smrg	# Now remove or move aside any old file at destination location.
49093493779Smrg	# We try this two ways since rm can't unlink itself on some
49193493779Smrg	# systems and the destination file might be busy for other
49293493779Smrg	# reasons.  In this case, the final cleanup might fail but the new
49393493779Smrg	# file should still install successfully.
49493493779Smrg	{
49593493779Smrg	  test ! -f "$dst" ||
49693493779Smrg	  $doit $rmcmd -f "$dst" 2>/dev/null ||
49793493779Smrg	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
49893493779Smrg	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
49993493779Smrg	  } ||
50093493779Smrg	  { echo "$0: cannot unlink or rename $dst" >&2
50193493779Smrg	    (exit 1); exit 1
50293493779Smrg	  }
50393493779Smrg	} &&
50493493779Smrg
50593493779Smrg	# Now rename the file to the real destination.
50693493779Smrg	$doit $mvcmd "$dsttmp" "$dst"
50793493779Smrg      }
50893493779Smrg    fi || exit 1
5096c321187Smrg
5106c321187Smrg    trap '' 0
5116c321187Smrg  fi
5126c321187Smrgdone
5136c321187Smrg
5146c321187Smrg# Local variables:
5156c321187Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
5166c321187Smrg# time-stamp-start: "scriptversion="
5176c321187Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
51893493779Smrg# time-stamp-time-zone: "UTC"
51993493779Smrg# time-stamp-end: "; # UTC"
5206c321187Smrg# End:
521