73
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
74
75
or: $0 [OPTION]... SRCFILES... DIRECTORY
75
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
76
or: $0 [OPTION]... -d DIRECTORIES...
76
or: $0 -d DIRECTORIES...
78
In the 1st form, copy SRCFILE to DSTFILE.
79
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
80
In the 4th, create DIRECTORIES.
78
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
79
In the second, create the directory path DIR.
83
-c copy source (using $cpprog) instead of moving (using $mvprog).
84
84
-d create directories instead of installing files.
85
-g GROUP $chgrpprog installed files to GROUP.
86
-m MODE $chmodprog installed files to MODE.
87
-o USER $chownprog installed files to USER.
88
-s $stripprog installed files.
89
-t DIRECTORY install into DIRECTORY.
90
-T report an error if DSTFILE is a directory.
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).
91
90
--help display this help and exit.
92
91
--version display version info and exit.
204
202
# If destination is a directory, append the input filename; won't work
205
203
# if double slashes aren't ignored.
206
204
if test -d "$dst"; then
207
if test -n "$no_target_directory"; then
208
echo "$0: $dstarg: Is a directory" >&2
211
205
dst=$dst/`basename "$src"`
215
209
# This sed command emulates the dirname command.
216
dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
210
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
218
212
# Make sure that the destination directory exists.
236
229
pathcomp=$pathcomp$1
238
231
if test ! -d "$pathcomp"; then
239
$mkdirprog "$pathcomp"
232
$mkdirprog "$pathcomp" || lasterr=$?
240
233
# mkdir can fail with a `File exist' error in case several
241
234
# install-sh are creating the directory concurrently. This
243
test -d "$pathcomp" || exit
236
test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
245
238
pathcomp=$pathcomp/
249
242
if test -n "$dir_arg"; then
250
$doit $mkdircmd "$dst" \
243
$doit $instcmd "$dst" \
251
244
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252
245
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253
246
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254
247
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
257
dstfile=`basename "$dst"`
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"`
259
261
# Make a couple of temp file names in the proper directory.
260
262
dsttmp=$dstdir/_inst.$$_
261
263
rmtmp=$dstdir/_rm.$$_
263
265
# Trap to clean up those temp files at exit.
264
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
266
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
265
267
trap '(exit $?); exit' 1 2 13 15
267
# Copy the file name to the temp name.
268
$doit $cpprog "$src" "$dsttmp" &&
269
# Move or copy the file name to the temp name
270
$doit $instcmd "$src" "$dsttmp" &&
270
272
# and set any options; do chmod last to preserve setuid bits.
272
274
# If any of these fail, we abort the whole thing. If we want to
273
275
# ignore errors from any of these, just make sure not to ignore
274
# errors from the above "$doit $cpprog $src $dsttmp" command.
276
# errors from the above "$doit $instcmd $src $dsttmp" command.
276
278
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277
279
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
278
280
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
279
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
281
301
# Now rename the file to the real destination.
282
{ $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
284
# The rename failed, perhaps because mv can't rename something else
285
# to itself, or perhaps because mv is so ancient that it does not
288
# Now remove or move aside any old file at destination location.
289
# We try this two ways since rm can't unlink itself on some
290
# systems and the destination file might be busy for other
291
# reasons. In this case, the final cleanup might fail but the new
292
# file should still install successfully.
294
if test -f "$dstdir/$dstfile"; then
295
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
296
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
298
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
306
# Now rename the file to the real destination.
307
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
310
fi || { (exit 1); exit 1; }
302
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
303
fi || { (exit 1); exit; }
313
306
# The final little trick to "correctly" pass the exit status to the exit trap.
318
311
# Local variables: