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