2 # $Id: install-sh 26 2006-09-20 18:02:06Z spb $
4 # install - install a program, script, or datafile
6 # This originates from X11R5 (mit/util/scripts/install.sh), which was
7 # later released in X11R6 (xc/config/util/install.sh) with the
8 # following copyright and license.
10 # Copyright (C) 1994 X Consortium
12 # Permission is hereby granted, free of charge, to any person obtaining a copy
13 # of this software and associated documentation files (the "Software"), to
14 # deal in the Software without restriction, including without limitation the
15 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 # sell copies of the Software, and to permit persons to whom the Software is
17 # furnished to do so, subject to the following conditions:
19 # The above copyright notice and this permission notice shall be included in
20 # all copies or substantial portions of the Software.
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 # Except as contained in this notice, the name of the X Consortium shall not
30 # be used in advertising or otherwise to promote the sale, use or other deal-
31 # ings in this Software without prior written authorization from the X Consor-
35 # FSF changes to this file are in the public domain.
37 # Calling this script install-sh is preferred over install.sh, to prevent
38 # `make' implicit rules from creating a file called install from it
39 # when there is no Makefile.
41 # This script is compatible with the BSD install script, but was written
42 # from scratch. It can only install one file at a time, a restriction
43 # shared with many OS's install programs.
46 # set DOITPROG to echo to test this script
48 # Don't use :- since 4.3BSD and earlier shells don't like it.
52 # put in absolute paths if you don't have them in your path; or use env. vars.
56 chmodprog
="${CHMODPROG-chmod}"
57 chownprog
="${CHOWNPROG-chown}"
58 chgrpprog
="${CHGRPPROG-chgrp}"
59 stripprog
="${STRIPPROG-strip}"
61 mkdirprog
="${MKDIRPROG-mkdir}"
66 chmodcmd
="$chmodprog 0755"
76 while [ x
"$1" != x
]; do
86 -m) chmodcmd
="$chmodprog $2"
91 -o) chowncmd
="$chownprog $2"
96 -g) chgrpcmd
="$chgrpprog $2"
101 -s) stripcmd
="$stripprog"
105 -t=*) transformarg
=`echo $1 | sed 's/-t=//'`
109 -b=*) transformbasename
=`echo $1 | sed 's/-b=//'`
113 *) if [ x
"$src" = x
]
117 # this colon is to work around a 386BSD /bin/sh bug
128 echo "install: no input file specified"
134 if [ x
"$dir_arg" != x
]; then
146 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
147 # might cause directories to be created, which would be especially bad
148 # if $src (and thus $dsttmp) contains '*'.
150 if [ -f $src -o -d $src ]
154 echo "install: $src does not exist"
160 echo "install: no destination specified"
166 # If destination is a directory, append the input filename; if your system
167 # does not like double slashes in filenames, you may need to add some logic
171 dst
="$dst"/`basename $src`
177 ## this sed command emulates the dirname command
178 dstdir
=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
180 # Make sure that the destination directory exists.
181 # this part is taken from Noah Friedman's mkinstalldirs script
183 # Skip lots of stat calls in the usual case.
184 if [ ! -d "$dstdir" ]; then
187 IFS
="${IFS-${defaultIFS}}"
190 # Some sh's can't handle IFS=/ for some reason.
192 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
197 while [ $# -ne 0 ] ; do
198 pathcomp
="${pathcomp}${1}"
201 if [ ! -d "${pathcomp}" ] ;
203 $mkdirprog "${pathcomp}"
208 pathcomp
="${pathcomp}/"
212 if [ x
"$dir_arg" != x
]
214 $doit $instcmd $dst &&
216 if [ x
"$chowncmd" != x
]; then $doit $chowncmd $dst; else true
; fi &&
217 if [ x
"$chgrpcmd" != x
]; then $doit $chgrpcmd $dst; else true
; fi &&
218 if [ x
"$stripcmd" != x
]; then $doit $stripcmd $dst; else true
; fi &&
219 if [ x
"$chmodcmd" != x
]; then $doit $chmodcmd $dst; else true
; fi
222 # If we're going to rename the final executable, determine the name now.
224 if [ x
"$transformarg" = x
]
226 dstfile
=`basename $dst`
228 dstfile
=`basename $dst $transformbasename |
229 sed $transformarg`$transformbasename
232 # don't allow the sed command to completely eliminate the filename
234 if [ x
"$dstfile" = x
]
236 dstfile
=`basename $dst`
241 # Make a temp file name in the proper directory.
243 dsttmp
=$dstdir/#inst.$$#
245 # Move or copy the file name to the temp name
247 $doit $instcmd $src $dsttmp &&
249 trap "rm -f ${dsttmp}" 0 &&
251 # and set any options; do chmod last to preserve setuid bits
253 # If any of these fail, we abort the whole thing. If we want to
254 # ignore errors from any of these, just make sure not to ignore
255 # errors from the above "$doit $instcmd $src $dsttmp" command.
257 if [ x
"$chowncmd" != x
]; then $doit $chowncmd $dsttmp; else true
;fi &&
258 if [ x
"$chgrpcmd" != x
]; then $doit $chgrpcmd $dsttmp; else true
;fi &&
259 if [ x
"$stripcmd" != x
]; then $doit $stripcmd $dsttmp; else true
;fi &&
260 if [ x
"$chmodcmd" != x
]; then $doit $chmodcmd $dsttmp; else true
;fi &&
262 # Now rename the file to the real destination.
264 $doit $rmcmd -f $dstdir/$dstfile &&
265 $doit $mvcmd $dsttmp $dstdir/$dstfile