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