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