install-sh revision fc89c0fb
1fc89c0fbSmrg#!/bin/sh
2fc89c0fbSmrg# install - install a program, script, or datafile
3fc89c0fbSmrg
4fc89c0fbSmrgscriptversion=2006-10-14.15
5fc89c0fbSmrg
6fc89c0fbSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was
7fc89c0fbSmrg# later released in X11R6 (xc/config/util/install.sh) with the
8fc89c0fbSmrg# following copyright and license.
9fc89c0fbSmrg#
10fc89c0fbSmrg# Copyright (C) 1994 X Consortium
11fc89c0fbSmrg#
12fc89c0fbSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy
13fc89c0fbSmrg# of this software and associated documentation files (the "Software"), to
14fc89c0fbSmrg# deal in the Software without restriction, including without limitation the
15fc89c0fbSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16fc89c0fbSmrg# sell copies of the Software, and to permit persons to whom the Software is
17fc89c0fbSmrg# furnished to do so, subject to the following conditions:
18fc89c0fbSmrg#
19fc89c0fbSmrg# The above copyright notice and this permission notice shall be included in
20fc89c0fbSmrg# all copies or substantial portions of the Software.
21fc89c0fbSmrg#
22fc89c0fbSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23fc89c0fbSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24fc89c0fbSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25fc89c0fbSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26fc89c0fbSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27fc89c0fbSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28fc89c0fbSmrg#
29fc89c0fbSmrg# Except as contained in this notice, the name of the X Consortium shall not
30fc89c0fbSmrg# be used in advertising or otherwise to promote the sale, use or other deal-
31fc89c0fbSmrg# ings in this Software without prior written authorization from the X Consor-
32fc89c0fbSmrg# tium.
33fc89c0fbSmrg#
34fc89c0fbSmrg#
35fc89c0fbSmrg# FSF changes to this file are in the public domain.
36fc89c0fbSmrg#
37fc89c0fbSmrg# Calling this script install-sh is preferred over install.sh, to prevent
38fc89c0fbSmrg# `make' implicit rules from creating a file called install from it
39fc89c0fbSmrg# when there is no Makefile.
40fc89c0fbSmrg#
41fc89c0fbSmrg# This script is compatible with the BSD install script, but was written
42fc89c0fbSmrg# from scratch.
43fc89c0fbSmrg
44fc89c0fbSmrgnl='
45fc89c0fbSmrg'
46fc89c0fbSmrgIFS=" ""	$nl"
47fc89c0fbSmrg
48fc89c0fbSmrg# set DOITPROG to echo to test this script
49fc89c0fbSmrg
50fc89c0fbSmrg# Don't use :- since 4.3BSD and earlier shells don't like it.
51fc89c0fbSmrgdoit="${DOITPROG-}"
52fc89c0fbSmrgif test -z "$doit"; then
53fc89c0fbSmrg  doit_exec=exec
54fc89c0fbSmrgelse
55fc89c0fbSmrg  doit_exec=$doit
56fc89c0fbSmrgfi
57fc89c0fbSmrg
58fc89c0fbSmrg# Put in absolute file names if you don't have them in your path;
59fc89c0fbSmrg# or use environment vars.
60fc89c0fbSmrg
61fc89c0fbSmrgmvprog="${MVPROG-mv}"
62fc89c0fbSmrgcpprog="${CPPROG-cp}"
63fc89c0fbSmrgchmodprog="${CHMODPROG-chmod}"
64fc89c0fbSmrgchownprog="${CHOWNPROG-chown}"
65fc89c0fbSmrgchgrpprog="${CHGRPPROG-chgrp}"
66fc89c0fbSmrgstripprog="${STRIPPROG-strip}"
67fc89c0fbSmrgrmprog="${RMPROG-rm}"
68fc89c0fbSmrgmkdirprog="${MKDIRPROG-mkdir}"
69fc89c0fbSmrg
70fc89c0fbSmrgposix_glob=
71fc89c0fbSmrgposix_mkdir=
72fc89c0fbSmrg
73fc89c0fbSmrg# Desired mode of installed file.
74fc89c0fbSmrgmode=0755
75fc89c0fbSmrg
76fc89c0fbSmrgchmodcmd=$chmodprog
77fc89c0fbSmrgchowncmd=
78fc89c0fbSmrgchgrpcmd=
79fc89c0fbSmrgstripcmd=
80fc89c0fbSmrgrmcmd="$rmprog -f"
81fc89c0fbSmrgmvcmd="$mvprog"
82fc89c0fbSmrgsrc=
83fc89c0fbSmrgdst=
84fc89c0fbSmrgdir_arg=
85fc89c0fbSmrgdstarg=
86fc89c0fbSmrgno_target_directory=
87fc89c0fbSmrg
88fc89c0fbSmrgusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
89fc89c0fbSmrg   or: $0 [OPTION]... SRCFILES... DIRECTORY
90fc89c0fbSmrg   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
91fc89c0fbSmrg   or: $0 [OPTION]... -d DIRECTORIES...
92fc89c0fbSmrg
93fc89c0fbSmrgIn the 1st form, copy SRCFILE to DSTFILE.
94fc89c0fbSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
95fc89c0fbSmrgIn the 4th, create DIRECTORIES.
96fc89c0fbSmrg
97fc89c0fbSmrgOptions:
98fc89c0fbSmrg-c         (ignored)
99fc89c0fbSmrg-d         create directories instead of installing files.
100fc89c0fbSmrg-g GROUP   $chgrpprog installed files to GROUP.
101fc89c0fbSmrg-m MODE    $chmodprog installed files to MODE.
102fc89c0fbSmrg-o USER    $chownprog installed files to USER.
103fc89c0fbSmrg-s         $stripprog installed files.
104fc89c0fbSmrg-t DIRECTORY  install into DIRECTORY.
105fc89c0fbSmrg-T         report an error if DSTFILE is a directory.
106fc89c0fbSmrg--help     display this help and exit.
107fc89c0fbSmrg--version  display version info and exit.
108fc89c0fbSmrg
109fc89c0fbSmrgEnvironment variables override the default commands:
110fc89c0fbSmrg  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
111fc89c0fbSmrg"
112fc89c0fbSmrg
113fc89c0fbSmrgwhile test $# -ne 0; do
114fc89c0fbSmrg  case $1 in
115fc89c0fbSmrg    -c) shift
116fc89c0fbSmrg        continue;;
117fc89c0fbSmrg
118fc89c0fbSmrg    -d) dir_arg=true
119fc89c0fbSmrg        shift
120fc89c0fbSmrg        continue;;
121fc89c0fbSmrg
122fc89c0fbSmrg    -g) chgrpcmd="$chgrpprog $2"
123fc89c0fbSmrg        shift
124fc89c0fbSmrg        shift
125fc89c0fbSmrg        continue;;
126fc89c0fbSmrg
127fc89c0fbSmrg    --help) echo "$usage"; exit $?;;
128fc89c0fbSmrg
129fc89c0fbSmrg    -m) mode=$2
130fc89c0fbSmrg        shift
131fc89c0fbSmrg        shift
132fc89c0fbSmrg	case $mode in
133fc89c0fbSmrg	  *' '* | *'	'* | *'
134fc89c0fbSmrg'*	  | *'*'* | *'?'* | *'['*)
135fc89c0fbSmrg	    echo "$0: invalid mode: $mode" >&2
136fc89c0fbSmrg	    exit 1;;
137fc89c0fbSmrg	esac
138fc89c0fbSmrg        continue;;
139fc89c0fbSmrg
140fc89c0fbSmrg    -o) chowncmd="$chownprog $2"
141fc89c0fbSmrg        shift
142fc89c0fbSmrg        shift
143fc89c0fbSmrg        continue;;
144fc89c0fbSmrg
145fc89c0fbSmrg    -s) stripcmd=$stripprog
146fc89c0fbSmrg        shift
147fc89c0fbSmrg        continue;;
148fc89c0fbSmrg
149fc89c0fbSmrg    -t) dstarg=$2
150fc89c0fbSmrg	shift
151fc89c0fbSmrg	shift
152fc89c0fbSmrg	continue;;
153fc89c0fbSmrg
154fc89c0fbSmrg    -T) no_target_directory=true
155fc89c0fbSmrg	shift
156fc89c0fbSmrg	continue;;
157fc89c0fbSmrg
158fc89c0fbSmrg    --version) echo "$0 $scriptversion"; exit $?;;
159fc89c0fbSmrg
160fc89c0fbSmrg    --)	shift
161fc89c0fbSmrg	break;;
162fc89c0fbSmrg
163fc89c0fbSmrg    -*)	echo "$0: invalid option: $1" >&2
164fc89c0fbSmrg	exit 1;;
165fc89c0fbSmrg
166fc89c0fbSmrg    *)  break;;
167fc89c0fbSmrg  esac
168fc89c0fbSmrgdone
169fc89c0fbSmrg
170fc89c0fbSmrgif test $# -ne 0 && test -z "$dir_arg$dstarg"; then
171fc89c0fbSmrg  # When -d is used, all remaining arguments are directories to create.
172fc89c0fbSmrg  # When -t is used, the destination is already specified.
173fc89c0fbSmrg  # Otherwise, the last argument is the destination.  Remove it from $@.
174fc89c0fbSmrg  for arg
175fc89c0fbSmrg  do
176fc89c0fbSmrg    if test -n "$dstarg"; then
177fc89c0fbSmrg      # $@ is not empty: it contains at least $arg.
178fc89c0fbSmrg      set fnord "$@" "$dstarg"
179fc89c0fbSmrg      shift # fnord
180fc89c0fbSmrg    fi
181fc89c0fbSmrg    shift # arg
182fc89c0fbSmrg    dstarg=$arg
183fc89c0fbSmrg  done
184fc89c0fbSmrgfi
185fc89c0fbSmrg
186fc89c0fbSmrgif test $# -eq 0; then
187fc89c0fbSmrg  if test -z "$dir_arg"; then
188fc89c0fbSmrg    echo "$0: no input file specified." >&2
189fc89c0fbSmrg    exit 1
190fc89c0fbSmrg  fi
191fc89c0fbSmrg  # It's OK to call `install-sh -d' without argument.
192fc89c0fbSmrg  # This can happen when creating conditional directories.
193fc89c0fbSmrg  exit 0
194fc89c0fbSmrgfi
195fc89c0fbSmrg
196fc89c0fbSmrgif test -z "$dir_arg"; then
197fc89c0fbSmrg  trap '(exit $?); exit' 1 2 13 15
198fc89c0fbSmrg
199fc89c0fbSmrg  # Set umask so as not to create temps with too-generous modes.
200fc89c0fbSmrg  # However, 'strip' requires both read and write access to temps.
201fc89c0fbSmrg  case $mode in
202fc89c0fbSmrg    # Optimize common cases.
203fc89c0fbSmrg    *644) cp_umask=133;;
204fc89c0fbSmrg    *755) cp_umask=22;;
205fc89c0fbSmrg
206fc89c0fbSmrg    *[0-7])
207fc89c0fbSmrg      if test -z "$stripcmd"; then
208fc89c0fbSmrg	u_plus_rw=
209fc89c0fbSmrg      else
210fc89c0fbSmrg	u_plus_rw='% 200'
211fc89c0fbSmrg      fi
212fc89c0fbSmrg      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
213fc89c0fbSmrg    *)
214fc89c0fbSmrg      if test -z "$stripcmd"; then
215fc89c0fbSmrg	u_plus_rw=
216fc89c0fbSmrg      else
217fc89c0fbSmrg	u_plus_rw=,u+rw
218fc89c0fbSmrg      fi
219fc89c0fbSmrg      cp_umask=$mode$u_plus_rw;;
220fc89c0fbSmrg  esac
221fc89c0fbSmrgfi
222fc89c0fbSmrg
223fc89c0fbSmrgfor src
224fc89c0fbSmrgdo
225fc89c0fbSmrg  # Protect names starting with `-'.
226fc89c0fbSmrg  case $src in
227fc89c0fbSmrg    -*) src=./$src ;;
228fc89c0fbSmrg  esac
229fc89c0fbSmrg
230fc89c0fbSmrg  if test -n "$dir_arg"; then
231fc89c0fbSmrg    dst=$src
232fc89c0fbSmrg    dstdir=$dst
233fc89c0fbSmrg    test -d "$dstdir"
234fc89c0fbSmrg    dstdir_status=$?
235fc89c0fbSmrg  else
236fc89c0fbSmrg
237fc89c0fbSmrg    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
238fc89c0fbSmrg    # might cause directories to be created, which would be especially bad
239fc89c0fbSmrg    # if $src (and thus $dsttmp) contains '*'.
240fc89c0fbSmrg    if test ! -f "$src" && test ! -d "$src"; then
241fc89c0fbSmrg      echo "$0: $src does not exist." >&2
242fc89c0fbSmrg      exit 1
243fc89c0fbSmrg    fi
244fc89c0fbSmrg
245fc89c0fbSmrg    if test -z "$dstarg"; then
246fc89c0fbSmrg      echo "$0: no destination specified." >&2
247fc89c0fbSmrg      exit 1
248fc89c0fbSmrg    fi
249fc89c0fbSmrg
250fc89c0fbSmrg    dst=$dstarg
251fc89c0fbSmrg    # Protect names starting with `-'.
252fc89c0fbSmrg    case $dst in
253fc89c0fbSmrg      -*) dst=./$dst ;;
254fc89c0fbSmrg    esac
255fc89c0fbSmrg
256fc89c0fbSmrg    # If destination is a directory, append the input filename; won't work
257fc89c0fbSmrg    # if double slashes aren't ignored.
258fc89c0fbSmrg    if test -d "$dst"; then
259fc89c0fbSmrg      if test -n "$no_target_directory"; then
260fc89c0fbSmrg	echo "$0: $dstarg: Is a directory" >&2
261fc89c0fbSmrg	exit 1
262fc89c0fbSmrg      fi
263fc89c0fbSmrg      dstdir=$dst
264fc89c0fbSmrg      dst=$dstdir/`basename "$src"`
265fc89c0fbSmrg      dstdir_status=0
266fc89c0fbSmrg    else
267fc89c0fbSmrg      # Prefer dirname, but fall back on a substitute if dirname fails.
268fc89c0fbSmrg      dstdir=`
269fc89c0fbSmrg	(dirname "$dst") 2>/dev/null ||
270fc89c0fbSmrg	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
271fc89c0fbSmrg	     X"$dst" : 'X\(//\)[^/]' \| \
272fc89c0fbSmrg	     X"$dst" : 'X\(//\)$' \| \
273fc89c0fbSmrg	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
274fc89c0fbSmrg	echo X"$dst" |
275fc89c0fbSmrg	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
276fc89c0fbSmrg		   s//\1/
277fc89c0fbSmrg		   q
278fc89c0fbSmrg		 }
279fc89c0fbSmrg		 /^X\(\/\/\)[^/].*/{
280fc89c0fbSmrg		   s//\1/
281fc89c0fbSmrg		   q
282fc89c0fbSmrg		 }
283fc89c0fbSmrg		 /^X\(\/\/\)$/{
284fc89c0fbSmrg		   s//\1/
285fc89c0fbSmrg		   q
286fc89c0fbSmrg		 }
287fc89c0fbSmrg		 /^X\(\/\).*/{
288fc89c0fbSmrg		   s//\1/
289fc89c0fbSmrg		   q
290fc89c0fbSmrg		 }
291fc89c0fbSmrg		 s/.*/./; q'
292fc89c0fbSmrg      `
293fc89c0fbSmrg
294fc89c0fbSmrg      test -d "$dstdir"
295fc89c0fbSmrg      dstdir_status=$?
296fc89c0fbSmrg    fi
297fc89c0fbSmrg  fi
298fc89c0fbSmrg
299fc89c0fbSmrg  obsolete_mkdir_used=false
300fc89c0fbSmrg
301fc89c0fbSmrg  if test $dstdir_status != 0; then
302fc89c0fbSmrg    case $posix_mkdir in
303fc89c0fbSmrg      '')
304fc89c0fbSmrg	# Create intermediate dirs using mode 755 as modified by the umask.
305fc89c0fbSmrg	# This is like FreeBSD 'install' as of 1997-10-28.
306fc89c0fbSmrg	umask=`umask`
307fc89c0fbSmrg	case $stripcmd.$umask in
308fc89c0fbSmrg	  # Optimize common cases.
309fc89c0fbSmrg	  *[2367][2367]) mkdir_umask=$umask;;
310fc89c0fbSmrg	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
311fc89c0fbSmrg
312fc89c0fbSmrg	  *[0-7])
313fc89c0fbSmrg	    mkdir_umask=`expr $umask + 22 \
314fc89c0fbSmrg	      - $umask % 100 % 40 + $umask % 20 \
315fc89c0fbSmrg	      - $umask % 10 % 4 + $umask % 2
316fc89c0fbSmrg	    `;;
317fc89c0fbSmrg	  *) mkdir_umask=$umask,go-w;;
318fc89c0fbSmrg	esac
319fc89c0fbSmrg
320fc89c0fbSmrg	# With -d, create the new directory with the user-specified mode.
321fc89c0fbSmrg	# Otherwise, rely on $mkdir_umask.
322fc89c0fbSmrg	if test -n "$dir_arg"; then
323fc89c0fbSmrg	  mkdir_mode=-m$mode
324fc89c0fbSmrg	else
325fc89c0fbSmrg	  mkdir_mode=
326fc89c0fbSmrg	fi
327fc89c0fbSmrg
328fc89c0fbSmrg	posix_mkdir=false
329fc89c0fbSmrg	case $umask in
330fc89c0fbSmrg	  *[123567][0-7][0-7])
331fc89c0fbSmrg	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
332fc89c0fbSmrg	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
333fc89c0fbSmrg	    ;;
334fc89c0fbSmrg	  *)
335fc89c0fbSmrg	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
336fc89c0fbSmrg	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
337fc89c0fbSmrg
338fc89c0fbSmrg	    if (umask $mkdir_umask &&
339fc89c0fbSmrg		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
340fc89c0fbSmrg	    then
341fc89c0fbSmrg	      if test -z "$dir_arg" || {
342fc89c0fbSmrg		   # Check for POSIX incompatibilities with -m.
343fc89c0fbSmrg		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
344fc89c0fbSmrg		   # other-writeable bit of parent directory when it shouldn't.
345fc89c0fbSmrg		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
346fc89c0fbSmrg		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
347fc89c0fbSmrg		   case $ls_ld_tmpdir in
348fc89c0fbSmrg		     d????-?r-*) different_mode=700;;
349fc89c0fbSmrg		     d????-?--*) different_mode=755;;
350fc89c0fbSmrg		     *) false;;
351fc89c0fbSmrg		   esac &&
352fc89c0fbSmrg		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
353fc89c0fbSmrg		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
354fc89c0fbSmrg		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
355fc89c0fbSmrg		   }
356fc89c0fbSmrg		 }
357fc89c0fbSmrg	      then posix_mkdir=:
358fc89c0fbSmrg	      fi
359fc89c0fbSmrg	      rmdir "$tmpdir/d" "$tmpdir"
360fc89c0fbSmrg	    else
361fc89c0fbSmrg	      # Remove any dirs left behind by ancient mkdir implementations.
362fc89c0fbSmrg	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
363fc89c0fbSmrg	    fi
364fc89c0fbSmrg	    trap '' 0;;
365fc89c0fbSmrg	esac;;
366fc89c0fbSmrg    esac
367fc89c0fbSmrg
368fc89c0fbSmrg    if
369fc89c0fbSmrg      $posix_mkdir && (
370fc89c0fbSmrg	umask $mkdir_umask &&
371fc89c0fbSmrg	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
372fc89c0fbSmrg      )
373fc89c0fbSmrg    then :
374fc89c0fbSmrg    else
375fc89c0fbSmrg
376fc89c0fbSmrg      # The umask is ridiculous, or mkdir does not conform to POSIX,
377fc89c0fbSmrg      # or it failed possibly due to a race condition.  Create the
378fc89c0fbSmrg      # directory the slow way, step by step, checking for races as we go.
379fc89c0fbSmrg
380fc89c0fbSmrg      case $dstdir in
381fc89c0fbSmrg	/*) prefix=/ ;;
382fc89c0fbSmrg	-*) prefix=./ ;;
383fc89c0fbSmrg	*)  prefix= ;;
384fc89c0fbSmrg      esac
385fc89c0fbSmrg
386fc89c0fbSmrg      case $posix_glob in
387fc89c0fbSmrg        '')
388fc89c0fbSmrg	  if (set -f) 2>/dev/null; then
389fc89c0fbSmrg	    posix_glob=true
390fc89c0fbSmrg	  else
391fc89c0fbSmrg	    posix_glob=false
392fc89c0fbSmrg	  fi ;;
393fc89c0fbSmrg      esac
394fc89c0fbSmrg
395fc89c0fbSmrg      oIFS=$IFS
396fc89c0fbSmrg      IFS=/
397fc89c0fbSmrg      $posix_glob && set -f
398fc89c0fbSmrg      set fnord $dstdir
399fc89c0fbSmrg      shift
400fc89c0fbSmrg      $posix_glob && set +f
401fc89c0fbSmrg      IFS=$oIFS
402fc89c0fbSmrg
403fc89c0fbSmrg      prefixes=
404fc89c0fbSmrg
405fc89c0fbSmrg      for d
406fc89c0fbSmrg      do
407fc89c0fbSmrg	test -z "$d" && continue
408fc89c0fbSmrg
409fc89c0fbSmrg	prefix=$prefix$d
410fc89c0fbSmrg	if test -d "$prefix"; then
411fc89c0fbSmrg	  prefixes=
412fc89c0fbSmrg	else
413fc89c0fbSmrg	  if $posix_mkdir; then
414fc89c0fbSmrg	    (umask=$mkdir_umask &&
415fc89c0fbSmrg	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
416fc89c0fbSmrg	    # Don't fail if two instances are running concurrently.
417fc89c0fbSmrg	    test -d "$prefix" || exit 1
418fc89c0fbSmrg	  else
419fc89c0fbSmrg	    case $prefix in
420fc89c0fbSmrg	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
421fc89c0fbSmrg	      *) qprefix=$prefix;;
422fc89c0fbSmrg	    esac
423fc89c0fbSmrg	    prefixes="$prefixes '$qprefix'"
424fc89c0fbSmrg	  fi
425fc89c0fbSmrg	fi
426fc89c0fbSmrg	prefix=$prefix/
427fc89c0fbSmrg      done
428fc89c0fbSmrg
429fc89c0fbSmrg      if test -n "$prefixes"; then
430fc89c0fbSmrg	# Don't fail if two instances are running concurrently.
431fc89c0fbSmrg	(umask $mkdir_umask &&
432fc89c0fbSmrg	 eval "\$doit_exec \$mkdirprog $prefixes") ||
433fc89c0fbSmrg	  test -d "$dstdir" || exit 1
434fc89c0fbSmrg	obsolete_mkdir_used=true
435fc89c0fbSmrg      fi
436fc89c0fbSmrg    fi
437fc89c0fbSmrg  fi
438fc89c0fbSmrg
439fc89c0fbSmrg  if test -n "$dir_arg"; then
440fc89c0fbSmrg    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
441fc89c0fbSmrg    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
442fc89c0fbSmrg    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
443fc89c0fbSmrg      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
444fc89c0fbSmrg  else
445fc89c0fbSmrg
446fc89c0fbSmrg    # Make a couple of temp file names in the proper directory.
447fc89c0fbSmrg    dsttmp=$dstdir/_inst.$$_
448fc89c0fbSmrg    rmtmp=$dstdir/_rm.$$_
449fc89c0fbSmrg
450fc89c0fbSmrg    # Trap to clean up those temp files at exit.
451fc89c0fbSmrg    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
452fc89c0fbSmrg
453fc89c0fbSmrg    # Copy the file name to the temp name.
454fc89c0fbSmrg    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
455fc89c0fbSmrg
456fc89c0fbSmrg    # and set any options; do chmod last to preserve setuid bits.
457fc89c0fbSmrg    #
458fc89c0fbSmrg    # If any of these fail, we abort the whole thing.  If we want to
459fc89c0fbSmrg    # ignore errors from any of these, just make sure not to ignore
460fc89c0fbSmrg    # errors from the above "$doit $cpprog $src $dsttmp" command.
461fc89c0fbSmrg    #
462fc89c0fbSmrg    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
463fc89c0fbSmrg      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
464fc89c0fbSmrg      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
465fc89c0fbSmrg      && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
466fc89c0fbSmrg
467fc89c0fbSmrg    # Now rename the file to the real destination.
468fc89c0fbSmrg    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
469fc89c0fbSmrg      || {
470fc89c0fbSmrg	   # The rename failed, perhaps because mv can't rename something else
471fc89c0fbSmrg	   # to itself, or perhaps because mv is so ancient that it does not
472fc89c0fbSmrg	   # support -f.
473fc89c0fbSmrg
474fc89c0fbSmrg	   # Now remove or move aside any old file at destination location.
475fc89c0fbSmrg	   # We try this two ways since rm can't unlink itself on some
476fc89c0fbSmrg	   # systems and the destination file might be busy for other
477fc89c0fbSmrg	   # reasons.  In this case, the final cleanup might fail but the new
478fc89c0fbSmrg	   # file should still install successfully.
479fc89c0fbSmrg	   {
480fc89c0fbSmrg	     if test -f "$dst"; then
481fc89c0fbSmrg	       $doit $rmcmd -f "$dst" 2>/dev/null \
482fc89c0fbSmrg	       || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
483fc89c0fbSmrg		     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
484fc89c0fbSmrg	       || {
485fc89c0fbSmrg		 echo "$0: cannot unlink or rename $dst" >&2
486fc89c0fbSmrg		 (exit 1); exit 1
487fc89c0fbSmrg	       }
488fc89c0fbSmrg	     else
489fc89c0fbSmrg	       :
490fc89c0fbSmrg	     fi
491fc89c0fbSmrg	   } &&
492fc89c0fbSmrg
493fc89c0fbSmrg	   # Now rename the file to the real destination.
494fc89c0fbSmrg	   $doit $mvcmd "$dsttmp" "$dst"
495fc89c0fbSmrg	 }
496fc89c0fbSmrg    } || exit 1
497fc89c0fbSmrg
498fc89c0fbSmrg    trap '' 0
499fc89c0fbSmrg  fi
500fc89c0fbSmrgdone
501fc89c0fbSmrg
502fc89c0fbSmrg# Local variables:
503fc89c0fbSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
504fc89c0fbSmrg# time-stamp-start: "scriptversion="
505fc89c0fbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
506fc89c0fbSmrg# time-stamp-end: "$"
507fc89c0fbSmrg# End:
508