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
14 # set DOITPROG to echo to test this script
16 # Don't use :- since 4.3BSD and earlier shells don't like it.
20 # put in absolute paths if you don't have them in your path; or use env. vars.
24 chmodprog="${CHMODPROG-chmod}"
25 chownprog="${CHOWNPROG-chown}"
26 chgrpprog="${CHGRPPROG-chgrp}"
27 stripprog="${STRIPPROG-strip}"
29 mkdirprog="${MKDIRPROG-mkdir}"
34 chmodcmd="$chmodprog 0755"
44 while [ x"$1" != x ]; do
54 -m) chmodcmd="$chmodprog $2"
59 -o) chowncmd="$chownprog $2"
64 -g) chgrpcmd="$chgrpprog $2"
69 -s) stripcmd="$stripprog"
73 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
77 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
85 # this colon is to work around a 386BSD /bin/sh bug
96 echo "install: no input file specified"
102 if [ x"$dir_arg" != x ]; then
113 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
114 # might cause directories to be created, which would be especially bad
115 # if $src (and thus $dsttmp) contains '*'.
117 if [ -f $src -o -d $src ]
121 echo "install: $src does not exist"
127 echo "install: no destination specified"
133 # If destination is a directory, append the input filename; if your system
134 # does not like double slashes in filenames, you may need to add some logic
138 dst="$dst"/`basename $src`
144 ## this sed command emulates the dirname command
145 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
147 # Make sure that the destination directory exists.
148 # this part is taken from Noah Friedman's mkinstalldirs script
150 # Skip lots of stat calls in the usual case.
151 if [ ! -d "$dstdir" ]; then
154 IFS="${IFS-${defaultIFS}}"
157 # Some sh's can't handle IFS=/ for some reason.
159 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
164 while [ $# -ne 0 ] ; do
165 pathcomp="${pathcomp}${1}"
168 if [ ! -d "${pathcomp}" ] ;
170 $mkdirprog "${pathcomp}"
175 pathcomp="${pathcomp}/"
179 if [ x"$dir_arg" != x ]
181 $doit $instcmd $dst &&
183 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
184 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
185 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
186 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
189 # If we're going to rename the final executable, determine the name now.
191 if [ x"$transformarg" = x ]
193 dstfile=`basename $dst`
195 dstfile=`basename $dst $transformbasename |
196 sed $transformarg`$transformbasename
199 # don't allow the sed command to completely eliminate the filename
201 if [ x"$dstfile" = x ]
203 dstfile=`basename $dst`
208 # Make a temp file name in the proper directory.
210 dsttmp=$dstdir/#inst.$$#
212 # Move or copy the file name to the temp name
214 $doit $instcmd $src $dsttmp &&
216 trap "rm -f ${dsttmp}" 0 &&
218 # and set any options; do chmod last to preserve setuid bits
220 # If any of these fail, we abort the whole thing. If we want to
221 # ignore errors from any of these, just make sure not to ignore
222 # errors from the above "$doit $instcmd $src $dsttmp" command.
224 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
225 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
226 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
227 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
229 # Now rename the file to the real destination.
231 $doit $rmcmd -f $dstdir/$dstfile &&
232 $doit $mvcmd $dsttmp $dstdir/$dstfile