74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
87
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
75
88
or: $0 [OPTION]... SRCFILES... DIRECTORY
76
or: $0 -d DIRECTORIES...
89
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
90
or: $0 [OPTION]... -d DIRECTORIES...
78
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
79
In the second, create the directory path DIR.
92
In the 1st form, copy SRCFILE to DSTFILE.
93
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
94
In the 4th, create DIRECTORIES.
83
-c copy source (using $cpprog) instead of moving (using $mvprog).
84
98
-d create directories instead of installing files.
85
-g GROUP $chgrp installed files to GROUP.
86
-m MODE $chmod installed files to MODE.
87
-o USER $chown installed files to USER.
88
-s strip installed files (using $stripprog).
99
-g GROUP $chgrpprog installed files to GROUP.
100
-m MODE $chmodprog installed files to MODE.
101
-o USER $chownprog installed files to USER.
102
-s $stripprog installed files.
103
-t DIRECTORY install into DIRECTORY.
104
-T report an error if DSTFILE is a directory.
90
105
--help display this help and exit.
91
106
--version display version info and exit.
202
216
# If destination is a directory, append the input filename; won't work
203
217
# if double slashes aren't ignored.
204
218
if test -d "$dst"; then
205
dst=$dst/`basename "$src"`
219
if test -n "$no_target_directory"; then
220
echo "$0: $dstarg: Is a directory" >&2
224
dst=$dstdir/`basename "$src"`
227
# Prefer dirname, but fall back on a substitute if dirname fails.
229
(dirname "$dst") 2>/dev/null ||
230
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
231
X"$dst" : 'X\(//\)[^/]' \| \
232
X"$dst" : 'X\(//\)$' \| \
233
X"$dst" : 'X\(/\)' \| \
234
. : '\(.\)' 2>/dev/null ||
236
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
237
/^X\(\/\/\)[^/].*/{ s//\1/; q; }
238
/^X\(\/\/\)$/{ s//\1/; q; }
239
/^X\(\/\).*/{ s//\1/; q; }
209
# This sed command emulates the dirname command.
210
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
212
# Make sure that the destination directory exists.
214
# Skip lots of stat calls in the usual case.
215
if test ! -d "$dstdir"; then
218
IFS="${IFS-$defaultIFS}"
221
# Some sh's can't handle IFS=/ for some reason.
223
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
228
while test $# -ne 0 ; do
248
obsolete_mkdir_used=false
250
if test $dstdir_status != 0; then
254
if $mkdirprog -m $test_mode -p -- / >/dev/null 2>&1; then
257
# Remove any dirs left behind by ancient mkdir implementations.
258
rmdir ./-m "$test_mode" ./-p ./-- 2>/dev/null
265
# With -d, create the new directory with the user-specified mode.
266
# Otherwise, create it using the same intermediate mode that
267
# mkdir -p would use when creating intermediate directories.
268
# POSIX says that this mode is "$(umask -S),u+wx", so use that
271
if test -n "$dir_arg"; then
274
case $intermediate_mode in
276
if umask_S=`(umask -S) 2>/dev/null`; then
277
intermediate_mode=$umask_S,u+wx
279
intermediate_mode=$test_mode
282
mkdir_mode=$intermediate_mode
285
$mkdirprog -m "$mkdir_mode" -p -- "$dstdir"
290
# mkdir does not conform to POSIX, or it failed possibly due to
291
# a race condition. Create the directory the slow way, step by
292
# step, checking for races as we go.
302
if (set -f) 2>/dev/null; then
311
$posix_glob && set -f
231
if test ! -d "$pathcomp"; then
232
$mkdirprog "$pathcomp" || lasterr=$?
233
# mkdir can fail with a `File exist' error in case several
234
# install-sh are creating the directory concurrently. This
236
test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
314
$posix_glob && set +f
319
test "x$d" = x && continue
322
if test ! -d "$pathcomp"; then
323
$mkdirprog "$pathcomp"
324
# Don't fail if two instances are running concurrently.
325
test -d "$pathcomp" || exit 1
329
obsolete_mkdir_used=true
242
333
if test -n "$dir_arg"; then
243
$doit $instcmd "$dst" \
244
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
245
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
246
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
247
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
334
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
335
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
336
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
337
test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dst"; } || exit 1
250
# If we're going to rename the final executable, determine the name now.
251
if test -z "$transformarg"; then
252
dstfile=`basename "$dst"`
254
dstfile=`basename "$dst" $transformbasename \
255
| sed $transformarg`$transformbasename
258
# don't allow the sed command to completely eliminate the filename.
259
test -z "$dstfile" && dstfile=`basename "$dst"`
261
340
# Make a couple of temp file names in the proper directory.
262
341
dsttmp=$dstdir/_inst.$$_
263
342
rmtmp=$dstdir/_rm.$$_
265
344
# Trap to clean up those temp files at exit.
266
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
267
trap '(exit $?); exit' 1 2 13 15
345
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
269
# Move or copy the file name to the temp name
270
$doit $instcmd "$src" "$dsttmp" &&
347
# Copy the file name to the temp name.
348
$doit $cpprog "$src" "$dsttmp" &&
272
350
# and set any options; do chmod last to preserve setuid bits.
274
352
# If any of these fail, we abort the whole thing. If we want to
275
353
# ignore errors from any of these, just make sure not to ignore
276
# errors from the above "$doit $instcmd $src $dsttmp" command.
354
# errors from the above "$doit $cpprog $src $dsttmp" command.
278
356
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
279
357
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
280
358
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
281
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
283
# Now remove or move aside any old file at destination location. We
284
# try this two ways since rm can't unlink itself on some systems and
285
# the destination file might be busy for other reasons. In this case,
286
# the final cleanup might fail but the new file should still install
289
if test -f "$dstdir/$dstfile"; then
290
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
291
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
293
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
359
&& { test -z "$chmodcmd" || $doit $chmodcmd "$mode" "$dsttmp"; } &&
301
361
# Now rename the file to the real destination.
302
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
303
fi || { (exit 1); exit; }
362
{ $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
364
# The rename failed, perhaps because mv can't rename something else
365
# to itself, or perhaps because mv is so ancient that it does not
368
# Now remove or move aside any old file at destination location.
369
# We try this two ways since rm can't unlink itself on some
370
# systems and the destination file might be busy for other
371
# reasons. In this case, the final cleanup might fail but the new
372
# file should still install successfully.
374
if test -f "$dst"; then
375
$doit $rmcmd -f "$dst" 2>/dev/null \
376
|| { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
377
&& { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
379
echo "$0: cannot unlink or rename $dst" >&2
387
# Now rename the file to the real destination.
388
$doit $mvcmd "$dsttmp" "$dst"
306
# The final little trick to "correctly" pass the exit status to the exit trap.
311
396
# Local variables:
312
397
# eval: (add-hook 'write-file-hooks 'time-stamp)
313
398
# time-stamp-start: "scriptversion="