3 # install - install a program, script, or datafile
4 # This comes from X11R5.
6 # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
8 # This script is compatible with the BSD install script, but was written
13 # set DOITPROG to echo to test this script
15 # Don't use :- since 4.3BSD and earlier shells don't like it.
19 # put in absolute paths if you don't have them in your path; or use env. vars.
23 chmodprog="${CHMODPROG-chmod}"
24 chownprog="${CHOWNPROG-chown}"
25 chgrpprog="${CHGRPPROG-chgrp}"
26 stripprog="${STRIPPROG-strip}"
28 mkdirprog="${MKDIRPROG-mkdir}"
33 chmodcmd="$chmodprog 0755"
43 while [ x"$1" != x ]; do
53 -m) chmodcmd="$chmodprog $2"
58 -o) chowncmd="$chownprog $2"
63 -g) chgrpcmd="$chgrpprog $2"
68 -s) stripcmd="$stripprog"
72 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
76 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
84 # this colon is to work around a 386BSD /bin/sh bug
95 echo "install: no input file specified"
101 if [ x"$dir_arg" != x ]; then
112 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
113 # might cause directories to be created, which would be especially bad
114 # if $src (and thus $dsttmp) contains '*'.
116 if [ -f $src -o -d $src ]
120 echo "install: $src does not exist"
126 echo "install: no destination specified"
132 # If destination is a directory, append the input filename; if your system
133 # does not like double slashes in filenames, you may need to add some logic
137 dst="$dst"/`basename $src`
143 ## this sed command emulates the dirname command
144 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
146 # Make sure that the destination directory exists.
147 # this part is taken from Noah Friedman's mkinstalldirs script
149 # Skip lots of stat calls in the usual case.
150 if [ ! -d "$dstdir" ]; then
153 IFS="${IFS-${defaultIFS}}"
156 # Some sh's can't handle IFS=/ for some reason.
158 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
163 while [ $# -ne 0 ] ; do
164 pathcomp="${pathcomp}${1}"
167 if [ ! -d "${pathcomp}" ] ;
169 $mkdirprog "${pathcomp}"
174 pathcomp="${pathcomp}/"
178 if [ x"$dir_arg" != x ]
180 $doit $instcmd $dst &&
182 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
183 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
184 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
185 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
188 # If we're going to rename the final executable, determine the name now.
190 if [ x"$transformarg" = x ]
192 dstfile=`basename $dst`
194 dstfile=`basename $dst $transformbasename |
195 sed $transformarg`$transformbasename
198 # don't allow the sed command to completely eliminate the filename
200 if [ x"$dstfile" = x ]
202 dstfile=`basename $dst`
207 # Make a temp file name in the proper directory.
209 dsttmp=$dstdir/#inst.$$#
211 # Move or copy the file name to the temp name
213 $doit $instcmd $src $dsttmp &&
215 trap "rm -f ${dsttmp}" 0 &&
217 # and set any options; do chmod last to preserve setuid bits
219 # If any of these fail, we abort the whole thing. If we want to
220 # ignore errors from any of these, just make sure not to ignore
221 # errors from the above "$doit $instcmd $src $dsttmp" command.
223 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
224 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
225 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
226 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
228 # Now rename the file to the real destination.
230 $doit $rmcmd -f $dstdir/$dstfile &&
231 $doit $mvcmd $dsttmp $dstdir/$dstfile