1102644Snectar#!/bin/sh
255682Smarkm# install - install a program, script, or datafile
3142403Snectar
4233294Sstasscriptversion=2009-04-28.21; # UTC
5142403Snectar
6127808Snectar# This originates from X11R5 (mit/util/scripts/install.sh), which was
7127808Snectar# later released in X11R6 (xc/config/util/install.sh) with the
8127808Snectar# following copyright and license.
9102644Snectar#
10127808Snectar# Copyright (C) 1994 X Consortium
11102644Snectar#
12127808Snectar# Permission is hereby granted, free of charge, to any person obtaining a copy
13127808Snectar# of this software and associated documentation files (the "Software"), to
14127808Snectar# deal in the Software without restriction, including without limitation the
15127808Snectar# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16127808Snectar# sell copies of the Software, and to permit persons to whom the Software is
17127808Snectar# furnished to do so, subject to the following conditions:
18127808Snectar#
19127808Snectar# The above copyright notice and this permission notice shall be included in
20127808Snectar# all copies or substantial portions of the Software.
21127808Snectar#
22127808Snectar# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23127808Snectar# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24127808Snectar# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25127808Snectar# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26127808Snectar# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27127808Snectar# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28127808Snectar#
29127808Snectar# Except as contained in this notice, the name of the X Consortium shall not
30127808Snectar# be used in advertising or otherwise to promote the sale, use or other deal-
31127808Snectar# ings in this Software without prior written authorization from the X Consor-
32127808Snectar# tium.
33127808Snectar#
34127808Snectar#
35127808Snectar# FSF changes to this file are in the public domain.
36127808Snectar#
3755682Smarkm# Calling this script install-sh is preferred over install.sh, to prevent
3855682Smarkm# `make' implicit rules from creating a file called install from it
3955682Smarkm# when there is no Makefile.
4055682Smarkm#
4155682Smarkm# This script is compatible with the BSD install script, but was written
42178825Sdfr# from scratch.
4355682Smarkm
44178825Sdfrnl='
45178825Sdfr'
46178825SdfrIFS=" ""	$nl"
47178825Sdfr
4855682Smarkm# set DOITPROG to echo to test this script
4955682Smarkm
5055682Smarkm# Don't use :- since 4.3BSD and earlier shells don't like it.
51233294Sstasdoit=${DOITPROG-}
52178825Sdfrif test -z "$doit"; then
53178825Sdfr  doit_exec=exec
54178825Sdfrelse
55178825Sdfr  doit_exec=$doit
56178825Sdfrfi
5755682Smarkm
58178825Sdfr# Put in absolute file names if you don't have them in your path;
59178825Sdfr# or use environment vars.
6055682Smarkm
61233294Sstaschgrpprog=${CHGRPPROG-chgrp}
62233294Sstaschmodprog=${CHMODPROG-chmod}
63233294Sstaschownprog=${CHOWNPROG-chown}
64233294Sstascmpprog=${CMPPROG-cmp}
65233294Sstascpprog=${CPPROG-cp}
66233294Sstasmkdirprog=${MKDIRPROG-mkdir}
67233294Sstasmvprog=${MVPROG-mv}
68233294Sstasrmprog=${RMPROG-rm}
69233294Sstasstripprog=${STRIPPROG-strip}
7055682Smarkm
71233294Sstasposix_glob='?'
72233294Sstasinitialize_posix_glob='
73233294Sstas  test "$posix_glob" != "?" || {
74233294Sstas    if (set -f) 2>/dev/null; then
75233294Sstas      posix_glob=
76233294Sstas    else
77233294Sstas      posix_glob=:
78233294Sstas    fi
79233294Sstas  }
80233294Sstas'
81233294Sstas
82178825Sdfrposix_mkdir=
83178825Sdfr
84178825Sdfr# Desired mode of installed file.
85178825Sdfrmode=0755
86178825Sdfr
87233294Sstaschgrpcmd=
88178825Sdfrchmodcmd=$chmodprog
89142403Snectarchowncmd=
90233294Sstasmvcmd=$mvprog
91233294Sstasrmcmd="$rmprog -f"
92142403Snectarstripcmd=
93233294Sstas
94142403Snectarsrc=
95142403Snectardst=
96142403Snectardir_arg=
97233294Sstasdst_arg=
98233294Sstas
99233294Sstascopy_on_change=false
100178825Sdfrno_target_directory=
10155682Smarkm
102233294Sstasusage="\
103233294SstasUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104142403Snectar   or: $0 [OPTION]... SRCFILES... DIRECTORY
105178825Sdfr   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106178825Sdfr   or: $0 [OPTION]... -d DIRECTORIES...
10755682Smarkm
108178825SdfrIn the 1st form, copy SRCFILE to DSTFILE.
109178825SdfrIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110178825SdfrIn the 4th, create DIRECTORIES.
11155682Smarkm
112142403SnectarOptions:
113233294Sstas     --help     display this help and exit.
114233294Sstas     --version  display version info and exit.
11555682Smarkm
116233294Sstas  -c            (ignored)
117233294Sstas  -C            install only if different (preserve the last data modification time)
118233294Sstas  -d            create directories instead of installing files.
119233294Sstas  -g GROUP      $chgrpprog installed files to GROUP.
120233294Sstas  -m MODE       $chmodprog installed files to MODE.
121233294Sstas  -o USER       $chownprog installed files to USER.
122233294Sstas  -s            $stripprog installed files.
123233294Sstas  -t DIRECTORY  install into DIRECTORY.
124233294Sstas  -T            report an error if DSTFILE is a directory.
125233294Sstas
126142403SnectarEnvironment variables override the default commands:
127233294Sstas  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
128233294Sstas  RMPROG STRIPPROG
129142403Snectar"
13055682Smarkm
131178825Sdfrwhile test $# -ne 0; do
132142403Snectar  case $1 in
133233294Sstas    -c) ;;
13455682Smarkm
135233294Sstas    -C) copy_on_change=true;;
13655682Smarkm
137233294Sstas    -d) dir_arg=true;;
138233294Sstas
139142403Snectar    -g) chgrpcmd="$chgrpprog $2"
140233294Sstas	shift;;
14155682Smarkm
142178825Sdfr    --help) echo "$usage"; exit $?;;
14355682Smarkm
144178825Sdfr    -m) mode=$2
145178825Sdfr	case $mode in
146178825Sdfr	  *' '* | *'	'* | *'
147178825Sdfr'*	  | *'*'* | *'?'* | *'['*)
148178825Sdfr	    echo "$0: invalid mode: $mode" >&2
149178825Sdfr	    exit 1;;
150178825Sdfr	esac
151233294Sstas	shift;;
15255682Smarkm
153142403Snectar    -o) chowncmd="$chownprog $2"
154233294Sstas	shift;;
155127808Snectar
156233294Sstas    -s) stripcmd=$stripprog;;
15755682Smarkm
158233294Sstas    -t) dst_arg=$2
159233294Sstas	shift;;
16055682Smarkm
161233294Sstas    -T) no_target_directory=true;;
162127808Snectar
163178825Sdfr    --version) echo "$0 $scriptversion"; exit $?;;
164178825Sdfr
165178825Sdfr    --)	shift
166142403Snectar	break;;
167178825Sdfr
168178825Sdfr    -*)	echo "$0: invalid option: $1" >&2
169178825Sdfr	exit 1;;
170178825Sdfr
171178825Sdfr    *)  break;;
172142403Snectar  esac
173233294Sstas  shift
174142403Snectardone
17555682Smarkm
176233294Sstasif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
177178825Sdfr  # When -d is used, all remaining arguments are directories to create.
178178825Sdfr  # When -t is used, the destination is already specified.
179178825Sdfr  # Otherwise, the last argument is the destination.  Remove it from $@.
180178825Sdfr  for arg
181178825Sdfr  do
182233294Sstas    if test -n "$dst_arg"; then
183178825Sdfr      # $@ is not empty: it contains at least $arg.
184233294Sstas      set fnord "$@" "$dst_arg"
185178825Sdfr      shift # fnord
186178825Sdfr    fi
187178825Sdfr    shift # arg
188233294Sstas    dst_arg=$arg
189178825Sdfr  done
190178825Sdfrfi
191178825Sdfr
192178825Sdfrif test $# -eq 0; then
193142403Snectar  if test -z "$dir_arg"; then
194142403Snectar    echo "$0: no input file specified." >&2
195142403Snectar    exit 1
196142403Snectar  fi
197142403Snectar  # It's OK to call `install-sh -d' without argument.
198142403Snectar  # This can happen when creating conditional directories.
199142403Snectar  exit 0
20055682Smarkmfi
20155682Smarkm
202178825Sdfrif test -z "$dir_arg"; then
203178825Sdfr  trap '(exit $?); exit' 1 2 13 15
204178825Sdfr
205178825Sdfr  # Set umask so as not to create temps with too-generous modes.
206178825Sdfr  # However, 'strip' requires both read and write access to temps.
207178825Sdfr  case $mode in
208178825Sdfr    # Optimize common cases.
209178825Sdfr    *644) cp_umask=133;;
210178825Sdfr    *755) cp_umask=22;;
211178825Sdfr
212178825Sdfr    *[0-7])
213178825Sdfr      if test -z "$stripcmd"; then
214178825Sdfr	u_plus_rw=
215178825Sdfr      else
216178825Sdfr	u_plus_rw='% 200'
217178825Sdfr      fi
218178825Sdfr      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
219178825Sdfr    *)
220178825Sdfr      if test -z "$stripcmd"; then
221178825Sdfr	u_plus_rw=
222178825Sdfr      else
223178825Sdfr	u_plus_rw=,u+rw
224178825Sdfr      fi
225178825Sdfr      cp_umask=$mode$u_plus_rw;;
226178825Sdfr  esac
227178825Sdfrfi
228178825Sdfr
229142403Snectarfor src
230142403Snectardo
231142403Snectar  # Protect names starting with `-'.
232142403Snectar  case $src in
233233294Sstas    -*) src=./$src;;
234142403Snectar  esac
23555682Smarkm
236142403Snectar  if test -n "$dir_arg"; then
237142403Snectar    dst=$src
238178825Sdfr    dstdir=$dst
239178825Sdfr    test -d "$dstdir"
240178825Sdfr    dstdir_status=$?
241178825Sdfr  else
24255682Smarkm
243178825Sdfr    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
244142403Snectar    # might cause directories to be created, which would be especially bad
245142403Snectar    # if $src (and thus $dsttmp) contains '*'.
246142403Snectar    if test ! -f "$src" && test ! -d "$src"; then
247142403Snectar      echo "$0: $src does not exist." >&2
248142403Snectar      exit 1
249142403Snectar    fi
25055682Smarkm
251233294Sstas    if test -z "$dst_arg"; then
252142403Snectar      echo "$0: no destination specified." >&2
253142403Snectar      exit 1
254142403Snectar    fi
25555682Smarkm
256233294Sstas    dst=$dst_arg
257142403Snectar    # Protect names starting with `-'.
258142403Snectar    case $dst in
259233294Sstas      -*) dst=./$dst;;
260142403Snectar    esac
26155682Smarkm
262142403Snectar    # If destination is a directory, append the input filename; won't work
263142403Snectar    # if double slashes aren't ignored.
264142403Snectar    if test -d "$dst"; then
265178825Sdfr      if test -n "$no_target_directory"; then
266233294Sstas	echo "$0: $dst_arg: Is a directory" >&2
267178825Sdfr	exit 1
268178825Sdfr      fi
269178825Sdfr      dstdir=$dst
270178825Sdfr      dst=$dstdir/`basename "$src"`
271178825Sdfr      dstdir_status=0
272178825Sdfr    else
273178825Sdfr      # Prefer dirname, but fall back on a substitute if dirname fails.
274178825Sdfr      dstdir=`
275178825Sdfr	(dirname "$dst") 2>/dev/null ||
276178825Sdfr	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
277178825Sdfr	     X"$dst" : 'X\(//\)[^/]' \| \
278178825Sdfr	     X"$dst" : 'X\(//\)$' \| \
279178825Sdfr	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
280178825Sdfr	echo X"$dst" |
281178825Sdfr	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
282178825Sdfr		   s//\1/
283178825Sdfr		   q
284178825Sdfr		 }
285178825Sdfr		 /^X\(\/\/\)[^/].*/{
286178825Sdfr		   s//\1/
287178825Sdfr		   q
288178825Sdfr		 }
289178825Sdfr		 /^X\(\/\/\)$/{
290178825Sdfr		   s//\1/
291178825Sdfr		   q
292178825Sdfr		 }
293178825Sdfr		 /^X\(\/\).*/{
294178825Sdfr		   s//\1/
295178825Sdfr		   q
296178825Sdfr		 }
297178825Sdfr		 s/.*/./; q'
298178825Sdfr      `
299178825Sdfr
300178825Sdfr      test -d "$dstdir"
301178825Sdfr      dstdir_status=$?
302142403Snectar    fi
303142403Snectar  fi
30455682Smarkm
305178825Sdfr  obsolete_mkdir_used=false
30655682Smarkm
307178825Sdfr  if test $dstdir_status != 0; then
308178825Sdfr    case $posix_mkdir in
309178825Sdfr      '')
310178825Sdfr	# Create intermediate dirs using mode 755 as modified by the umask.
311178825Sdfr	# This is like FreeBSD 'install' as of 1997-10-28.
312178825Sdfr	umask=`umask`
313178825Sdfr	case $stripcmd.$umask in
314178825Sdfr	  # Optimize common cases.
315178825Sdfr	  *[2367][2367]) mkdir_umask=$umask;;
316178825Sdfr	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
31755682Smarkm
318178825Sdfr	  *[0-7])
319178825Sdfr	    mkdir_umask=`expr $umask + 22 \
320178825Sdfr	      - $umask % 100 % 40 + $umask % 20 \
321178825Sdfr	      - $umask % 10 % 4 + $umask % 2
322178825Sdfr	    `;;
323178825Sdfr	  *) mkdir_umask=$umask,go-w;;
324178825Sdfr	esac
32555682Smarkm
326178825Sdfr	# With -d, create the new directory with the user-specified mode.
327178825Sdfr	# Otherwise, rely on $mkdir_umask.
328178825Sdfr	if test -n "$dir_arg"; then
329178825Sdfr	  mkdir_mode=-m$mode
330178825Sdfr	else
331178825Sdfr	  mkdir_mode=
332178825Sdfr	fi
33355682Smarkm
334178825Sdfr	posix_mkdir=false
335178825Sdfr	case $umask in
336178825Sdfr	  *[123567][0-7][0-7])
337178825Sdfr	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
338178825Sdfr	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
339178825Sdfr	    ;;
340178825Sdfr	  *)
341178825Sdfr	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
342178825Sdfr	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
34355682Smarkm
344178825Sdfr	    if (umask $mkdir_umask &&
345178825Sdfr		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
346178825Sdfr	    then
347178825Sdfr	      if test -z "$dir_arg" || {
348178825Sdfr		   # Check for POSIX incompatibilities with -m.
349178825Sdfr		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
350178825Sdfr		   # other-writeable bit of parent directory when it shouldn't.
351178825Sdfr		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
352178825Sdfr		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
353178825Sdfr		   case $ls_ld_tmpdir in
354178825Sdfr		     d????-?r-*) different_mode=700;;
355178825Sdfr		     d????-?--*) different_mode=755;;
356178825Sdfr		     *) false;;
357178825Sdfr		   esac &&
358178825Sdfr		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
359178825Sdfr		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
360178825Sdfr		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
361178825Sdfr		   }
362178825Sdfr		 }
363178825Sdfr	      then posix_mkdir=:
364178825Sdfr	      fi
365178825Sdfr	      rmdir "$tmpdir/d" "$tmpdir"
366178825Sdfr	    else
367178825Sdfr	      # Remove any dirs left behind by ancient mkdir implementations.
368178825Sdfr	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
369178825Sdfr	    fi
370178825Sdfr	    trap '' 0;;
371178825Sdfr	esac;;
372178825Sdfr    esac
373178825Sdfr
374178825Sdfr    if
375178825Sdfr      $posix_mkdir && (
376178825Sdfr	umask $mkdir_umask &&
377178825Sdfr	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
378178825Sdfr      )
379178825Sdfr    then :
380178825Sdfr    else
381178825Sdfr
382178825Sdfr      # The umask is ridiculous, or mkdir does not conform to POSIX,
383178825Sdfr      # or it failed possibly due to a race condition.  Create the
384178825Sdfr      # directory the slow way, step by step, checking for races as we go.
385178825Sdfr
386178825Sdfr      case $dstdir in
387233294Sstas	/*) prefix='/';;
388233294Sstas	-*) prefix='./';;
389233294Sstas	*)  prefix='';;
390178825Sdfr      esac
391178825Sdfr
392233294Sstas      eval "$initialize_posix_glob"
393178825Sdfr
394178825Sdfr      oIFS=$IFS
395178825Sdfr      IFS=/
396233294Sstas      $posix_glob set -f
397178825Sdfr      set fnord $dstdir
398142403Snectar      shift
399233294Sstas      $posix_glob set +f
400178825Sdfr      IFS=$oIFS
401178825Sdfr
402178825Sdfr      prefixes=
403178825Sdfr
404178825Sdfr      for d
405178825Sdfr      do
406178825Sdfr	test -z "$d" && continue
407178825Sdfr
408178825Sdfr	prefix=$prefix$d
409178825Sdfr	if test -d "$prefix"; then
410178825Sdfr	  prefixes=
411178825Sdfr	else
412178825Sdfr	  if $posix_mkdir; then
413178825Sdfr	    (umask=$mkdir_umask &&
414178825Sdfr	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
415178825Sdfr	    # Don't fail if two instances are running concurrently.
416178825Sdfr	    test -d "$prefix" || exit 1
417178825Sdfr	  else
418178825Sdfr	    case $prefix in
419178825Sdfr	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
420178825Sdfr	      *) qprefix=$prefix;;
421178825Sdfr	    esac
422178825Sdfr	    prefixes="$prefixes '$qprefix'"
423178825Sdfr	  fi
424178825Sdfr	fi
425178825Sdfr	prefix=$prefix/
426178825Sdfr      done
427178825Sdfr
428178825Sdfr      if test -n "$prefixes"; then
429178825Sdfr	# Don't fail if two instances are running concurrently.
430178825Sdfr	(umask $mkdir_umask &&
431178825Sdfr	 eval "\$doit_exec \$mkdirprog $prefixes") ||
432178825Sdfr	  test -d "$dstdir" || exit 1
433178825Sdfr	obsolete_mkdir_used=true
434142403Snectar      fi
435178825Sdfr    fi
436142403Snectar  fi
43755682Smarkm
438142403Snectar  if test -n "$dir_arg"; then
439178825Sdfr    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
440178825Sdfr    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
441178825Sdfr    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
442178825Sdfr      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
443142403Snectar  else
44455682Smarkm
445142403Snectar    # Make a couple of temp file names in the proper directory.
446142403Snectar    dsttmp=$dstdir/_inst.$$_
447142403Snectar    rmtmp=$dstdir/_rm.$$_
44855682Smarkm
449142403Snectar    # Trap to clean up those temp files at exit.
450178825Sdfr    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
451127808Snectar
452178825Sdfr    # Copy the file name to the temp name.
453178825Sdfr    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
454127808Snectar
455142403Snectar    # and set any options; do chmod last to preserve setuid bits.
456142403Snectar    #
457142403Snectar    # If any of these fail, we abort the whole thing.  If we want to
458142403Snectar    # ignore errors from any of these, just make sure not to ignore
459178825Sdfr    # errors from the above "$doit $cpprog $src $dsttmp" command.
460142403Snectar    #
461233294Sstas    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
462233294Sstas    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
463233294Sstas    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
464233294Sstas    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
46555682Smarkm
466233294Sstas    # If -C, don't bother to copy if it wouldn't change the file.
467233294Sstas    if $copy_on_change &&
468233294Sstas       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
469233294Sstas       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
47055682Smarkm
471233294Sstas       eval "$initialize_posix_glob" &&
472233294Sstas       $posix_glob set -f &&
473233294Sstas       set X $old && old=:$2:$4:$5:$6 &&
474233294Sstas       set X $new && new=:$2:$4:$5:$6 &&
475233294Sstas       $posix_glob set +f &&
476178825Sdfr
477233294Sstas       test "$old" = "$new" &&
478233294Sstas       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
479233294Sstas    then
480233294Sstas      rm -f "$dsttmp"
481233294Sstas    else
482233294Sstas      # Rename the file to the real destination.
483233294Sstas      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
484178825Sdfr
485233294Sstas      # The rename failed, perhaps because mv can't rename something else
486233294Sstas      # to itself, or perhaps because mv is so ancient that it does not
487233294Sstas      # support -f.
488233294Sstas      {
489233294Sstas	# Now remove or move aside any old file at destination location.
490233294Sstas	# We try this two ways since rm can't unlink itself on some
491233294Sstas	# systems and the destination file might be busy for other
492233294Sstas	# reasons.  In this case, the final cleanup might fail but the new
493233294Sstas	# file should still install successfully.
494233294Sstas	{
495233294Sstas	  test ! -f "$dst" ||
496233294Sstas	  $doit $rmcmd -f "$dst" 2>/dev/null ||
497233294Sstas	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
498233294Sstas	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
499233294Sstas	  } ||
500233294Sstas	  { echo "$0: cannot unlink or rename $dst" >&2
501233294Sstas	    (exit 1); exit 1
502233294Sstas	  }
503233294Sstas	} &&
504233294Sstas
505233294Sstas	# Now rename the file to the real destination.
506233294Sstas	$doit $mvcmd "$dsttmp" "$dst"
507233294Sstas      }
508233294Sstas    fi || exit 1
509233294Sstas
510178825Sdfr    trap '' 0
511178825Sdfr  fi
512142403Snectardone
51355682Smarkm
514142403Snectar# Local variables:
515142403Snectar# eval: (add-hook 'write-file-hooks 'time-stamp)
516142403Snectar# time-stamp-start: "scriptversion="
517142403Snectar# time-stamp-format: "%:y-%02m-%02d.%02H"
518233294Sstas# time-stamp-time-zone: "UTC"
519233294Sstas# time-stamp-end: "; # UTC"
520142403Snectar# End:
521