1238104Sdes#!/bin/sh
2238104Sdes# install - install a program, script, or datafile
3238104Sdes
4266114Sdesscriptversion=2011-11-20.07; # UTC
5238104Sdes
6238104Sdes# This originates from X11R5 (mit/util/scripts/install.sh), which was
7238104Sdes# later released in X11R6 (xc/config/util/install.sh) with the
8238104Sdes# following copyright and license.
9238104Sdes#
10238104Sdes# Copyright (C) 1994 X Consortium
11238104Sdes#
12238104Sdes# Permission is hereby granted, free of charge, to any person obtaining a copy
13238104Sdes# of this software and associated documentation files (the "Software"), to
14238104Sdes# deal in the Software without restriction, including without limitation the
15238104Sdes# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16238104Sdes# sell copies of the Software, and to permit persons to whom the Software is
17238104Sdes# furnished to do so, subject to the following conditions:
18238104Sdes#
19238104Sdes# The above copyright notice and this permission notice shall be included in
20238104Sdes# all copies or substantial portions of the Software.
21238104Sdes#
22238104Sdes# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23238104Sdes# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24238104Sdes# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25238104Sdes# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26238104Sdes# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27238104Sdes# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28238104Sdes#
29238104Sdes# Except as contained in this notice, the name of the X Consortium shall not
30238104Sdes# be used in advertising or otherwise to promote the sale, use or other deal-
31238104Sdes# ings in this Software without prior written authorization from the X Consor-
32238104Sdes# tium.
33238104Sdes#
34238104Sdes#
35238104Sdes# FSF changes to this file are in the public domain.
36238104Sdes#
37238104Sdes# Calling this script install-sh is preferred over install.sh, to prevent
38266114Sdes# 'make' implicit rules from creating a file called install from it
39238104Sdes# when there is no Makefile.
40238104Sdes#
41238104Sdes# This script is compatible with the BSD install script, but was written
42238104Sdes# from scratch.
43238104Sdes
44238104Sdesnl='
45238104Sdes'
46238104SdesIFS=" ""	$nl"
47238104Sdes
48238104Sdes# set DOITPROG to echo to test this script
49238104Sdes
50238104Sdes# Don't use :- since 4.3BSD and earlier shells don't like it.
51238104Sdesdoit=${DOITPROG-}
52238104Sdesif test -z "$doit"; then
53238104Sdes  doit_exec=exec
54238104Sdeselse
55238104Sdes  doit_exec=$doit
56238104Sdesfi
57238104Sdes
58238104Sdes# Put in absolute file names if you don't have them in your path;
59238104Sdes# or use environment vars.
60238104Sdes
61238104Sdeschgrpprog=${CHGRPPROG-chgrp}
62238104Sdeschmodprog=${CHMODPROG-chmod}
63238104Sdeschownprog=${CHOWNPROG-chown}
64238104Sdescmpprog=${CMPPROG-cmp}
65238104Sdescpprog=${CPPROG-cp}
66238104Sdesmkdirprog=${MKDIRPROG-mkdir}
67238104Sdesmvprog=${MVPROG-mv}
68238104Sdesrmprog=${RMPROG-rm}
69238104Sdesstripprog=${STRIPPROG-strip}
70238104Sdes
71238104Sdesposix_glob='?'
72238104Sdesinitialize_posix_glob='
73238104Sdes  test "$posix_glob" != "?" || {
74238104Sdes    if (set -f) 2>/dev/null; then
75238104Sdes      posix_glob=
76238104Sdes    else
77238104Sdes      posix_glob=:
78238104Sdes    fi
79238104Sdes  }
80238104Sdes'
81238104Sdes
82238104Sdesposix_mkdir=
83238104Sdes
84238104Sdes# Desired mode of installed file.
85238104Sdesmode=0755
86238104Sdes
87238104Sdeschgrpcmd=
88238104Sdeschmodcmd=$chmodprog
89238104Sdeschowncmd=
90238104Sdesmvcmd=$mvprog
91238104Sdesrmcmd="$rmprog -f"
92238104Sdesstripcmd=
93238104Sdes
94238104Sdessrc=
95238104Sdesdst=
96238104Sdesdir_arg=
97238104Sdesdst_arg=
98238104Sdes
99238104Sdescopy_on_change=false
100238104Sdesno_target_directory=
101238104Sdes
102238104Sdesusage="\
103238104SdesUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104238104Sdes   or: $0 [OPTION]... SRCFILES... DIRECTORY
105238104Sdes   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106238104Sdes   or: $0 [OPTION]... -d DIRECTORIES...
107238104Sdes
108238104SdesIn the 1st form, copy SRCFILE to DSTFILE.
109238104SdesIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110238104SdesIn the 4th, create DIRECTORIES.
111238104Sdes
112238104SdesOptions:
113238104Sdes     --help     display this help and exit.
114238104Sdes     --version  display version info and exit.
115238104Sdes
116238104Sdes  -c            (ignored)
117238104Sdes  -C            install only if different (preserve the last data modification time)
118238104Sdes  -d            create directories instead of installing files.
119238104Sdes  -g GROUP      $chgrpprog installed files to GROUP.
120238104Sdes  -m MODE       $chmodprog installed files to MODE.
121238104Sdes  -o USER       $chownprog installed files to USER.
122238104Sdes  -s            $stripprog installed files.
123238104Sdes  -t DIRECTORY  install into DIRECTORY.
124238104Sdes  -T            report an error if DSTFILE is a directory.
125238104Sdes
126238104SdesEnvironment variables override the default commands:
127238104Sdes  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
128238104Sdes  RMPROG STRIPPROG
129238104Sdes"
130238104Sdes
131238104Sdeswhile test $# -ne 0; do
132238104Sdes  case $1 in
133238104Sdes    -c) ;;
134238104Sdes
135238104Sdes    -C) copy_on_change=true;;
136238104Sdes
137238104Sdes    -d) dir_arg=true;;
138238104Sdes
139238104Sdes    -g) chgrpcmd="$chgrpprog $2"
140238104Sdes	shift;;
141238104Sdes
142238104Sdes    --help) echo "$usage"; exit $?;;
143238104Sdes
144238104Sdes    -m) mode=$2
145238104Sdes	case $mode in
146238104Sdes	  *' '* | *'	'* | *'
147238104Sdes'*	  | *'*'* | *'?'* | *'['*)
148238104Sdes	    echo "$0: invalid mode: $mode" >&2
149238104Sdes	    exit 1;;
150238104Sdes	esac
151238104Sdes	shift;;
152238104Sdes
153238104Sdes    -o) chowncmd="$chownprog $2"
154238104Sdes	shift;;
155238104Sdes
156238104Sdes    -s) stripcmd=$stripprog;;
157238104Sdes
158238104Sdes    -t) dst_arg=$2
159266114Sdes	# Protect names problematic for 'test' and other utilities.
160238104Sdes	case $dst_arg in
161238104Sdes	  -* | [=\(\)!]) dst_arg=./$dst_arg;;
162238104Sdes	esac
163238104Sdes	shift;;
164238104Sdes
165238104Sdes    -T) no_target_directory=true;;
166238104Sdes
167238104Sdes    --version) echo "$0 $scriptversion"; exit $?;;
168238104Sdes
169238104Sdes    --)	shift
170238104Sdes	break;;
171238104Sdes
172238104Sdes    -*)	echo "$0: invalid option: $1" >&2
173238104Sdes	exit 1;;
174238104Sdes
175238104Sdes    *)  break;;
176238104Sdes  esac
177238104Sdes  shift
178238104Sdesdone
179238104Sdes
180238104Sdesif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
181238104Sdes  # When -d is used, all remaining arguments are directories to create.
182238104Sdes  # When -t is used, the destination is already specified.
183238104Sdes  # Otherwise, the last argument is the destination.  Remove it from $@.
184238104Sdes  for arg
185238104Sdes  do
186238104Sdes    if test -n "$dst_arg"; then
187238104Sdes      # $@ is not empty: it contains at least $arg.
188238104Sdes      set fnord "$@" "$dst_arg"
189238104Sdes      shift # fnord
190238104Sdes    fi
191238104Sdes    shift # arg
192238104Sdes    dst_arg=$arg
193266114Sdes    # Protect names problematic for 'test' and other utilities.
194238104Sdes    case $dst_arg in
195238104Sdes      -* | [=\(\)!]) dst_arg=./$dst_arg;;
196238104Sdes    esac
197238104Sdes  done
198238104Sdesfi
199238104Sdes
200238104Sdesif test $# -eq 0; then
201238104Sdes  if test -z "$dir_arg"; then
202238104Sdes    echo "$0: no input file specified." >&2
203238104Sdes    exit 1
204238104Sdes  fi
205266114Sdes  # It's OK to call 'install-sh -d' without argument.
206238104Sdes  # This can happen when creating conditional directories.
207238104Sdes  exit 0
208238104Sdesfi
209238104Sdes
210238104Sdesif test -z "$dir_arg"; then
211238104Sdes  do_exit='(exit $ret); exit $ret'
212238104Sdes  trap "ret=129; $do_exit" 1
213238104Sdes  trap "ret=130; $do_exit" 2
214238104Sdes  trap "ret=141; $do_exit" 13
215238104Sdes  trap "ret=143; $do_exit" 15
216238104Sdes
217238104Sdes  # Set umask so as not to create temps with too-generous modes.
218238104Sdes  # However, 'strip' requires both read and write access to temps.
219238104Sdes  case $mode in
220238104Sdes    # Optimize common cases.
221238104Sdes    *644) cp_umask=133;;
222238104Sdes    *755) cp_umask=22;;
223238104Sdes
224238104Sdes    *[0-7])
225238104Sdes      if test -z "$stripcmd"; then
226238104Sdes	u_plus_rw=
227238104Sdes      else
228238104Sdes	u_plus_rw='% 200'
229238104Sdes      fi
230238104Sdes      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
231238104Sdes    *)
232238104Sdes      if test -z "$stripcmd"; then
233238104Sdes	u_plus_rw=
234238104Sdes      else
235238104Sdes	u_plus_rw=,u+rw
236238104Sdes      fi
237238104Sdes      cp_umask=$mode$u_plus_rw;;
238238104Sdes  esac
239238104Sdesfi
240238104Sdes
241238104Sdesfor src
242238104Sdesdo
243266114Sdes  # Protect names problematic for 'test' and other utilities.
244238104Sdes  case $src in
245238104Sdes    -* | [=\(\)!]) src=./$src;;
246238104Sdes  esac
247238104Sdes
248238104Sdes  if test -n "$dir_arg"; then
249238104Sdes    dst=$src
250238104Sdes    dstdir=$dst
251238104Sdes    test -d "$dstdir"
252238104Sdes    dstdir_status=$?
253238104Sdes  else
254238104Sdes
255238104Sdes    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
256238104Sdes    # might cause directories to be created, which would be especially bad
257238104Sdes    # if $src (and thus $dsttmp) contains '*'.
258238104Sdes    if test ! -f "$src" && test ! -d "$src"; then
259238104Sdes      echo "$0: $src does not exist." >&2
260238104Sdes      exit 1
261238104Sdes    fi
262238104Sdes
263238104Sdes    if test -z "$dst_arg"; then
264238104Sdes      echo "$0: no destination specified." >&2
265238104Sdes      exit 1
266238104Sdes    fi
267238104Sdes    dst=$dst_arg
268238104Sdes
269238104Sdes    # If destination is a directory, append the input filename; won't work
270238104Sdes    # if double slashes aren't ignored.
271238104Sdes    if test -d "$dst"; then
272238104Sdes      if test -n "$no_target_directory"; then
273238104Sdes	echo "$0: $dst_arg: Is a directory" >&2
274238104Sdes	exit 1
275238104Sdes      fi
276238104Sdes      dstdir=$dst
277238104Sdes      dst=$dstdir/`basename "$src"`
278238104Sdes      dstdir_status=0
279238104Sdes    else
280238104Sdes      # Prefer dirname, but fall back on a substitute if dirname fails.
281238104Sdes      dstdir=`
282238104Sdes	(dirname "$dst") 2>/dev/null ||
283238104Sdes	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
284238104Sdes	     X"$dst" : 'X\(//\)[^/]' \| \
285238104Sdes	     X"$dst" : 'X\(//\)$' \| \
286238104Sdes	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
287238104Sdes	echo X"$dst" |
288238104Sdes	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
289238104Sdes		   s//\1/
290238104Sdes		   q
291238104Sdes		 }
292238104Sdes		 /^X\(\/\/\)[^/].*/{
293238104Sdes		   s//\1/
294238104Sdes		   q
295238104Sdes		 }
296238104Sdes		 /^X\(\/\/\)$/{
297238104Sdes		   s//\1/
298238104Sdes		   q
299238104Sdes		 }
300238104Sdes		 /^X\(\/\).*/{
301238104Sdes		   s//\1/
302238104Sdes		   q
303238104Sdes		 }
304238104Sdes		 s/.*/./; q'
305238104Sdes      `
306238104Sdes
307238104Sdes      test -d "$dstdir"
308238104Sdes      dstdir_status=$?
309238104Sdes    fi
310238104Sdes  fi
311238104Sdes
312238104Sdes  obsolete_mkdir_used=false
313238104Sdes
314238104Sdes  if test $dstdir_status != 0; then
315238104Sdes    case $posix_mkdir in
316238104Sdes      '')
317238104Sdes	# Create intermediate dirs using mode 755 as modified by the umask.
318238104Sdes	# This is like FreeBSD 'install' as of 1997-10-28.
319238104Sdes	umask=`umask`
320238104Sdes	case $stripcmd.$umask in
321238104Sdes	  # Optimize common cases.
322238104Sdes	  *[2367][2367]) mkdir_umask=$umask;;
323238104Sdes	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
324238104Sdes
325238104Sdes	  *[0-7])
326238104Sdes	    mkdir_umask=`expr $umask + 22 \
327238104Sdes	      - $umask % 100 % 40 + $umask % 20 \
328238104Sdes	      - $umask % 10 % 4 + $umask % 2
329238104Sdes	    `;;
330238104Sdes	  *) mkdir_umask=$umask,go-w;;
331238104Sdes	esac
332238104Sdes
333238104Sdes	# With -d, create the new directory with the user-specified mode.
334238104Sdes	# Otherwise, rely on $mkdir_umask.
335238104Sdes	if test -n "$dir_arg"; then
336238104Sdes	  mkdir_mode=-m$mode
337238104Sdes	else
338238104Sdes	  mkdir_mode=
339238104Sdes	fi
340238104Sdes
341238104Sdes	posix_mkdir=false
342238104Sdes	case $umask in
343238104Sdes	  *[123567][0-7][0-7])
344238104Sdes	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
345238104Sdes	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
346238104Sdes	    ;;
347238104Sdes	  *)
348238104Sdes	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
349238104Sdes	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
350238104Sdes
351238104Sdes	    if (umask $mkdir_umask &&
352238104Sdes		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
353238104Sdes	    then
354238104Sdes	      if test -z "$dir_arg" || {
355238104Sdes		   # Check for POSIX incompatibilities with -m.
356238104Sdes		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
357266114Sdes		   # other-writable bit of parent directory when it shouldn't.
358238104Sdes		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
359238104Sdes		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
360238104Sdes		   case $ls_ld_tmpdir in
361238104Sdes		     d????-?r-*) different_mode=700;;
362238104Sdes		     d????-?--*) different_mode=755;;
363238104Sdes		     *) false;;
364238104Sdes		   esac &&
365238104Sdes		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
366238104Sdes		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
367238104Sdes		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
368238104Sdes		   }
369238104Sdes		 }
370238104Sdes	      then posix_mkdir=:
371238104Sdes	      fi
372238104Sdes	      rmdir "$tmpdir/d" "$tmpdir"
373238104Sdes	    else
374238104Sdes	      # Remove any dirs left behind by ancient mkdir implementations.
375238104Sdes	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
376238104Sdes	    fi
377238104Sdes	    trap '' 0;;
378238104Sdes	esac;;
379238104Sdes    esac
380238104Sdes
381238104Sdes    if
382238104Sdes      $posix_mkdir && (
383238104Sdes	umask $mkdir_umask &&
384238104Sdes	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
385238104Sdes      )
386238104Sdes    then :
387238104Sdes    else
388238104Sdes
389238104Sdes      # The umask is ridiculous, or mkdir does not conform to POSIX,
390238104Sdes      # or it failed possibly due to a race condition.  Create the
391238104Sdes      # directory the slow way, step by step, checking for races as we go.
392238104Sdes
393238104Sdes      case $dstdir in
394238104Sdes	/*) prefix='/';;
395238104Sdes	[-=\(\)!]*) prefix='./';;
396238104Sdes	*)  prefix='';;
397238104Sdes      esac
398238104Sdes
399238104Sdes      eval "$initialize_posix_glob"
400238104Sdes
401238104Sdes      oIFS=$IFS
402238104Sdes      IFS=/
403238104Sdes      $posix_glob set -f
404238104Sdes      set fnord $dstdir
405238104Sdes      shift
406238104Sdes      $posix_glob set +f
407238104Sdes      IFS=$oIFS
408238104Sdes
409238104Sdes      prefixes=
410238104Sdes
411238104Sdes      for d
412238104Sdes      do
413238104Sdes	test X"$d" = X && continue
414238104Sdes
415238104Sdes	prefix=$prefix$d
416238104Sdes	if test -d "$prefix"; then
417238104Sdes	  prefixes=
418238104Sdes	else
419238104Sdes	  if $posix_mkdir; then
420238104Sdes	    (umask=$mkdir_umask &&
421238104Sdes	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
422238104Sdes	    # Don't fail if two instances are running concurrently.
423238104Sdes	    test -d "$prefix" || exit 1
424238104Sdes	  else
425238104Sdes	    case $prefix in
426238104Sdes	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
427238104Sdes	      *) qprefix=$prefix;;
428238104Sdes	    esac
429238104Sdes	    prefixes="$prefixes '$qprefix'"
430238104Sdes	  fi
431238104Sdes	fi
432238104Sdes	prefix=$prefix/
433238104Sdes      done
434238104Sdes
435238104Sdes      if test -n "$prefixes"; then
436238104Sdes	# Don't fail if two instances are running concurrently.
437238104Sdes	(umask $mkdir_umask &&
438238104Sdes	 eval "\$doit_exec \$mkdirprog $prefixes") ||
439238104Sdes	  test -d "$dstdir" || exit 1
440238104Sdes	obsolete_mkdir_used=true
441238104Sdes      fi
442238104Sdes    fi
443238104Sdes  fi
444238104Sdes
445238104Sdes  if test -n "$dir_arg"; then
446238104Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
447238104Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
448238104Sdes    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
449238104Sdes      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
450238104Sdes  else
451238104Sdes
452238104Sdes    # Make a couple of temp file names in the proper directory.
453238104Sdes    dsttmp=$dstdir/_inst.$$_
454238104Sdes    rmtmp=$dstdir/_rm.$$_
455238104Sdes
456238104Sdes    # Trap to clean up those temp files at exit.
457238104Sdes    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
458238104Sdes
459238104Sdes    # Copy the file name to the temp name.
460238104Sdes    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
461238104Sdes
462238104Sdes    # and set any options; do chmod last to preserve setuid bits.
463238104Sdes    #
464238104Sdes    # If any of these fail, we abort the whole thing.  If we want to
465238104Sdes    # ignore errors from any of these, just make sure not to ignore
466238104Sdes    # errors from the above "$doit $cpprog $src $dsttmp" command.
467238104Sdes    #
468238104Sdes    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
469238104Sdes    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
470238104Sdes    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
471238104Sdes    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
472238104Sdes
473238104Sdes    # If -C, don't bother to copy if it wouldn't change the file.
474238104Sdes    if $copy_on_change &&
475238104Sdes       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
476238104Sdes       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
477238104Sdes
478238104Sdes       eval "$initialize_posix_glob" &&
479238104Sdes       $posix_glob set -f &&
480238104Sdes       set X $old && old=:$2:$4:$5:$6 &&
481238104Sdes       set X $new && new=:$2:$4:$5:$6 &&
482238104Sdes       $posix_glob set +f &&
483238104Sdes
484238104Sdes       test "$old" = "$new" &&
485238104Sdes       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
486238104Sdes    then
487238104Sdes      rm -f "$dsttmp"
488238104Sdes    else
489238104Sdes      # Rename the file to the real destination.
490238104Sdes      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
491238104Sdes
492238104Sdes      # The rename failed, perhaps because mv can't rename something else
493238104Sdes      # to itself, or perhaps because mv is so ancient that it does not
494238104Sdes      # support -f.
495238104Sdes      {
496238104Sdes	# Now remove or move aside any old file at destination location.
497238104Sdes	# We try this two ways since rm can't unlink itself on some
498238104Sdes	# systems and the destination file might be busy for other
499238104Sdes	# reasons.  In this case, the final cleanup might fail but the new
500238104Sdes	# file should still install successfully.
501238104Sdes	{
502238104Sdes	  test ! -f "$dst" ||
503238104Sdes	  $doit $rmcmd -f "$dst" 2>/dev/null ||
504238104Sdes	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
505238104Sdes	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
506238104Sdes	  } ||
507238104Sdes	  { echo "$0: cannot unlink or rename $dst" >&2
508238104Sdes	    (exit 1); exit 1
509238104Sdes	  }
510238104Sdes	} &&
511238104Sdes
512238104Sdes	# Now rename the file to the real destination.
513238104Sdes	$doit $mvcmd "$dsttmp" "$dst"
514238104Sdes      }
515238104Sdes    fi || exit 1
516238104Sdes
517238104Sdes    trap '' 0
518238104Sdes  fi
519238104Sdesdone
520238104Sdes
521238104Sdes# Local variables:
522238104Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
523238104Sdes# time-stamp-start: "scriptversion="
524238104Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
525238104Sdes# time-stamp-time-zone: "UTC"
526238104Sdes# time-stamp-end: "; # UTC"
527238104Sdes# End:
528