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