2
2
# install - install a program, script, or datafile
4
scriptversion=2004-04-01.17
4
scriptversion=2004-09-10.20
6
6
# This originates from X11R5 (mit/util/scripts/install.sh), which was
7
7
# later released in X11R6 (xc/config/util/install.sh) with the
74
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
73
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
75
74
or: $0 [OPTION]... SRCFILES... DIRECTORY
76
or: $0 -d DIRECTORIES...
75
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
76
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.
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.
83
-c copy source (using $cpprog) instead of moving (using $mvprog).
84
84
-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).
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.
90
91
--help display this help and exit.
91
92
--version display version info and exit.
132
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
133
-T) no_target_directory=true
136
137
--version) echo "$0 $scriptversion"; exit 0;;
138
139
*) # When -d is used, all remaining arguments are directories to create.
139
test -n "$dir_arg" && break
140
# When -t is used, the destination is already specified.
141
test -n "$dir_arg$dstarg" && break
140
142
# Otherwise, the last argument is the destination. Remove it from $@.
176
178
if test -d "$dst"; then
183
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
185
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
184
186
# might cause directories to be created, which would be especially bad
185
187
# if $src (and thus $dsttmp) contains '*'.
186
188
if test ! -f "$src" && test ! -d "$src"; then
202
204
# If destination is a directory, append the input filename; won't work
203
205
# if double slashes aren't ignored.
204
206
if test -d "$dst"; then
207
if test -n "$no_target_directory"; then
208
echo "$0: $dstarg: Is a directory" >&2
205
211
dst=$dst/`basename "$src"`
229
235
pathcomp=$pathcomp$1
231
237
if test ! -d "$pathcomp"; then
232
$mkdirprog "$pathcomp" || lasterr=$?
238
$mkdirprog "$pathcomp"
233
239
# mkdir can fail with a `File exist' error in case several
234
240
# install-sh are creating the directory concurrently. This
236
test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
242
test -d "$pathcomp" || exit
238
244
pathcomp=$pathcomp/
242
248
if test -n "$dir_arg"; then
243
$doit $instcmd "$dst" \
249
$doit $mkdircmd "$dst" \
244
250
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
245
251
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
246
252
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
247
253
&& { test -z "$chmodcmd" || $doit $chmodcmd "$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"`
256
dstfile=`basename "$dst"`
261
258
# Make a couple of temp file names in the proper directory.
262
259
dsttmp=$dstdir/_inst.$$_
263
260
rmtmp=$dstdir/_rm.$$_
265
262
# Trap to clean up those temp files at exit.
266
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
263
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
267
264
trap '(exit $?); exit' 1 2 13 15
269
# Move or copy the file name to the temp name
270
$doit $instcmd "$src" "$dsttmp" &&
266
# Copy the file name to the temp name.
267
$doit $cpprog "$src" "$dsttmp" &&
272
269
# and set any options; do chmod last to preserve setuid bits.
274
271
# If any of these fail, we abort the whole thing. If we want to
275
272
# ignore errors from any of these, just make sure not to ignore
276
# errors from the above "$doit $instcmd $src $dsttmp" command.
273
# errors from the above "$doit $cpprog $src $dsttmp" command.
278
275
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
279
276
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \