1238106Sdes#!/bin/sh
2238106Sdes# install - install a program, script, or datafile
3238106Sdes
4249141Sdesscriptversion=2011-11-20.07; # UTC
5238106Sdes
6238106Sdes# This originates from X11R5 (mit/util/scripts/install.sh), which was
7238106Sdes# later released in X11R6 (xc/config/util/install.sh) with the
8238106Sdes# following copyright and license.
9238106Sdes#
10238106Sdes# Copyright (C) 1994 X Consortium
11238106Sdes#
12238106Sdes# Permission is hereby granted, free of charge, to any person obtaining a copy
13238106Sdes# of this software and associated documentation files (the "Software"), to
14238106Sdes# deal in the Software without restriction, including without limitation the
15238106Sdes# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16238106Sdes# sell copies of the Software, and to permit persons to whom the Software is
17238106Sdes# furnished to do so, subject to the following conditions:
18238106Sdes#
19238106Sdes# The above copyright notice and this permission notice shall be included in
20238106Sdes# all copies or substantial portions of the Software.
21238106Sdes#
22238106Sdes# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23238106Sdes# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24238106Sdes# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25238106Sdes# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26238106Sdes# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27238106Sdes# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28238106Sdes#
29238106Sdes# Except as contained in this notice, the name of the X Consortium shall not
30238106Sdes# be used in advertising or otherwise to promote the sale, use or other deal-
31238106Sdes# ings in this Software without prior written authorization from the X Consor-
32238106Sdes# tium.
33238106Sdes#
34238106Sdes#
35238106Sdes# FSF changes to this file are in the public domain.
36238106Sdes#
37238106Sdes# Calling this script install-sh is preferred over install.sh, to prevent
38249141Sdes# 'make' implicit rules from creating a file called install from it
39238106Sdes# when there is no Makefile.
40238106Sdes#
41238106Sdes# This script is compatible with the BSD install script, but was written
42238106Sdes# from scratch.
43238106Sdes
44238106Sdesnl='
45238106Sdes'
46238106SdesIFS=" ""	$nl"
47238106Sdes
48238106Sdes# set DOITPROG to echo to test this script
49238106Sdes
50238106Sdes# Don't use :- since 4.3BSD and earlier shells don't like it.
51238106Sdesdoit=${DOITPROG-}
52238106Sdesif test -z "$doit"; then
53238106Sdes  doit_exec=exec
54238106Sdeselse
55238106Sdes  doit_exec=$doit
56238106Sdesfi
57238106Sdes
58238106Sdes# Put in absolute file names if you don't have them in your path;
59238106Sdes# or use environment vars.
60238106Sdes
61238106Sdeschgrpprog=${CHGRPPROG-chgrp}
62238106Sdeschmodprog=${CHMODPROG-chmod}
63238106Sdeschownprog=${CHOWNPROG-chown}
64238106Sdescmpprog=${CMPPROG-cmp}
65238106Sdescpprog=${CPPROG-cp}
66238106Sdesmkdirprog=${MKDIRPROG-mkdir}
67238106Sdesmvprog=${MVPROG-mv}
68238106Sdesrmprog=${RMPROG-rm}
69238106Sdesstripprog=${STRIPPROG-strip}
70238106Sdes
71238106Sdesposix_glob='?'
72238106Sdesinitialize_posix_glob='
73238106Sdes  test "$posix_glob" != "?" || {
74238106Sdes    if (set -f) 2>/dev/null; then
75238106Sdes      posix_glob=
76238106Sdes    else
77238106Sdes      posix_glob=:
78238106Sdes    fi
79238106Sdes  }
80238106Sdes'
81238106Sdes
82238106Sdesposix_mkdir=
83238106Sdes
84238106Sdes# Desired mode of installed file.
85238106Sdesmode=0755
86238106Sdes
87238106Sdeschgrpcmd=
88238106Sdeschmodcmd=$chmodprog
89238106Sdeschowncmd=
90238106Sdesmvcmd=$mvprog
91238106Sdesrmcmd="$rmprog -f"
92238106Sdesstripcmd=
93238106Sdes
94238106Sdessrc=
95238106Sdesdst=
96238106Sdesdir_arg=
97238106Sdesdst_arg=
98238106Sdes
99238106Sdescopy_on_change=false
100238106Sdesno_target_directory=
101238106Sdes
102238106Sdesusage="\
103238106SdesUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104238106Sdes   or: $0 [OPTION]... SRCFILES... DIRECTORY
105238106Sdes   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106238106Sdes   or: $0 [OPTION]... -d DIRECTORIES...
107238106Sdes
108238106SdesIn the 1st form, copy SRCFILE to DSTFILE.
109238106SdesIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110238106SdesIn the 4th, create DIRECTORIES.
111238106Sdes
112238106SdesOptions:
113238106Sdes     --help     display this help and exit.
114238106Sdes     --version  display version info and exit.
115238106Sdes
116238106Sdes  -c            (ignored)
117238106Sdes  -C            install only if different (preserve the last data modification time)
118238106Sdes  -d            create directories instead of installing files.
119238106Sdes  -g GROUP      $chgrpprog installed files to GROUP.
120238106Sdes  -m MODE       $chmodprog installed files to MODE.
121238106Sdes  -o USER       $chownprog installed files to USER.
122238106Sdes  -s            $stripprog installed files.
123238106Sdes  -t DIRECTORY  install into DIRECTORY.
124238106Sdes  -T            report an error if DSTFILE is a directory.
125238106Sdes
126238106SdesEnvironment variables override the default commands:
127238106Sdes  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
128238106Sdes  RMPROG STRIPPROG
129238106Sdes"
130238106Sdes
131238106Sdeswhile test $# -ne 0; do
132238106Sdes  case $1 in
133238106Sdes    -c) ;;
134238106Sdes
135238106Sdes    -C) copy_on_change=true;;
136238106Sdes
137238106Sdes    -d) dir_arg=true;;
138238106Sdes
139238106Sdes    -g) chgrpcmd="$chgrpprog $2"
140238106Sdes	shift;;
141238106Sdes
142238106Sdes    --help) echo "$usage"; exit $?;;
143238106Sdes
144238106Sdes    -m) mode=$2
145238106Sdes	case $mode in
146238106Sdes	  *' '* | *'	'* | *'
147238106Sdes'*	  | *'*'* | *'?'* | *'['*)
148238106Sdes	    echo "$0: invalid mode: $mode" >&2
149238106Sdes	    exit 1;;
150238106Sdes	esac
151238106Sdes	shift;;
152238106Sdes
153238106Sdes    -o) chowncmd="$chownprog $2"
154238106Sdes	shift;;
155238106Sdes
156238106Sdes    -s) stripcmd=$stripprog;;
157238106Sdes
158238106Sdes    -t) dst_arg=$2
159249141Sdes	# Protect names problematic for 'test' and other utilities.
160249141Sdes	case $dst_arg in
161249141Sdes	  -* | [=\(\)!]) dst_arg=./$dst_arg;;
162249141Sdes	esac
163238106Sdes	shift;;
164238106Sdes
165238106Sdes    -T) no_target_directory=true;;
166238106Sdes
167238106Sdes    --version) echo "$0 $scriptversion"; exit $?;;
168238106Sdes
169238106Sdes    --)	shift
170238106Sdes	break;;
171238106Sdes
172238106Sdes    -*)	echo "$0: invalid option: $1" >&2
173238106Sdes	exit 1;;
174238106Sdes
175238106Sdes    *)  break;;
176238106Sdes  esac
177238106Sdes  shift
178238106Sdesdone
179238106Sdes
180238106Sdesif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
181238106Sdes  # When -d is used, all remaining arguments are directories to create.
182238106Sdes  # When -t is used, the destination is already specified.
183238106Sdes  # Otherwise, the last argument is the destination.  Remove it from $@.
184238106Sdes  for arg
185238106Sdes  do
186238106Sdes    if test -n "$dst_arg"; then
187238106Sdes      # $@ is not empty: it contains at least $arg.
188238106Sdes      set fnord "$@" "$dst_arg"
189238106Sdes      shift # fnord
190238106Sdes    fi
191238106Sdes    shift # arg
192238106Sdes    dst_arg=$arg
193249141Sdes    # Protect names problematic for 'test' and other utilities.
194249141Sdes    case $dst_arg in
195249141Sdes      -* | [=\(\)!]) dst_arg=./$dst_arg;;
196249141Sdes    esac
197238106Sdes  done
198238106Sdesfi
199238106Sdes
200238106Sdesif test $# -eq 0; then
201238106Sdes  if test -z "$dir_arg"; then
202238106Sdes    echo "$0: no input file specified." >&2
203238106Sdes    exit 1
204238106Sdes  fi
205249141Sdes  # It's OK to call 'install-sh -d' without argument.
206238106Sdes  # This can happen when creating conditional directories.
207238106Sdes  exit 0
208238106Sdesfi
209238106Sdes
210238106Sdesif test -z "$dir_arg"; then
211249141Sdes  do_exit='(exit $ret); exit $ret'
212249141Sdes  trap "ret=129; $do_exit" 1
213249141Sdes  trap "ret=130; $do_exit" 2
214249141Sdes  trap "ret=141; $do_exit" 13
215249141Sdes  trap "ret=143; $do_exit" 15
216238106Sdes
217238106Sdes  # Set umask so as not to create temps with too-generous modes.
218238106Sdes  # However, 'strip' requires both read and write access to temps.
219238106Sdes  case $mode in
220238106Sdes    # Optimize common cases.
221238106Sdes    *644) cp_umask=133;;
222238106Sdes    *755) cp_umask=22;;
223238106Sdes
224238106Sdes    *[0-7])
225238106Sdes      if test -z "$stripcmd"; then
226238106Sdes	u_plus_rw=
227238106Sdes      else
228238106Sdes	u_plus_rw='% 200'
229238106Sdes      fi
230238106Sdes      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
231238106Sdes    *)
232238106Sdes      if test -z "$stripcmd"; then
233238106Sdes	u_plus_rw=
234238106Sdes      else
235238106Sdes	u_plus_rw=,u+rw
236238106Sdes      fi
237238106Sdes      cp_umask=$mode$u_plus_rw;;
238238106Sdes  esac
239238106Sdesfi
240238106Sdes
241238106Sdesfor src
242238106Sdesdo
243249141Sdes  # Protect names problematic for 'test' and other utilities.
244238106Sdes  case $src in
245249141Sdes    -* | [=\(\)!]) src=./$src;;
246238106Sdes  esac
247238106Sdes
248238106Sdes  if test -n "$dir_arg"; then
249238106Sdes    dst=$src
250238106Sdes    dstdir=$dst
251238106Sdes    test -d "$dstdir"
252238106Sdes    dstdir_status=$?
253238106Sdes  else
254238106Sdes
255238106Sdes    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
256238106Sdes    # might cause directories to be created, which would be especially bad
257238106Sdes    # if $src (and thus $dsttmp) contains '*'.
258238106Sdes    if test ! -f "$src" && test ! -d "$src"; then
259238106Sdes      echo "$0: $src does not exist." >&2
260238106Sdes      exit 1
261238106Sdes    fi
262238106Sdes
263238106Sdes    if test -z "$dst_arg"; then
264238106Sdes      echo "$0: no destination specified." >&2
265238106Sdes      exit 1
266238106Sdes    fi
267238106Sdes    dst=$dst_arg
268238106Sdes
269238106Sdes    # If destination is a directory, append the input filename; won't work
270238106Sdes    # if double slashes aren't ignored.
271238106Sdes    if test -d "$dst"; then
272238106Sdes      if test -n "$no_target_directory"; then
273238106Sdes	echo "$0: $dst_arg: Is a directory" >&2
274238106Sdes	exit 1
275238106Sdes      fi
276238106Sdes      dstdir=$dst
277238106Sdes      dst=$dstdir/`basename "$src"`
278238106Sdes      dstdir_status=0
279238106Sdes    else
280238106Sdes      # Prefer dirname, but fall back on a substitute if dirname fails.
281238106Sdes      dstdir=`
282238106Sdes	(dirname "$dst") 2>/dev/null ||
283238106Sdes	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
284238106Sdes	     X"$dst" : 'X\(//\)[^/]' \| \
285238106Sdes	     X"$dst" : 'X\(//\)$' \| \
286238106Sdes	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
287238106Sdes	echo X"$dst" |
288238106Sdes	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
289238106Sdes		   s//\1/
290238106Sdes		   q
291238106Sdes		 }
292238106Sdes		 /^X\(\/\/\)[^/].*/{
293238106Sdes		   s//\1/
294238106Sdes		   q
295238106Sdes		 }
296238106Sdes		 /^X\(\/\/\)$/{
297238106Sdes		   s//\1/
298238106Sdes		   q
299238106Sdes		 }
300238106Sdes		 /^X\(\/\).*/{
301238106Sdes		   s//\1/
302238106Sdes		   q
303238106Sdes		 }
304238106Sdes		 s/.*/./; q'
305238106Sdes      `
306238106Sdes
307238106Sdes      test -d "$dstdir"
308238106Sdes      dstdir_status=$?
309238106Sdes    fi
310238106Sdes  fi
311238106Sdes
312238106Sdes  obsolete_mkdir_used=false
313238106Sdes
314238106Sdes  if test $dstdir_status != 0; then
315238106Sdes    case $posix_mkdir in
316238106Sdes      '')
317238106Sdes	# Create intermediate dirs using mode 755 as modified by the umask.
318238106Sdes	# This is like FreeBSD 'install' as of 1997-10-28.
319238106Sdes	umask=`umask`
320238106Sdes	case $stripcmd.$umask in
321238106Sdes	  # Optimize common cases.
322238106Sdes	  *[2367][2367]) mkdir_umask=$umask;;
323238106Sdes	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
324238106Sdes
325238106Sdes	  *[0-7])
326238106Sdes	    mkdir_umask=`expr $umask + 22 \
327238106Sdes	      - $umask % 100 % 40 + $umask % 20 \
328238106Sdes	      - $umask % 10 % 4 + $umask % 2
329238106Sdes	    `;;
330238106Sdes	  *) mkdir_umask=$umask,go-w;;
331238106Sdes	esac
332238106Sdes
333238106Sdes	# With -d, create the new directory with the user-specified mode.
334238106Sdes	# Otherwise, rely on $mkdir_umask.
335238106Sdes	if test -n "$dir_arg"; then
336238106Sdes	  mkdir_mode=-m$mode
337238106Sdes	else
338238106Sdes	  mkdir_mode=
339238106Sdes	fi
340238106Sdes
341238106Sdes	posix_mkdir=false
342238106Sdes	case $umask in
343238106Sdes	  *[123567][0-7][0-7])
344238106Sdes	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
345238106Sdes	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
346238106Sdes	    ;;
347238106Sdes	  *)
348238106Sdes	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
349238106Sdes	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
350238106Sdes
351238106Sdes	    if (umask $mkdir_umask &&
352238106Sdes		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
353238106Sdes	    then
354238106Sdes	      if test -z "$dir_arg" || {
355238106Sdes		   # Check for POSIX incompatibilities with -m.
356238106Sdes		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
357249141Sdes		   # other-writable bit of parent directory when it shouldn't.
358238106Sdes		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
359238106Sdes		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
360238106Sdes		   case $ls_ld_tmpdir in
361238106Sdes		     d????-?r-*) different_mode=700;;
362238106Sdes		     d????-?--*) different_mode=755;;
363238106Sdes		     *) false;;
364238106Sdes		   esac &&
365238106Sdes		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
366238106Sdes		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
367238106Sdes		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
368238106Sdes		   }
369238106Sdes		 }
370238106Sdes	      then posix_mkdir=:
371238106Sdes	      fi
372238106Sdes	      rmdir "$tmpdir/d" "$tmpdir"
373238106Sdes	    else
374238106Sdes	      # Remove any dirs left behind by ancient mkdir implementations.
375238106Sdes	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
376238106Sdes	    fi
377238106Sdes	    trap '' 0;;
378238106Sdes	esac;;
379238106Sdes    esac
380238106Sdes
381238106Sdes    if
382238106Sdes      $posix_mkdir && (
383238106Sdes	umask $mkdir_umask &&
384238106Sdes	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
385238106Sdes      )
386238106Sdes    then :
387238106Sdes    else
388238106Sdes
389238106Sdes      # The umask is ridiculous, or mkdir does not conform to POSIX,
390238106Sdes      # or it failed possibly due to a race condition.  Create the
391238106Sdes      # directory the slow way, step by step, checking for races as we go.
392238106Sdes
393238106Sdes      case $dstdir in
394238106Sdes	/*) prefix='/';;
395249141Sdes	[-=\(\)!]*) prefix='./';;
396238106Sdes	*)  prefix='';;
397238106Sdes      esac
398238106Sdes
399238106Sdes      eval "$initialize_posix_glob"
400238106Sdes
401238106Sdes      oIFS=$IFS
402238106Sdes      IFS=/
403238106Sdes      $posix_glob set -f
404238106Sdes      set fnord $dstdir
405238106Sdes      shift
406238106Sdes      $posix_glob set +f
407238106Sdes      IFS=$oIFS
408238106Sdes
409238106Sdes      prefixes=
410238106Sdes
411238106Sdes      for d
412238106Sdes      do
413249141Sdes	test X"$d" = X && continue
414238106Sdes
415238106Sdes	prefix=$prefix$d
416238106Sdes	if test -d "$prefix"; then
417238106Sdes	  prefixes=
418238106Sdes	else
419238106Sdes	  if $posix_mkdir; then
420238106Sdes	    (umask=$mkdir_umask &&
421238106Sdes	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
422238106Sdes	    # Don't fail if two instances are running concurrently.
423238106Sdes	    test -d "$prefix" || exit 1
424238106Sdes	  else
425238106Sdes	    case $prefix in
426238106Sdes	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
427238106Sdes	      *) qprefix=$prefix;;
428238106Sdes	    esac
429238106Sdes	    prefixes="$prefixes '$qprefix'"
430238106Sdes	  fi
431238106Sdes	fi
432238106Sdes	prefix=$prefix/
433238106Sdes      done
434238106Sdes
435238106Sdes      if test -n "$prefixes"; then
436238106Sdes	# Don't fail if two instances are running concurrently.
437238106Sdes	(umask $mkdir_umask &&
438238106Sdes	 eval "\$doit_exec \$mkdirprog $prefixes") ||
439238106Sdes	  test -d "$dstdir" || exit 1
440238106Sdes	obsolete_mkdir_used=true
441238106Sdes      fi
442238106Sdes    fi
443238106Sdes  fi
444238106Sdes
445238106Sdes  if test -n "$dir_arg"; then
446238106Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
447238106Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
448238106Sdes    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
449238106Sdes      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
450238106Sdes  else
451238106Sdes
452238106Sdes    # Make a couple of temp file names in the proper directory.
453238106Sdes    dsttmp=$dstdir/_inst.$$_
454238106Sdes    rmtmp=$dstdir/_rm.$$_
455238106Sdes
456238106Sdes    # Trap to clean up those temp files at exit.
457238106Sdes    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
458238106Sdes
459238106Sdes    # Copy the file name to the temp name.
460238106Sdes    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
461238106Sdes
462238106Sdes    # and set any options; do chmod last to preserve setuid bits.
463238106Sdes    #
464238106Sdes    # If any of these fail, we abort the whole thing.  If we want to
465238106Sdes    # ignore errors from any of these, just make sure not to ignore
466238106Sdes    # errors from the above "$doit $cpprog $src $dsttmp" command.
467238106Sdes    #
468238106Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
469238106Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
470238106Sdes    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
471238106Sdes    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
472238106Sdes
473238106Sdes    # If -C, don't bother to copy if it wouldn't change the file.
474238106Sdes    if $copy_on_change &&
475238106Sdes       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
476238106Sdes       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
477238106Sdes
478238106Sdes       eval "$initialize_posix_glob" &&
479238106Sdes       $posix_glob set -f &&
480238106Sdes       set X $old && old=:$2:$4:$5:$6 &&
481238106Sdes       set X $new && new=:$2:$4:$5:$6 &&
482238106Sdes       $posix_glob set +f &&
483238106Sdes
484238106Sdes       test "$old" = "$new" &&
485238106Sdes       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
486238106Sdes    then
487238106Sdes      rm -f "$dsttmp"
488238106Sdes    else
489238106Sdes      # Rename the file to the real destination.
490238106Sdes      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
491238106Sdes
492238106Sdes      # The rename failed, perhaps because mv can't rename something else
493238106Sdes      # to itself, or perhaps because mv is so ancient that it does not
494238106Sdes      # support -f.
495238106Sdes      {
496238106Sdes	# Now remove or move aside any old file at destination location.
497238106Sdes	# We try this two ways since rm can't unlink itself on some
498238106Sdes	# systems and the destination file might be busy for other
499238106Sdes	# reasons.  In this case, the final cleanup might fail but the new
500238106Sdes	# file should still install successfully.
501238106Sdes	{
502238106Sdes	  test ! -f "$dst" ||
503238106Sdes	  $doit $rmcmd -f "$dst" 2>/dev/null ||
504238106Sdes	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
505238106Sdes	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
506238106Sdes	  } ||
507238106Sdes	  { echo "$0: cannot unlink or rename $dst" >&2
508238106Sdes	    (exit 1); exit 1
509238106Sdes	  }
510238106Sdes	} &&
511238106Sdes
512238106Sdes	# Now rename the file to the real destination.
513238106Sdes	$doit $mvcmd "$dsttmp" "$dst"
514238106Sdes      }
515238106Sdes    fi || exit 1
516238106Sdes
517238106Sdes    trap '' 0
518238106Sdes  fi
519238106Sdesdone
520238106Sdes
521238106Sdes# Local variables:
522238106Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
523238106Sdes# time-stamp-start: "scriptversion="
524238106Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
525238106Sdes# time-stamp-time-zone: "UTC"
526238106Sdes# time-stamp-end: "; # UTC"
527238106Sdes# End:
528