install-sh revision 7104f784
109885543Smrg#!/bin/sh
209885543Smrg# install - install a program, script, or datafile
309885543Smrg
47104f784Smrgscriptversion=2006-12-25.00
509885543Smrg
609885543Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was
709885543Smrg# later released in X11R6 (xc/config/util/install.sh) with the
809885543Smrg# following copyright and license.
909885543Smrg#
1009885543Smrg# Copyright (C) 1994 X Consortium
1109885543Smrg#
1209885543Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy
1309885543Smrg# of this software and associated documentation files (the "Software"), to
1409885543Smrg# deal in the Software without restriction, including without limitation the
1509885543Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1609885543Smrg# sell copies of the Software, and to permit persons to whom the Software is
1709885543Smrg# furnished to do so, subject to the following conditions:
1809885543Smrg#
1909885543Smrg# The above copyright notice and this permission notice shall be included in
2009885543Smrg# all copies or substantial portions of the Software.
2109885543Smrg#
2209885543Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2309885543Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2409885543Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
2509885543Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2609885543Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
2709885543Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2809885543Smrg#
2909885543Smrg# Except as contained in this notice, the name of the X Consortium shall not
3009885543Smrg# be used in advertising or otherwise to promote the sale, use or other deal-
3109885543Smrg# ings in this Software without prior written authorization from the X Consor-
3209885543Smrg# tium.
3309885543Smrg#
3409885543Smrg#
3509885543Smrg# FSF changes to this file are in the public domain.
3609885543Smrg#
3709885543Smrg# Calling this script install-sh is preferred over install.sh, to prevent
3809885543Smrg# `make' implicit rules from creating a file called install from it
3909885543Smrg# when there is no Makefile.
4009885543Smrg#
4109885543Smrg# This script is compatible with the BSD install script, but was written
427104f784Smrg# from scratch.
437104f784Smrg
447104f784Smrgnl='
457104f784Smrg'
467104f784SmrgIFS=" ""	$nl"
4709885543Smrg
4809885543Smrg# set DOITPROG to echo to test this script
4909885543Smrg
5009885543Smrg# Don't use :- since 4.3BSD and earlier shells don't like it.
517104f784Smrgdoit=${DOITPROG-}
527104f784Smrgif test -z "$doit"; then
537104f784Smrg  doit_exec=exec
547104f784Smrgelse
557104f784Smrg  doit_exec=$doit
567104f784Smrgfi
5709885543Smrg
587104f784Smrg# Put in absolute file names if you don't have them in your path;
597104f784Smrg# or use environment vars.
607104f784Smrg
617104f784Smrgchgrpprog=${CHGRPPROG-chgrp}
627104f784Smrgchmodprog=${CHMODPROG-chmod}
637104f784Smrgchownprog=${CHOWNPROG-chown}
647104f784Smrgcmpprog=${CMPPROG-cmp}
657104f784Smrgcpprog=${CPPROG-cp}
667104f784Smrgmkdirprog=${MKDIRPROG-mkdir}
677104f784Smrgmvprog=${MVPROG-mv}
687104f784Smrgrmprog=${RMPROG-rm}
697104f784Smrgstripprog=${STRIPPROG-strip}
707104f784Smrg
717104f784Smrgposix_glob='?'
727104f784Smrginitialize_posix_glob='
737104f784Smrg  test "$posix_glob" != "?" || {
747104f784Smrg    if (set -f) 2>/dev/null; then
757104f784Smrg      posix_glob=
767104f784Smrg    else
777104f784Smrg      posix_glob=:
787104f784Smrg    fi
797104f784Smrg  }
807104f784Smrg'
8109885543Smrg
827104f784Smrgposix_mkdir=
837104f784Smrg
847104f784Smrg# Desired mode of installed file.
857104f784Smrgmode=0755
8609885543Smrg
8709885543Smrgchgrpcmd=
887104f784Smrgchmodcmd=$chmodprog
897104f784Smrgchowncmd=
907104f784Smrgmvcmd=$mvprog
9109885543Smrgrmcmd="$rmprog -f"
927104f784Smrgstripcmd=
937104f784Smrg
9409885543Smrgsrc=
9509885543Smrgdst=
9609885543Smrgdir_arg=
977104f784Smrgdst_arg=
987104f784Smrg
997104f784Smrgcopy_on_change=false
10009885543Smrgno_target_directory=
10109885543Smrg
1027104f784Smrgusage="\
1037104f784SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
10409885543Smrg   or: $0 [OPTION]... SRCFILES... DIRECTORY
10509885543Smrg   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
10609885543Smrg   or: $0 [OPTION]... -d DIRECTORIES...
10709885543Smrg
10809885543SmrgIn the 1st form, copy SRCFILE to DSTFILE.
10909885543SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
11009885543SmrgIn the 4th, create DIRECTORIES.
11109885543Smrg
11209885543SmrgOptions:
1137104f784Smrg     --help     display this help and exit.
1147104f784Smrg     --version  display version info and exit.
1157104f784Smrg
1167104f784Smrg  -c            (ignored)
1177104f784Smrg  -C            install only if different (preserve the last data modification time)
1187104f784Smrg  -d            create directories instead of installing files.
1197104f784Smrg  -g GROUP      $chgrpprog installed files to GROUP.
1207104f784Smrg  -m MODE       $chmodprog installed files to MODE.
1217104f784Smrg  -o USER       $chownprog installed files to USER.
1227104f784Smrg  -s            $stripprog installed files.
1237104f784Smrg  -t DIRECTORY  install into DIRECTORY.
1247104f784Smrg  -T            report an error if DSTFILE is a directory.
12509885543Smrg
12609885543SmrgEnvironment variables override the default commands:
1277104f784Smrg  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
1287104f784Smrg  RMPROG STRIPPROG
12909885543Smrg"
13009885543Smrg
1317104f784Smrgwhile test $# -ne 0; do
13209885543Smrg  case $1 in
1337104f784Smrg    -c) ;;
1347104f784Smrg
1357104f784Smrg    -C) copy_on_change=true;;
13609885543Smrg
1377104f784Smrg    -d) dir_arg=true;;
13809885543Smrg
13909885543Smrg    -g) chgrpcmd="$chgrpprog $2"
1407104f784Smrg	shift;;
14109885543Smrg
14209885543Smrg    --help) echo "$usage"; exit $?;;
14309885543Smrg
1447104f784Smrg    -m) mode=$2
1457104f784Smrg	case $mode in
1467104f784Smrg	  *' '* | *'	'* | *'
1477104f784Smrg'*	  | *'*'* | *'?'* | *'['*)
1487104f784Smrg	    echo "$0: invalid mode: $mode" >&2
1497104f784Smrg	    exit 1;;
1507104f784Smrg	esac
1517104f784Smrg	shift;;
15209885543Smrg
15309885543Smrg    -o) chowncmd="$chownprog $2"
1547104f784Smrg	shift;;
15509885543Smrg
1567104f784Smrg    -s) stripcmd=$stripprog;;
15709885543Smrg
1587104f784Smrg    -t) dst_arg=$2
1597104f784Smrg	shift;;
16009885543Smrg
1617104f784Smrg    -T) no_target_directory=true;;
16209885543Smrg
16309885543Smrg    --version) echo "$0 $scriptversion"; exit $?;;
16409885543Smrg
1657104f784Smrg    --)	shift
16609885543Smrg	break;;
1677104f784Smrg
1687104f784Smrg    -*)	echo "$0: invalid option: $1" >&2
1697104f784Smrg	exit 1;;
1707104f784Smrg
1717104f784Smrg    *)  break;;
17209885543Smrg  esac
1737104f784Smrg  shift
17409885543Smrgdone
17509885543Smrg
1767104f784Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
1777104f784Smrg  # When -d is used, all remaining arguments are directories to create.
1787104f784Smrg  # When -t is used, the destination is already specified.
1797104f784Smrg  # Otherwise, the last argument is the destination.  Remove it from $@.
1807104f784Smrg  for arg
1817104f784Smrg  do
1827104f784Smrg    if test -n "$dst_arg"; then
1837104f784Smrg      # $@ is not empty: it contains at least $arg.
1847104f784Smrg      set fnord "$@" "$dst_arg"
1857104f784Smrg      shift # fnord
1867104f784Smrg    fi
1877104f784Smrg    shift # arg
1887104f784Smrg    dst_arg=$arg
1897104f784Smrg  done
1907104f784Smrgfi
1917104f784Smrg
1927104f784Smrgif test $# -eq 0; then
19309885543Smrg  if test -z "$dir_arg"; then
19409885543Smrg    echo "$0: no input file specified." >&2
19509885543Smrg    exit 1
19609885543Smrg  fi
19709885543Smrg  # It's OK to call `install-sh -d' without argument.
19809885543Smrg  # This can happen when creating conditional directories.
19909885543Smrg  exit 0
20009885543Smrgfi
20109885543Smrg
2027104f784Smrgif test -z "$dir_arg"; then
2037104f784Smrg  trap '(exit $?); exit' 1 2 13 15
2047104f784Smrg
2057104f784Smrg  # Set umask so as not to create temps with too-generous modes.
2067104f784Smrg  # However, 'strip' requires both read and write access to temps.
2077104f784Smrg  case $mode in
2087104f784Smrg    # Optimize common cases.
2097104f784Smrg    *644) cp_umask=133;;
2107104f784Smrg    *755) cp_umask=22;;
2117104f784Smrg
2127104f784Smrg    *[0-7])
2137104f784Smrg      if test -z "$stripcmd"; then
2147104f784Smrg	u_plus_rw=
2157104f784Smrg      else
2167104f784Smrg	u_plus_rw='% 200'
2177104f784Smrg      fi
2187104f784Smrg      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
2197104f784Smrg    *)
2207104f784Smrg      if test -z "$stripcmd"; then
2217104f784Smrg	u_plus_rw=
2227104f784Smrg      else
2237104f784Smrg	u_plus_rw=,u+rw
2247104f784Smrg      fi
2257104f784Smrg      cp_umask=$mode$u_plus_rw;;
2267104f784Smrg  esac
2277104f784Smrgfi
2287104f784Smrg
22909885543Smrgfor src
23009885543Smrgdo
23109885543Smrg  # Protect names starting with `-'.
23209885543Smrg  case $src in
2337104f784Smrg    -*) src=./$src;;
23409885543Smrg  esac
23509885543Smrg
23609885543Smrg  if test -n "$dir_arg"; then
23709885543Smrg    dst=$src
2387104f784Smrg    dstdir=$dst
2397104f784Smrg    test -d "$dstdir"
2407104f784Smrg    dstdir_status=$?
24109885543Smrg  else
2427104f784Smrg
24309885543Smrg    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
24409885543Smrg    # might cause directories to be created, which would be especially bad
24509885543Smrg    # if $src (and thus $dsttmp) contains '*'.
24609885543Smrg    if test ! -f "$src" && test ! -d "$src"; then
24709885543Smrg      echo "$0: $src does not exist." >&2
24809885543Smrg      exit 1
24909885543Smrg    fi
25009885543Smrg
2517104f784Smrg    if test -z "$dst_arg"; then
25209885543Smrg      echo "$0: no destination specified." >&2
25309885543Smrg      exit 1
25409885543Smrg    fi
25509885543Smrg
2567104f784Smrg    dst=$dst_arg
25709885543Smrg    # Protect names starting with `-'.
25809885543Smrg    case $dst in
2597104f784Smrg      -*) dst=./$dst;;
26009885543Smrg    esac
26109885543Smrg
26209885543Smrg    # If destination is a directory, append the input filename; won't work
26309885543Smrg    # if double slashes aren't ignored.
26409885543Smrg    if test -d "$dst"; then
26509885543Smrg      if test -n "$no_target_directory"; then
2667104f784Smrg	echo "$0: $dst_arg: Is a directory" >&2
26709885543Smrg	exit 1
26809885543Smrg      fi
2697104f784Smrg      dstdir=$dst
2707104f784Smrg      dst=$dstdir/`basename "$src"`
2717104f784Smrg      dstdir_status=0
2727104f784Smrg    else
2737104f784Smrg      # Prefer dirname, but fall back on a substitute if dirname fails.
2747104f784Smrg      dstdir=`
2757104f784Smrg	(dirname "$dst") 2>/dev/null ||
2767104f784Smrg	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
2777104f784Smrg	     X"$dst" : 'X\(//\)[^/]' \| \
2787104f784Smrg	     X"$dst" : 'X\(//\)$' \| \
2797104f784Smrg	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
2807104f784Smrg	echo X"$dst" |
2817104f784Smrg	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
2827104f784Smrg		   s//\1/
2837104f784Smrg		   q
2847104f784Smrg		 }
2857104f784Smrg		 /^X\(\/\/\)[^/].*/{
2867104f784Smrg		   s//\1/
2877104f784Smrg		   q
2887104f784Smrg		 }
2897104f784Smrg		 /^X\(\/\/\)$/{
2907104f784Smrg		   s//\1/
2917104f784Smrg		   q
2927104f784Smrg		 }
2937104f784Smrg		 /^X\(\/\).*/{
2947104f784Smrg		   s//\1/
2957104f784Smrg		   q
2967104f784Smrg		 }
2977104f784Smrg		 s/.*/./; q'
2987104f784Smrg      `
2997104f784Smrg
3007104f784Smrg      test -d "$dstdir"
3017104f784Smrg      dstdir_status=$?
30209885543Smrg    fi
30309885543Smrg  fi
30409885543Smrg
3057104f784Smrg  obsolete_mkdir_used=false
3067104f784Smrg
3077104f784Smrg  if test $dstdir_status != 0; then
3087104f784Smrg    case $posix_mkdir in
3097104f784Smrg      '')
3107104f784Smrg	# Create intermediate dirs using mode 755 as modified by the umask.
3117104f784Smrg	# This is like FreeBSD 'install' as of 1997-10-28.
3127104f784Smrg	umask=`umask`
3137104f784Smrg	case $stripcmd.$umask in
3147104f784Smrg	  # Optimize common cases.
3157104f784Smrg	  *[2367][2367]) mkdir_umask=$umask;;
3167104f784Smrg	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
3177104f784Smrg
3187104f784Smrg	  *[0-7])
3197104f784Smrg	    mkdir_umask=`expr $umask + 22 \
3207104f784Smrg	      - $umask % 100 % 40 + $umask % 20 \
3217104f784Smrg	      - $umask % 10 % 4 + $umask % 2
3227104f784Smrg	    `;;
3237104f784Smrg	  *) mkdir_umask=$umask,go-w;;
3247104f784Smrg	esac
3257104f784Smrg
3267104f784Smrg	# With -d, create the new directory with the user-specified mode.
3277104f784Smrg	# Otherwise, rely on $mkdir_umask.
3287104f784Smrg	if test -n "$dir_arg"; then
3297104f784Smrg	  mkdir_mode=-m$mode
3307104f784Smrg	else
3317104f784Smrg	  mkdir_mode=
3327104f784Smrg	fi
3337104f784Smrg
3347104f784Smrg	posix_mkdir=false
3357104f784Smrg	case $umask in
3367104f784Smrg	  *[123567][0-7][0-7])
3377104f784Smrg	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
3387104f784Smrg	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
3397104f784Smrg	    ;;
3407104f784Smrg	  *)
3417104f784Smrg	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
3427104f784Smrg	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
3437104f784Smrg
3447104f784Smrg	    if (umask $mkdir_umask &&
3457104f784Smrg		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
3467104f784Smrg	    then
3477104f784Smrg	      if test -z "$dir_arg" || {
3487104f784Smrg		   # Check for POSIX incompatibilities with -m.
3497104f784Smrg		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
3507104f784Smrg		   # other-writeable bit of parent directory when it shouldn't.
3517104f784Smrg		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
3527104f784Smrg		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
3537104f784Smrg		   case $ls_ld_tmpdir in
3547104f784Smrg		     d????-?r-*) different_mode=700;;
3557104f784Smrg		     d????-?--*) different_mode=755;;
3567104f784Smrg		     *) false;;
3577104f784Smrg		   esac &&
3587104f784Smrg		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
3597104f784Smrg		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
3607104f784Smrg		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
3617104f784Smrg		   }
3627104f784Smrg		 }
3637104f784Smrg	      then posix_mkdir=:
3647104f784Smrg	      fi
3657104f784Smrg	      rmdir "$tmpdir/d" "$tmpdir"
3667104f784Smrg	    else
3677104f784Smrg	      # Remove any dirs left behind by ancient mkdir implementations.
3687104f784Smrg	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
3697104f784Smrg	    fi
3707104f784Smrg	    trap '' 0;;
3717104f784Smrg	esac;;
3727104f784Smrg    esac
37309885543Smrg
3747104f784Smrg    if
3757104f784Smrg      $posix_mkdir && (
3767104f784Smrg	umask $mkdir_umask &&
3777104f784Smrg	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
3787104f784Smrg      )
3797104f784Smrg    then :
3807104f784Smrg    else
38109885543Smrg
3827104f784Smrg      # The umask is ridiculous, or mkdir does not conform to POSIX,
3837104f784Smrg      # or it failed possibly due to a race condition.  Create the
3847104f784Smrg      # directory the slow way, step by step, checking for races as we go.
38509885543Smrg
3867104f784Smrg      case $dstdir in
3877104f784Smrg	/*) prefix='/';;
3887104f784Smrg	-*) prefix='./';;
3897104f784Smrg	*)  prefix='';;
3907104f784Smrg      esac
39109885543Smrg
3927104f784Smrg      eval "$initialize_posix_glob"
39309885543Smrg
3947104f784Smrg      oIFS=$IFS
3957104f784Smrg      IFS=/
3967104f784Smrg      $posix_glob set -f
3977104f784Smrg      set fnord $dstdir
39809885543Smrg      shift
3997104f784Smrg      $posix_glob set +f
4007104f784Smrg      IFS=$oIFS
4017104f784Smrg
4027104f784Smrg      prefixes=
4037104f784Smrg
4047104f784Smrg      for d
4057104f784Smrg      do
4067104f784Smrg	test -z "$d" && continue
4077104f784Smrg
4087104f784Smrg	prefix=$prefix$d
4097104f784Smrg	if test -d "$prefix"; then
4107104f784Smrg	  prefixes=
4117104f784Smrg	else
4127104f784Smrg	  if $posix_mkdir; then
4137104f784Smrg	    (umask=$mkdir_umask &&
4147104f784Smrg	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
4157104f784Smrg	    # Don't fail if two instances are running concurrently.
4167104f784Smrg	    test -d "$prefix" || exit 1
4177104f784Smrg	  else
4187104f784Smrg	    case $prefix in
4197104f784Smrg	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
4207104f784Smrg	      *) qprefix=$prefix;;
4217104f784Smrg	    esac
4227104f784Smrg	    prefixes="$prefixes '$qprefix'"
4237104f784Smrg	  fi
4247104f784Smrg	fi
4257104f784Smrg	prefix=$prefix/
4267104f784Smrg      done
4277104f784Smrg
4287104f784Smrg      if test -n "$prefixes"; then
4297104f784Smrg	# Don't fail if two instances are running concurrently.
4307104f784Smrg	(umask $mkdir_umask &&
4317104f784Smrg	 eval "\$doit_exec \$mkdirprog $prefixes") ||
4327104f784Smrg	  test -d "$dstdir" || exit 1
4337104f784Smrg	obsolete_mkdir_used=true
43409885543Smrg      fi
4357104f784Smrg    fi
43609885543Smrg  fi
43709885543Smrg
43809885543Smrg  if test -n "$dir_arg"; then
4397104f784Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
4407104f784Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
4417104f784Smrg    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
4427104f784Smrg      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
44309885543Smrg  else
44409885543Smrg
44509885543Smrg    # Make a couple of temp file names in the proper directory.
44609885543Smrg    dsttmp=$dstdir/_inst.$$_
44709885543Smrg    rmtmp=$dstdir/_rm.$$_
44809885543Smrg
44909885543Smrg    # Trap to clean up those temp files at exit.
45009885543Smrg    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
45109885543Smrg
45209885543Smrg    # Copy the file name to the temp name.
4537104f784Smrg    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
45409885543Smrg
45509885543Smrg    # and set any options; do chmod last to preserve setuid bits.
45609885543Smrg    #
45709885543Smrg    # If any of these fail, we abort the whole thing.  If we want to
45809885543Smrg    # ignore errors from any of these, just make sure not to ignore
45909885543Smrg    # errors from the above "$doit $cpprog $src $dsttmp" command.
46009885543Smrg    #
4617104f784Smrg    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
4627104f784Smrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
4637104f784Smrg    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
4647104f784Smrg    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
4657104f784Smrg
4667104f784Smrg    # If -C, don't bother to copy if it wouldn't change the file.
4677104f784Smrg    if $copy_on_change &&
4687104f784Smrg       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
4697104f784Smrg       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
4707104f784Smrg
4717104f784Smrg       eval "$initialize_posix_glob" &&
4727104f784Smrg       $posix_glob set -f &&
4737104f784Smrg       set X $old && old=:$2:$4:$5:$6 &&
4747104f784Smrg       set X $new && new=:$2:$4:$5:$6 &&
4757104f784Smrg       $posix_glob set +f &&
4767104f784Smrg
4777104f784Smrg       test "$old" = "$new" &&
4787104f784Smrg       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
4797104f784Smrg    then
4807104f784Smrg      rm -f "$dsttmp"
4817104f784Smrg    else
4827104f784Smrg      # Rename the file to the real destination.
4837104f784Smrg      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
4847104f784Smrg
4857104f784Smrg      # The rename failed, perhaps because mv can't rename something else
4867104f784Smrg      # to itself, or perhaps because mv is so ancient that it does not
4877104f784Smrg      # support -f.
4887104f784Smrg      {
4897104f784Smrg	# Now remove or move aside any old file at destination location.
4907104f784Smrg	# We try this two ways since rm can't unlink itself on some
4917104f784Smrg	# systems and the destination file might be busy for other
4927104f784Smrg	# reasons.  In this case, the final cleanup might fail but the new
4937104f784Smrg	# file should still install successfully.
4947104f784Smrg	{
4957104f784Smrg	  test ! -f "$dst" ||
4967104f784Smrg	  $doit $rmcmd -f "$dst" 2>/dev/null ||
4977104f784Smrg	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
4987104f784Smrg	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
4997104f784Smrg	  } ||
5007104f784Smrg	  { echo "$0: cannot unlink or rename $dst" >&2
5017104f784Smrg	    (exit 1); exit 1
5027104f784Smrg	  }
5037104f784Smrg	} &&
5047104f784Smrg
5057104f784Smrg	# Now rename the file to the real destination.
5067104f784Smrg	$doit $mvcmd "$dsttmp" "$dst"
5077104f784Smrg      }
5087104f784Smrg    fi || exit 1
5097104f784Smrg
5107104f784Smrg    trap '' 0
5117104f784Smrg  fi
51209885543Smrgdone
51309885543Smrg
51409885543Smrg# Local variables:
51509885543Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
51609885543Smrg# time-stamp-start: "scriptversion="
51709885543Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
51809885543Smrg# time-stamp-end: "$"
51909885543Smrg# End:
520