1117610Sdes#!/bin/sh
2117610Sdes# install - install a program, script, or datafile
3141098Sdes
4255376Sdesscriptversion=2011-11-20.07; # UTC
5141098Sdes
6141098Sdes# This originates from X11R5 (mit/util/scripts/install.sh), which was
7141098Sdes# later released in X11R6 (xc/config/util/install.sh) with the
8141098Sdes# following copyright and license.
9117610Sdes#
10141098Sdes# Copyright (C) 1994 X Consortium
11117610Sdes#
12141098Sdes# Permission is hereby granted, free of charge, to any person obtaining a copy
13141098Sdes# of this software and associated documentation files (the "Software"), to
14141098Sdes# deal in the Software without restriction, including without limitation the
15141098Sdes# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16141098Sdes# sell copies of the Software, and to permit persons to whom the Software is
17141098Sdes# furnished to do so, subject to the following conditions:
18117610Sdes#
19141098Sdes# The above copyright notice and this permission notice shall be included in
20141098Sdes# all copies or substantial portions of the Software.
21141098Sdes#
22141098Sdes# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23141098Sdes# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24141098Sdes# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25141098Sdes# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26141098Sdes# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27141098Sdes# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28141098Sdes#
29141098Sdes# Except as contained in this notice, the name of the X Consortium shall not
30141098Sdes# be used in advertising or otherwise to promote the sale, use or other deal-
31141098Sdes# ings in this Software without prior written authorization from the X Consor-
32141098Sdes# tium.
33141098Sdes#
34141098Sdes#
35141098Sdes# FSF changes to this file are in the public domain.
36141098Sdes#
37117610Sdes# Calling this script install-sh is preferred over install.sh, to prevent
38255376Sdes# 'make' implicit rules from creating a file called install from it
39117610Sdes# when there is no Makefile.
40117610Sdes#
41117610Sdes# This script is compatible with the BSD install script, but was written
42228692Sdes# from scratch.
43117610Sdes
44228692Sdesnl='
45228692Sdes'
46228692SdesIFS=" ""	$nl"
47228692Sdes
48117610Sdes# set DOITPROG to echo to test this script
49117610Sdes
50117610Sdes# Don't use :- since 4.3BSD and earlier shells don't like it.
51228692Sdesdoit=${DOITPROG-}
52228692Sdesif test -z "$doit"; then
53228692Sdes  doit_exec=exec
54228692Sdeselse
55228692Sdes  doit_exec=$doit
56228692Sdesfi
57117610Sdes
58228692Sdes# Put in absolute file names if you don't have them in your path;
59228692Sdes# or use environment vars.
60117610Sdes
61228692Sdeschgrpprog=${CHGRPPROG-chgrp}
62228692Sdeschmodprog=${CHMODPROG-chmod}
63228692Sdeschownprog=${CHOWNPROG-chown}
64228692Sdescmpprog=${CMPPROG-cmp}
65228692Sdescpprog=${CPPROG-cp}
66228692Sdesmkdirprog=${MKDIRPROG-mkdir}
67228692Sdesmvprog=${MVPROG-mv}
68228692Sdesrmprog=${RMPROG-rm}
69228692Sdesstripprog=${STRIPPROG-strip}
70117610Sdes
71228692Sdesposix_glob='?'
72228692Sdesinitialize_posix_glob='
73228692Sdes  test "$posix_glob" != "?" || {
74228692Sdes    if (set -f) 2>/dev/null; then
75228692Sdes      posix_glob=
76228692Sdes    else
77228692Sdes      posix_glob=:
78228692Sdes    fi
79228692Sdes  }
80228692Sdes'
81228692Sdes
82228692Sdesposix_mkdir=
83228692Sdes
84228692Sdes# Desired mode of installed file.
85228692Sdesmode=0755
86228692Sdes
87228692Sdeschgrpcmd=
88228692Sdeschmodcmd=$chmodprog
89141098Sdeschowncmd=
90228692Sdesmvcmd=$mvprog
91228692Sdesrmcmd="$rmprog -f"
92141098Sdesstripcmd=
93228692Sdes
94141098Sdessrc=
95141098Sdesdst=
96141098Sdesdir_arg=
97228692Sdesdst_arg=
98228692Sdes
99228692Sdescopy_on_change=false
100174832Sdesno_target_directory=
101117610Sdes
102228692Sdesusage="\
103228692SdesUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104141098Sdes   or: $0 [OPTION]... SRCFILES... DIRECTORY
105174832Sdes   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106174832Sdes   or: $0 [OPTION]... -d DIRECTORIES...
107117610Sdes
108174832SdesIn the 1st form, copy SRCFILE to DSTFILE.
109174832SdesIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110174832SdesIn the 4th, create DIRECTORIES.
111117610Sdes
112141098SdesOptions:
113228692Sdes     --help     display this help and exit.
114228692Sdes     --version  display version info and exit.
115117610Sdes
116228692Sdes  -c            (ignored)
117228692Sdes  -C            install only if different (preserve the last data modification time)
118228692Sdes  -d            create directories instead of installing files.
119228692Sdes  -g GROUP      $chgrpprog installed files to GROUP.
120228692Sdes  -m MODE       $chmodprog installed files to MODE.
121228692Sdes  -o USER       $chownprog installed files to USER.
122228692Sdes  -s            $stripprog installed files.
123228692Sdes  -t DIRECTORY  install into DIRECTORY.
124228692Sdes  -T            report an error if DSTFILE is a directory.
125228692Sdes
126141098SdesEnvironment variables override the default commands:
127228692Sdes  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
128228692Sdes  RMPROG STRIPPROG
129141098Sdes"
130117610Sdes
131228692Sdeswhile test $# -ne 0; do
132141098Sdes  case $1 in
133228692Sdes    -c) ;;
134117610Sdes
135228692Sdes    -C) copy_on_change=true;;
136117610Sdes
137228692Sdes    -d) dir_arg=true;;
138228692Sdes
139141098Sdes    -g) chgrpcmd="$chgrpprog $2"
140228692Sdes	shift;;
141117610Sdes
142174832Sdes    --help) echo "$usage"; exit $?;;
143117610Sdes
144228692Sdes    -m) mode=$2
145228692Sdes	case $mode in
146228692Sdes	  *' '* | *'	'* | *'
147228692Sdes'*	  | *'*'* | *'?'* | *'['*)
148228692Sdes	    echo "$0: invalid mode: $mode" >&2
149228692Sdes	    exit 1;;
150228692Sdes	esac
151228692Sdes	shift;;
152117610Sdes
153141098Sdes    -o) chowncmd="$chownprog $2"
154228692Sdes	shift;;
155117610Sdes
156228692Sdes    -s) stripcmd=$stripprog;;
157117610Sdes
158228692Sdes    -t) dst_arg=$2
159255376Sdes	# Protect names problematic for 'test' and other utilities.
160255376Sdes	case $dst_arg in
161255376Sdes	  -* | [=\(\)!]) dst_arg=./$dst_arg;;
162255376Sdes	esac
163228692Sdes	shift;;
164117610Sdes
165228692Sdes    -T) no_target_directory=true;;
166117610Sdes
167174832Sdes    --version) echo "$0 $scriptversion"; exit $?;;
168174832Sdes
169228692Sdes    --)	shift
170141098Sdes	break;;
171228692Sdes
172228692Sdes    -*)	echo "$0: invalid option: $1" >&2
173228692Sdes	exit 1;;
174228692Sdes
175228692Sdes    *)  break;;
176141098Sdes  esac
177228692Sdes  shift
178141098Sdesdone
179141098Sdes
180228692Sdesif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
181228692Sdes  # When -d is used, all remaining arguments are directories to create.
182228692Sdes  # When -t is used, the destination is already specified.
183228692Sdes  # Otherwise, the last argument is the destination.  Remove it from $@.
184228692Sdes  for arg
185228692Sdes  do
186228692Sdes    if test -n "$dst_arg"; then
187228692Sdes      # $@ is not empty: it contains at least $arg.
188228692Sdes      set fnord "$@" "$dst_arg"
189228692Sdes      shift # fnord
190228692Sdes    fi
191228692Sdes    shift # arg
192228692Sdes    dst_arg=$arg
193255376Sdes    # Protect names problematic for 'test' and other utilities.
194255376Sdes    case $dst_arg in
195255376Sdes      -* | [=\(\)!]) dst_arg=./$dst_arg;;
196255376Sdes    esac
197228692Sdes  done
198228692Sdesfi
199228692Sdes
200228692Sdesif test $# -eq 0; then
201141098Sdes  if test -z "$dir_arg"; then
202141098Sdes    echo "$0: no input file specified." >&2
203141098Sdes    exit 1
204141098Sdes  fi
205255376Sdes  # It's OK to call 'install-sh -d' without argument.
206141098Sdes  # This can happen when creating conditional directories.
207141098Sdes  exit 0
208117610Sdesfi
209117610Sdes
210228692Sdesif test -z "$dir_arg"; then
211255376Sdes  do_exit='(exit $ret); exit $ret'
212255376Sdes  trap "ret=129; $do_exit" 1
213255376Sdes  trap "ret=130; $do_exit" 2
214255376Sdes  trap "ret=141; $do_exit" 13
215255376Sdes  trap "ret=143; $do_exit" 15
216228692Sdes
217228692Sdes  # Set umask so as not to create temps with too-generous modes.
218228692Sdes  # However, 'strip' requires both read and write access to temps.
219228692Sdes  case $mode in
220228692Sdes    # Optimize common cases.
221228692Sdes    *644) cp_umask=133;;
222228692Sdes    *755) cp_umask=22;;
223228692Sdes
224228692Sdes    *[0-7])
225228692Sdes      if test -z "$stripcmd"; then
226228692Sdes	u_plus_rw=
227228692Sdes      else
228228692Sdes	u_plus_rw='% 200'
229228692Sdes      fi
230228692Sdes      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
231228692Sdes    *)
232228692Sdes      if test -z "$stripcmd"; then
233228692Sdes	u_plus_rw=
234228692Sdes      else
235228692Sdes	u_plus_rw=,u+rw
236228692Sdes      fi
237228692Sdes      cp_umask=$mode$u_plus_rw;;
238228692Sdes  esac
239228692Sdesfi
240228692Sdes
241141098Sdesfor src
242141098Sdesdo
243255376Sdes  # Protect names problematic for 'test' and other utilities.
244141098Sdes  case $src in
245255376Sdes    -* | [=\(\)!]) src=./$src;;
246141098Sdes  esac
247117610Sdes
248141098Sdes  if test -n "$dir_arg"; then
249141098Sdes    dst=$src
250228692Sdes    dstdir=$dst
251228692Sdes    test -d "$dstdir"
252228692Sdes    dstdir_status=$?
253228692Sdes  else
254117610Sdes
255174832Sdes    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
256141098Sdes    # might cause directories to be created, which would be especially bad
257141098Sdes    # if $src (and thus $dsttmp) contains '*'.
258141098Sdes    if test ! -f "$src" && test ! -d "$src"; then
259141098Sdes      echo "$0: $src does not exist." >&2
260141098Sdes      exit 1
261141098Sdes    fi
262117610Sdes
263228692Sdes    if test -z "$dst_arg"; then
264141098Sdes      echo "$0: no destination specified." >&2
265141098Sdes      exit 1
266141098Sdes    fi
267228692Sdes    dst=$dst_arg
268117610Sdes
269141098Sdes    # If destination is a directory, append the input filename; won't work
270141098Sdes    # if double slashes aren't ignored.
271141098Sdes    if test -d "$dst"; then
272174832Sdes      if test -n "$no_target_directory"; then
273228692Sdes	echo "$0: $dst_arg: Is a directory" >&2
274174832Sdes	exit 1
275174832Sdes      fi
276228692Sdes      dstdir=$dst
277228692Sdes      dst=$dstdir/`basename "$src"`
278228692Sdes      dstdir_status=0
279228692Sdes    else
280228692Sdes      # Prefer dirname, but fall back on a substitute if dirname fails.
281228692Sdes      dstdir=`
282228692Sdes	(dirname "$dst") 2>/dev/null ||
283228692Sdes	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
284228692Sdes	     X"$dst" : 'X\(//\)[^/]' \| \
285228692Sdes	     X"$dst" : 'X\(//\)$' \| \
286228692Sdes	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
287228692Sdes	echo X"$dst" |
288228692Sdes	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
289228692Sdes		   s//\1/
290228692Sdes		   q
291228692Sdes		 }
292228692Sdes		 /^X\(\/\/\)[^/].*/{
293228692Sdes		   s//\1/
294228692Sdes		   q
295228692Sdes		 }
296228692Sdes		 /^X\(\/\/\)$/{
297228692Sdes		   s//\1/
298228692Sdes		   q
299228692Sdes		 }
300228692Sdes		 /^X\(\/\).*/{
301228692Sdes		   s//\1/
302228692Sdes		   q
303228692Sdes		 }
304228692Sdes		 s/.*/./; q'
305228692Sdes      `
306228692Sdes
307228692Sdes      test -d "$dstdir"
308228692Sdes      dstdir_status=$?
309141098Sdes    fi
310141098Sdes  fi
311117610Sdes
312228692Sdes  obsolete_mkdir_used=false
313117610Sdes
314228692Sdes  if test $dstdir_status != 0; then
315228692Sdes    case $posix_mkdir in
316228692Sdes      '')
317228692Sdes	# Create intermediate dirs using mode 755 as modified by the umask.
318228692Sdes	# This is like FreeBSD 'install' as of 1997-10-28.
319228692Sdes	umask=`umask`
320228692Sdes	case $stripcmd.$umask in
321228692Sdes	  # Optimize common cases.
322228692Sdes	  *[2367][2367]) mkdir_umask=$umask;;
323228692Sdes	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
324117610Sdes
325228692Sdes	  *[0-7])
326228692Sdes	    mkdir_umask=`expr $umask + 22 \
327228692Sdes	      - $umask % 100 % 40 + $umask % 20 \
328228692Sdes	      - $umask % 10 % 4 + $umask % 2
329228692Sdes	    `;;
330228692Sdes	  *) mkdir_umask=$umask,go-w;;
331228692Sdes	esac
332117610Sdes
333228692Sdes	# With -d, create the new directory with the user-specified mode.
334228692Sdes	# Otherwise, rely on $mkdir_umask.
335228692Sdes	if test -n "$dir_arg"; then
336228692Sdes	  mkdir_mode=-m$mode
337228692Sdes	else
338228692Sdes	  mkdir_mode=
339228692Sdes	fi
340117610Sdes
341228692Sdes	posix_mkdir=false
342228692Sdes	case $umask in
343228692Sdes	  *[123567][0-7][0-7])
344228692Sdes	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
345228692Sdes	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
346228692Sdes	    ;;
347228692Sdes	  *)
348228692Sdes	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
349228692Sdes	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
350117610Sdes
351228692Sdes	    if (umask $mkdir_umask &&
352228692Sdes		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
353228692Sdes	    then
354228692Sdes	      if test -z "$dir_arg" || {
355228692Sdes		   # Check for POSIX incompatibilities with -m.
356228692Sdes		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
357255376Sdes		   # other-writable bit of parent directory when it shouldn't.
358228692Sdes		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
359228692Sdes		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
360228692Sdes		   case $ls_ld_tmpdir in
361228692Sdes		     d????-?r-*) different_mode=700;;
362228692Sdes		     d????-?--*) different_mode=755;;
363228692Sdes		     *) false;;
364228692Sdes		   esac &&
365228692Sdes		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
366228692Sdes		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
367228692Sdes		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
368228692Sdes		   }
369228692Sdes		 }
370228692Sdes	      then posix_mkdir=:
371228692Sdes	      fi
372228692Sdes	      rmdir "$tmpdir/d" "$tmpdir"
373228692Sdes	    else
374228692Sdes	      # Remove any dirs left behind by ancient mkdir implementations.
375228692Sdes	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
376228692Sdes	    fi
377228692Sdes	    trap '' 0;;
378228692Sdes	esac;;
379228692Sdes    esac
380228692Sdes
381228692Sdes    if
382228692Sdes      $posix_mkdir && (
383228692Sdes	umask $mkdir_umask &&
384228692Sdes	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
385228692Sdes      )
386228692Sdes    then :
387228692Sdes    else
388228692Sdes
389228692Sdes      # The umask is ridiculous, or mkdir does not conform to POSIX,
390228692Sdes      # or it failed possibly due to a race condition.  Create the
391228692Sdes      # directory the slow way, step by step, checking for races as we go.
392228692Sdes
393228692Sdes      case $dstdir in
394228692Sdes	/*) prefix='/';;
395255376Sdes	[-=\(\)!]*) prefix='./';;
396228692Sdes	*)  prefix='';;
397228692Sdes      esac
398228692Sdes
399228692Sdes      eval "$initialize_posix_glob"
400228692Sdes
401228692Sdes      oIFS=$IFS
402228692Sdes      IFS=/
403228692Sdes      $posix_glob set -f
404228692Sdes      set fnord $dstdir
405141098Sdes      shift
406228692Sdes      $posix_glob set +f
407228692Sdes      IFS=$oIFS
408228692Sdes
409228692Sdes      prefixes=
410228692Sdes
411228692Sdes      for d
412228692Sdes      do
413255376Sdes	test X"$d" = X && continue
414228692Sdes
415228692Sdes	prefix=$prefix$d
416228692Sdes	if test -d "$prefix"; then
417228692Sdes	  prefixes=
418228692Sdes	else
419228692Sdes	  if $posix_mkdir; then
420228692Sdes	    (umask=$mkdir_umask &&
421228692Sdes	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
422228692Sdes	    # Don't fail if two instances are running concurrently.
423228692Sdes	    test -d "$prefix" || exit 1
424228692Sdes	  else
425228692Sdes	    case $prefix in
426228692Sdes	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
427228692Sdes	      *) qprefix=$prefix;;
428228692Sdes	    esac
429228692Sdes	    prefixes="$prefixes '$qprefix'"
430228692Sdes	  fi
431228692Sdes	fi
432228692Sdes	prefix=$prefix/
433228692Sdes      done
434228692Sdes
435228692Sdes      if test -n "$prefixes"; then
436228692Sdes	# Don't fail if two instances are running concurrently.
437228692Sdes	(umask $mkdir_umask &&
438228692Sdes	 eval "\$doit_exec \$mkdirprog $prefixes") ||
439228692Sdes	  test -d "$dstdir" || exit 1
440228692Sdes	obsolete_mkdir_used=true
441141098Sdes      fi
442228692Sdes    fi
443141098Sdes  fi
444117610Sdes
445141098Sdes  if test -n "$dir_arg"; then
446228692Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
447228692Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
448228692Sdes    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
449228692Sdes      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
450141098Sdes  else
451117610Sdes
452141098Sdes    # Make a couple of temp file names in the proper directory.
453141098Sdes    dsttmp=$dstdir/_inst.$$_
454141098Sdes    rmtmp=$dstdir/_rm.$$_
455117610Sdes
456141098Sdes    # Trap to clean up those temp files at exit.
457174832Sdes    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
458117610Sdes
459174832Sdes    # Copy the file name to the temp name.
460228692Sdes    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
461117610Sdes
462141098Sdes    # and set any options; do chmod last to preserve setuid bits.
463141098Sdes    #
464141098Sdes    # If any of these fail, we abort the whole thing.  If we want to
465141098Sdes    # ignore errors from any of these, just make sure not to ignore
466174832Sdes    # errors from the above "$doit $cpprog $src $dsttmp" command.
467141098Sdes    #
468228692Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
469228692Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
470228692Sdes    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
471228692Sdes    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
472117610Sdes
473228692Sdes    # If -C, don't bother to copy if it wouldn't change the file.
474228692Sdes    if $copy_on_change &&
475228692Sdes       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
476228692Sdes       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
477117610Sdes
478228692Sdes       eval "$initialize_posix_glob" &&
479228692Sdes       $posix_glob set -f &&
480228692Sdes       set X $old && old=:$2:$4:$5:$6 &&
481228692Sdes       set X $new && new=:$2:$4:$5:$6 &&
482228692Sdes       $posix_glob set +f &&
483117610Sdes
484228692Sdes       test "$old" = "$new" &&
485228692Sdes       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
486228692Sdes    then
487228692Sdes      rm -f "$dsttmp"
488228692Sdes    else
489228692Sdes      # Rename the file to the real destination.
490228692Sdes      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
491228692Sdes
492228692Sdes      # The rename failed, perhaps because mv can't rename something else
493228692Sdes      # to itself, or perhaps because mv is so ancient that it does not
494228692Sdes      # support -f.
495228692Sdes      {
496228692Sdes	# Now remove or move aside any old file at destination location.
497228692Sdes	# We try this two ways since rm can't unlink itself on some
498228692Sdes	# systems and the destination file might be busy for other
499228692Sdes	# reasons.  In this case, the final cleanup might fail but the new
500228692Sdes	# file should still install successfully.
501228692Sdes	{
502228692Sdes	  test ! -f "$dst" ||
503228692Sdes	  $doit $rmcmd -f "$dst" 2>/dev/null ||
504228692Sdes	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
505228692Sdes	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
506228692Sdes	  } ||
507228692Sdes	  { echo "$0: cannot unlink or rename $dst" >&2
508228692Sdes	    (exit 1); exit 1
509228692Sdes	  }
510228692Sdes	} &&
511228692Sdes
512228692Sdes	# Now rename the file to the real destination.
513228692Sdes	$doit $mvcmd "$dsttmp" "$dst"
514228692Sdes      }
515228692Sdes    fi || exit 1
516228692Sdes
517228692Sdes    trap '' 0
518228692Sdes  fi
519141098Sdesdone
520117610Sdes
521141098Sdes# Local variables:
522141098Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
523141098Sdes# time-stamp-start: "scriptversion="
524141098Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
525228692Sdes# time-stamp-time-zone: "UTC"
526228692Sdes# time-stamp-end: "; # UTC"
527141098Sdes# End:
528