install-sh revision 54569438
1692f60a7Smrg#!/bin/sh
2692f60a7Smrg# install - install a program, script, or datafile
3692f60a7Smrg
454569438Smrgscriptversion=2006-12-25.00
5692f60a7Smrg
6692f60a7Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was
7692f60a7Smrg# later released in X11R6 (xc/config/util/install.sh) with the
8692f60a7Smrg# following copyright and license.
9692f60a7Smrg#
10692f60a7Smrg# Copyright (C) 1994 X Consortium
11692f60a7Smrg#
12692f60a7Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy
13692f60a7Smrg# of this software and associated documentation files (the "Software"), to
14692f60a7Smrg# deal in the Software without restriction, including without limitation the
15692f60a7Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16692f60a7Smrg# sell copies of the Software, and to permit persons to whom the Software is
17692f60a7Smrg# furnished to do so, subject to the following conditions:
18692f60a7Smrg#
19692f60a7Smrg# The above copyright notice and this permission notice shall be included in
20692f60a7Smrg# all copies or substantial portions of the Software.
21692f60a7Smrg#
22692f60a7Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23692f60a7Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24692f60a7Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25692f60a7Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26692f60a7Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27692f60a7Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28692f60a7Smrg#
29692f60a7Smrg# Except as contained in this notice, the name of the X Consortium shall not
30692f60a7Smrg# be used in advertising or otherwise to promote the sale, use or other deal-
31692f60a7Smrg# ings in this Software without prior written authorization from the X Consor-
32692f60a7Smrg# tium.
33692f60a7Smrg#
34692f60a7Smrg#
35692f60a7Smrg# FSF changes to this file are in the public domain.
36692f60a7Smrg#
37692f60a7Smrg# Calling this script install-sh is preferred over install.sh, to prevent
38692f60a7Smrg# `make' implicit rules from creating a file called install from it
39692f60a7Smrg# when there is no Makefile.
40692f60a7Smrg#
41692f60a7Smrg# This script is compatible with the BSD install script, but was written
4254569438Smrg# from scratch.
4354569438Smrg
4454569438Smrgnl='
4554569438Smrg'
4654569438SmrgIFS=" ""	$nl"
47692f60a7Smrg
48692f60a7Smrg# set DOITPROG to echo to test this script
49692f60a7Smrg
50692f60a7Smrg# Don't use :- since 4.3BSD and earlier shells don't like it.
5154569438Smrgdoit=${DOITPROG-}
5254569438Smrgif test -z "$doit"; then
5354569438Smrg  doit_exec=exec
5454569438Smrgelse
5554569438Smrg  doit_exec=$doit
5654569438Smrgfi
57692f60a7Smrg
5854569438Smrg# Put in absolute file names if you don't have them in your path;
5954569438Smrg# or use environment vars.
6054569438Smrg
6154569438Smrgchgrpprog=${CHGRPPROG-chgrp}
6254569438Smrgchmodprog=${CHMODPROG-chmod}
6354569438Smrgchownprog=${CHOWNPROG-chown}
6454569438Smrgcmpprog=${CMPPROG-cmp}
6554569438Smrgcpprog=${CPPROG-cp}
6654569438Smrgmkdirprog=${MKDIRPROG-mkdir}
6754569438Smrgmvprog=${MVPROG-mv}
6854569438Smrgrmprog=${RMPROG-rm}
6954569438Smrgstripprog=${STRIPPROG-strip}
7054569438Smrg
7154569438Smrgposix_glob='?'
7254569438Smrginitialize_posix_glob='
7354569438Smrg  test "$posix_glob" != "?" || {
7454569438Smrg    if (set -f) 2>/dev/null; then
7554569438Smrg      posix_glob=
7654569438Smrg    else
7754569438Smrg      posix_glob=:
7854569438Smrg    fi
7954569438Smrg  }
8054569438Smrg'
81692f60a7Smrg
8254569438Smrgposix_mkdir=
8354569438Smrg
8454569438Smrg# Desired mode of installed file.
8554569438Smrgmode=0755
86692f60a7Smrg
87692f60a7Smrgchgrpcmd=
8854569438Smrgchmodcmd=$chmodprog
8954569438Smrgchowncmd=
9054569438Smrgmvcmd=$mvprog
91692f60a7Smrgrmcmd="$rmprog -f"
9254569438Smrgstripcmd=
9354569438Smrg
94692f60a7Smrgsrc=
95692f60a7Smrgdst=
96692f60a7Smrgdir_arg=
9754569438Smrgdst_arg=
9854569438Smrg
9954569438Smrgcopy_on_change=false
100692f60a7Smrgno_target_directory=
101692f60a7Smrg
10254569438Smrgusage="\
10354569438SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104692f60a7Smrg   or: $0 [OPTION]... SRCFILES... DIRECTORY
105692f60a7Smrg   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106692f60a7Smrg   or: $0 [OPTION]... -d DIRECTORIES...
107692f60a7Smrg
108692f60a7SmrgIn the 1st form, copy SRCFILE to DSTFILE.
109692f60a7SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110692f60a7SmrgIn the 4th, create DIRECTORIES.
111692f60a7Smrg
112692f60a7SmrgOptions:
11354569438Smrg     --help     display this help and exit.
11454569438Smrg     --version  display version info and exit.
11554569438Smrg
11654569438Smrg  -c            (ignored)
11754569438Smrg  -C            install only if different (preserve the last data modification time)
11854569438Smrg  -d            create directories instead of installing files.
11954569438Smrg  -g GROUP      $chgrpprog installed files to GROUP.
12054569438Smrg  -m MODE       $chmodprog installed files to MODE.
12154569438Smrg  -o USER       $chownprog installed files to USER.
12254569438Smrg  -s            $stripprog installed files.
12354569438Smrg  -t DIRECTORY  install into DIRECTORY.
12454569438Smrg  -T            report an error if DSTFILE is a directory.
125692f60a7Smrg
126692f60a7SmrgEnvironment variables override the default commands:
12754569438Smrg  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
12854569438Smrg  RMPROG STRIPPROG
129692f60a7Smrg"
130692f60a7Smrg
13154569438Smrgwhile test $# -ne 0; do
132692f60a7Smrg  case $1 in
13354569438Smrg    -c) ;;
13454569438Smrg
13554569438Smrg    -C) copy_on_change=true;;
136692f60a7Smrg
13754569438Smrg    -d) dir_arg=true;;
138692f60a7Smrg
139692f60a7Smrg    -g) chgrpcmd="$chgrpprog $2"
14054569438Smrg	shift;;
141692f60a7Smrg
142692f60a7Smrg    --help) echo "$usage"; exit $?;;
143692f60a7Smrg
14454569438Smrg    -m) mode=$2
14554569438Smrg	case $mode in
14654569438Smrg	  *' '* | *'	'* | *'
14754569438Smrg'*	  | *'*'* | *'?'* | *'['*)
14854569438Smrg	    echo "$0: invalid mode: $mode" >&2
14954569438Smrg	    exit 1;;
15054569438Smrg	esac
15154569438Smrg	shift;;
152692f60a7Smrg
153692f60a7Smrg    -o) chowncmd="$chownprog $2"
15454569438Smrg	shift;;
155692f60a7Smrg
15654569438Smrg    -s) stripcmd=$stripprog;;
157692f60a7Smrg
15854569438Smrg    -t) dst_arg=$2
15954569438Smrg	shift;;
160692f60a7Smrg
16154569438Smrg    -T) no_target_directory=true;;
162692f60a7Smrg
163692f60a7Smrg    --version) echo "$0 $scriptversion"; exit $?;;
164692f60a7Smrg
16554569438Smrg    --)	shift
166692f60a7Smrg	break;;
16754569438Smrg
16854569438Smrg    -*)	echo "$0: invalid option: $1" >&2
16954569438Smrg	exit 1;;
17054569438Smrg
17154569438Smrg    *)  break;;
172692f60a7Smrg  esac
17354569438Smrg  shift
174692f60a7Smrgdone
175692f60a7Smrg
17654569438Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
17754569438Smrg  # When -d is used, all remaining arguments are directories to create.
17854569438Smrg  # When -t is used, the destination is already specified.
17954569438Smrg  # Otherwise, the last argument is the destination.  Remove it from $@.
18054569438Smrg  for arg
18154569438Smrg  do
18254569438Smrg    if test -n "$dst_arg"; then
18354569438Smrg      # $@ is not empty: it contains at least $arg.
18454569438Smrg      set fnord "$@" "$dst_arg"
18554569438Smrg      shift # fnord
18654569438Smrg    fi
18754569438Smrg    shift # arg
18854569438Smrg    dst_arg=$arg
18954569438Smrg  done
19054569438Smrgfi
19154569438Smrg
19254569438Smrgif test $# -eq 0; then
193692f60a7Smrg  if test -z "$dir_arg"; then
194692f60a7Smrg    echo "$0: no input file specified." >&2
195692f60a7Smrg    exit 1
196692f60a7Smrg  fi
197692f60a7Smrg  # It's OK to call `install-sh -d' without argument.
198692f60a7Smrg  # This can happen when creating conditional directories.
199692f60a7Smrg  exit 0
200692f60a7Smrgfi
201692f60a7Smrg
20254569438Smrgif test -z "$dir_arg"; then
20354569438Smrg  trap '(exit $?); exit' 1 2 13 15
20454569438Smrg
20554569438Smrg  # Set umask so as not to create temps with too-generous modes.
20654569438Smrg  # However, 'strip' requires both read and write access to temps.
20754569438Smrg  case $mode in
20854569438Smrg    # Optimize common cases.
20954569438Smrg    *644) cp_umask=133;;
21054569438Smrg    *755) cp_umask=22;;
21154569438Smrg
21254569438Smrg    *[0-7])
21354569438Smrg      if test -z "$stripcmd"; then
21454569438Smrg	u_plus_rw=
21554569438Smrg      else
21654569438Smrg	u_plus_rw='% 200'
21754569438Smrg      fi
21854569438Smrg      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
21954569438Smrg    *)
22054569438Smrg      if test -z "$stripcmd"; then
22154569438Smrg	u_plus_rw=
22254569438Smrg      else
22354569438Smrg	u_plus_rw=,u+rw
22454569438Smrg      fi
22554569438Smrg      cp_umask=$mode$u_plus_rw;;
22654569438Smrg  esac
22754569438Smrgfi
22854569438Smrg
229692f60a7Smrgfor src
230692f60a7Smrgdo
231692f60a7Smrg  # Protect names starting with `-'.
232692f60a7Smrg  case $src in
23354569438Smrg    -*) src=./$src;;
234692f60a7Smrg  esac
235692f60a7Smrg
236692f60a7Smrg  if test -n "$dir_arg"; then
237692f60a7Smrg    dst=$src
23854569438Smrg    dstdir=$dst
23954569438Smrg    test -d "$dstdir"
24054569438Smrg    dstdir_status=$?
241692f60a7Smrg  else
24254569438Smrg
243692f60a7Smrg    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
244692f60a7Smrg    # might cause directories to be created, which would be especially bad
245692f60a7Smrg    # if $src (and thus $dsttmp) contains '*'.
246692f60a7Smrg    if test ! -f "$src" && test ! -d "$src"; then
247692f60a7Smrg      echo "$0: $src does not exist." >&2
248692f60a7Smrg      exit 1
249692f60a7Smrg    fi
250692f60a7Smrg
25154569438Smrg    if test -z "$dst_arg"; then
252692f60a7Smrg      echo "$0: no destination specified." >&2
253692f60a7Smrg      exit 1
254692f60a7Smrg    fi
255692f60a7Smrg
25654569438Smrg    dst=$dst_arg
257692f60a7Smrg    # Protect names starting with `-'.
258692f60a7Smrg    case $dst in
25954569438Smrg      -*) dst=./$dst;;
260692f60a7Smrg    esac
261692f60a7Smrg
262692f60a7Smrg    # If destination is a directory, append the input filename; won't work
263692f60a7Smrg    # if double slashes aren't ignored.
264692f60a7Smrg    if test -d "$dst"; then
265692f60a7Smrg      if test -n "$no_target_directory"; then
26654569438Smrg	echo "$0: $dst_arg: Is a directory" >&2
267692f60a7Smrg	exit 1
268692f60a7Smrg      fi
26954569438Smrg      dstdir=$dst
27054569438Smrg      dst=$dstdir/`basename "$src"`
27154569438Smrg      dstdir_status=0
27254569438Smrg    else
27354569438Smrg      # Prefer dirname, but fall back on a substitute if dirname fails.
27454569438Smrg      dstdir=`
27554569438Smrg	(dirname "$dst") 2>/dev/null ||
27654569438Smrg	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
27754569438Smrg	     X"$dst" : 'X\(//\)[^/]' \| \
27854569438Smrg	     X"$dst" : 'X\(//\)$' \| \
27954569438Smrg	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
28054569438Smrg	echo X"$dst" |
28154569438Smrg	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
28254569438Smrg		   s//\1/
28354569438Smrg		   q
28454569438Smrg		 }
28554569438Smrg		 /^X\(\/\/\)[^/].*/{
28654569438Smrg		   s//\1/
28754569438Smrg		   q
28854569438Smrg		 }
28954569438Smrg		 /^X\(\/\/\)$/{
29054569438Smrg		   s//\1/
29154569438Smrg		   q
29254569438Smrg		 }
29354569438Smrg		 /^X\(\/\).*/{
29454569438Smrg		   s//\1/
29554569438Smrg		   q
29654569438Smrg		 }
29754569438Smrg		 s/.*/./; q'
29854569438Smrg      `
29954569438Smrg
30054569438Smrg      test -d "$dstdir"
30154569438Smrg      dstdir_status=$?
302692f60a7Smrg    fi
303692f60a7Smrg  fi
304692f60a7Smrg
30554569438Smrg  obsolete_mkdir_used=false
30654569438Smrg
30754569438Smrg  if test $dstdir_status != 0; then
30854569438Smrg    case $posix_mkdir in
30954569438Smrg      '')
31054569438Smrg	# Create intermediate dirs using mode 755 as modified by the umask.
31154569438Smrg	# This is like FreeBSD 'install' as of 1997-10-28.
31254569438Smrg	umask=`umask`
31354569438Smrg	case $stripcmd.$umask in
31454569438Smrg	  # Optimize common cases.
31554569438Smrg	  *[2367][2367]) mkdir_umask=$umask;;
31654569438Smrg	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
31754569438Smrg
31854569438Smrg	  *[0-7])
31954569438Smrg	    mkdir_umask=`expr $umask + 22 \
32054569438Smrg	      - $umask % 100 % 40 + $umask % 20 \
32154569438Smrg	      - $umask % 10 % 4 + $umask % 2
32254569438Smrg	    `;;
32354569438Smrg	  *) mkdir_umask=$umask,go-w;;
32454569438Smrg	esac
32554569438Smrg
32654569438Smrg	# With -d, create the new directory with the user-specified mode.
32754569438Smrg	# Otherwise, rely on $mkdir_umask.
32854569438Smrg	if test -n "$dir_arg"; then
32954569438Smrg	  mkdir_mode=-m$mode
33054569438Smrg	else
33154569438Smrg	  mkdir_mode=
33254569438Smrg	fi
33354569438Smrg
33454569438Smrg	posix_mkdir=false
33554569438Smrg	case $umask in
33654569438Smrg	  *[123567][0-7][0-7])
33754569438Smrg	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
33854569438Smrg	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
33954569438Smrg	    ;;
34054569438Smrg	  *)
34154569438Smrg	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
34254569438Smrg	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
34354569438Smrg
34454569438Smrg	    if (umask $mkdir_umask &&
34554569438Smrg		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
34654569438Smrg	    then
34754569438Smrg	      if test -z "$dir_arg" || {
34854569438Smrg		   # Check for POSIX incompatibilities with -m.
34954569438Smrg		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
35054569438Smrg		   # other-writeable bit of parent directory when it shouldn't.
35154569438Smrg		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
35254569438Smrg		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
35354569438Smrg		   case $ls_ld_tmpdir in
35454569438Smrg		     d????-?r-*) different_mode=700;;
35554569438Smrg		     d????-?--*) different_mode=755;;
35654569438Smrg		     *) false;;
35754569438Smrg		   esac &&
35854569438Smrg		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
35954569438Smrg		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
36054569438Smrg		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
36154569438Smrg		   }
36254569438Smrg		 }
36354569438Smrg	      then posix_mkdir=:
36454569438Smrg	      fi
36554569438Smrg	      rmdir "$tmpdir/d" "$tmpdir"
36654569438Smrg	    else
36754569438Smrg	      # Remove any dirs left behind by ancient mkdir implementations.
36854569438Smrg	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
36954569438Smrg	    fi
37054569438Smrg	    trap '' 0;;
37154569438Smrg	esac;;
37254569438Smrg    esac
373692f60a7Smrg
37454569438Smrg    if
37554569438Smrg      $posix_mkdir && (
37654569438Smrg	umask $mkdir_umask &&
37754569438Smrg	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
37854569438Smrg      )
37954569438Smrg    then :
38054569438Smrg    else
381692f60a7Smrg
38254569438Smrg      # The umask is ridiculous, or mkdir does not conform to POSIX,
38354569438Smrg      # or it failed possibly due to a race condition.  Create the
38454569438Smrg      # directory the slow way, step by step, checking for races as we go.
385692f60a7Smrg
38654569438Smrg      case $dstdir in
38754569438Smrg	/*) prefix='/';;
38854569438Smrg	-*) prefix='./';;
38954569438Smrg	*)  prefix='';;
39054569438Smrg      esac
391692f60a7Smrg
39254569438Smrg      eval "$initialize_posix_glob"
393692f60a7Smrg
39454569438Smrg      oIFS=$IFS
39554569438Smrg      IFS=/
39654569438Smrg      $posix_glob set -f
39754569438Smrg      set fnord $dstdir
398692f60a7Smrg      shift
39954569438Smrg      $posix_glob set +f
40054569438Smrg      IFS=$oIFS
40154569438Smrg
40254569438Smrg      prefixes=
40354569438Smrg
40454569438Smrg      for d
40554569438Smrg      do
40654569438Smrg	test -z "$d" && continue
40754569438Smrg
40854569438Smrg	prefix=$prefix$d
40954569438Smrg	if test -d "$prefix"; then
41054569438Smrg	  prefixes=
41154569438Smrg	else
41254569438Smrg	  if $posix_mkdir; then
41354569438Smrg	    (umask=$mkdir_umask &&
41454569438Smrg	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
41554569438Smrg	    # Don't fail if two instances are running concurrently.
41654569438Smrg	    test -d "$prefix" || exit 1
41754569438Smrg	  else
41854569438Smrg	    case $prefix in
41954569438Smrg	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
42054569438Smrg	      *) qprefix=$prefix;;
42154569438Smrg	    esac
42254569438Smrg	    prefixes="$prefixes '$qprefix'"
42354569438Smrg	  fi
42454569438Smrg	fi
42554569438Smrg	prefix=$prefix/
42654569438Smrg      done
42754569438Smrg
42854569438Smrg      if test -n "$prefixes"; then
42954569438Smrg	# Don't fail if two instances are running concurrently.
43054569438Smrg	(umask $mkdir_umask &&
43154569438Smrg	 eval "\$doit_exec \$mkdirprog $prefixes") ||
43254569438Smrg	  test -d "$dstdir" || exit 1
43354569438Smrg	obsolete_mkdir_used=true
434692f60a7Smrg      fi
43554569438Smrg    fi
436692f60a7Smrg  fi
437692f60a7Smrg
438692f60a7Smrg  if test -n "$dir_arg"; then
43954569438Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
44054569438Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
44154569438Smrg    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
44254569438Smrg      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
443692f60a7Smrg  else
444692f60a7Smrg
445692f60a7Smrg    # Make a couple of temp file names in the proper directory.
446692f60a7Smrg    dsttmp=$dstdir/_inst.$$_
447692f60a7Smrg    rmtmp=$dstdir/_rm.$$_
448692f60a7Smrg
449692f60a7Smrg    # Trap to clean up those temp files at exit.
450692f60a7Smrg    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
451692f60a7Smrg
452692f60a7Smrg    # Copy the file name to the temp name.
45354569438Smrg    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
454692f60a7Smrg
455692f60a7Smrg    # and set any options; do chmod last to preserve setuid bits.
456692f60a7Smrg    #
457692f60a7Smrg    # If any of these fail, we abort the whole thing.  If we want to
458692f60a7Smrg    # ignore errors from any of these, just make sure not to ignore
459692f60a7Smrg    # errors from the above "$doit $cpprog $src $dsttmp" command.
460692f60a7Smrg    #
46154569438Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
46254569438Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
46354569438Smrg    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
46454569438Smrg    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
46554569438Smrg
46654569438Smrg    # If -C, don't bother to copy if it wouldn't change the file.
46754569438Smrg    if $copy_on_change &&
46854569438Smrg       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
46954569438Smrg       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
47054569438Smrg
47154569438Smrg       eval "$initialize_posix_glob" &&
47254569438Smrg       $posix_glob set -f &&
47354569438Smrg       set X $old && old=:$2:$4:$5:$6 &&
47454569438Smrg       set X $new && new=:$2:$4:$5:$6 &&
47554569438Smrg       $posix_glob set +f &&
47654569438Smrg
47754569438Smrg       test "$old" = "$new" &&
47854569438Smrg       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
47954569438Smrg    then
48054569438Smrg      rm -f "$dsttmp"
48154569438Smrg    else
48254569438Smrg      # Rename the file to the real destination.
48354569438Smrg      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
48454569438Smrg
48554569438Smrg      # The rename failed, perhaps because mv can't rename something else
48654569438Smrg      # to itself, or perhaps because mv is so ancient that it does not
48754569438Smrg      # support -f.
48854569438Smrg      {
48954569438Smrg	# Now remove or move aside any old file at destination location.
49054569438Smrg	# We try this two ways since rm can't unlink itself on some
49154569438Smrg	# systems and the destination file might be busy for other
49254569438Smrg	# reasons.  In this case, the final cleanup might fail but the new
49354569438Smrg	# file should still install successfully.
49454569438Smrg	{
49554569438Smrg	  test ! -f "$dst" ||
49654569438Smrg	  $doit $rmcmd -f "$dst" 2>/dev/null ||
49754569438Smrg	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
49854569438Smrg	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
49954569438Smrg	  } ||
50054569438Smrg	  { echo "$0: cannot unlink or rename $dst" >&2
50154569438Smrg	    (exit 1); exit 1
50254569438Smrg	  }
50354569438Smrg	} &&
50454569438Smrg
50554569438Smrg	# Now rename the file to the real destination.
50654569438Smrg	$doit $mvcmd "$dsttmp" "$dst"
50754569438Smrg      }
50854569438Smrg    fi || exit 1
50954569438Smrg
51054569438Smrg    trap '' 0
51154569438Smrg  fi
512692f60a7Smrgdone
513692f60a7Smrg
514692f60a7Smrg# Local variables:
515692f60a7Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
516692f60a7Smrg# time-stamp-start: "scriptversion="
517692f60a7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
518692f60a7Smrg# time-stamp-end: "$"
519692f60a7Smrg# End:
520