3 # install - install a program, script, or datafile
4 # This comes from X11R5.
6 # Calling this script install-sh is preferred over install.sh, to prevent
7 # `make' implicit rules from creating a file called install from it
8 # when there is no Makefile.
10 # This script is compatible with the BSD install script, but was written
16 # set DOITPROG to echo to test this script
18 # Don't use :- since 4.3BSD and earlier shells don't like it.
22 # put in absolute paths if you don't have them in your path; or use env. vars.
26 chmodprog="${CHMODPROG-chmod}"
27 chownprog="${CHOWNPROG-chown}"
28 chgrpprog="${CHGRPPROG-chgrp}"
29 stripprog="${STRIPPROG-strip}"
31 mkdirprog="${MKDIRPROG-mkdir}"
36 chmodcmd="$chmodprog 0755"
46 while [ x"$1" != x ]; do
56 -m) chmodcmd="$chmodprog $2"
61 -o) chowncmd="$chownprog $2"
66 -g) chgrpcmd="$chgrpprog $2"
71 -s) stripcmd="$stripprog"
75 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
79 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
87 # this colon is to work around a 386BSD /bin/sh bug
98 echo "install: no input file specified"
104 if [ x"$dir_arg" != x ]; then
115 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
116 # might cause directories to be created, which would be especially bad
117 # if $src (and thus $dsttmp) contains '*'.
119 if [ -f $src -o -d $src ]
123 echo "install: $src does not exist"
129 echo "install: no destination specified"
135 # If destination is a directory, append the input filename; if your system
136 # does not like double slashes in filenames, you may need to add some logic
140 dst="$dst"/`basename $src`
146 ## this sed command emulates the dirname command
147 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
149 # Make sure that the destination directory exists.
150 # this part is taken from Noah Friedman's mkinstalldirs script
152 # Skip lots of stat calls in the usual case.
153 if [ ! -d "$dstdir" ]; then
156 IFS="${IFS-${defaultIFS}}"
159 # Some sh's can't handle IFS=/ for some reason.
161 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
166 while [ $# -ne 0 ] ; do
167 pathcomp="${pathcomp}${1}"
170 if [ ! -d "${pathcomp}" ] ;
172 $mkdirprog "${pathcomp}"
177 pathcomp="${pathcomp}/"
181 if [ x"$dir_arg" != x ]
183 $doit $instcmd $dst &&
185 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
186 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
187 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
188 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
191 # If we're going to rename the final executable, determine the name now.
193 if [ x"$transformarg" = x ]
195 dstfile=`basename $dst`
197 dstfile=`basename $dst $transformbasename |
198 sed $transformarg`$transformbasename
201 # don't allow the sed command to completely eliminate the filename
203 if [ x"$dstfile" = x ]
205 dstfile=`basename $dst`
210 # Make a temp file name in the proper directory.
212 dsttmp=$dstdir/#inst.$$#
214 # Move or copy the file name to the temp name
216 $doit $instcmd $src $dsttmp &&
218 trap "rm -f ${dsttmp}" 0 &&
220 # and set any options; do chmod last to preserve setuid bits
222 # If any of these fail, we abort the whole thing. If we want to
223 # ignore errors from any of these, just make sure not to ignore
224 # errors from the above "$doit $instcmd $src $dsttmp" command.
226 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
227 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
228 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
229 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
231 # Now rename the file to the real destination.
233 $doit $rmcmd -f $dstdir/$dstfile &&
234 $doit $mvcmd $dsttmp $dstdir/$dstfile