5 # install - install a program, script, or datafile
6 # This comes from X11R5; it is not part of GNU.
8 # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
10 # This script is compatible with the BSD install script, but was written
15 # set DOITPROG to echo to test this script
17 # Don't use :- since 4.3BSD and earlier shells don't like it.
21 # put in absolute paths if you don't have them in your path; or use env. vars.
25 chmodprog="${CHMODPROG-chmod}"
26 chownprog="${CHOWNPROG-chown}"
27 chgrpprog="${CHGRPPROG-chgrp}"
28 stripprog="${STRIPPROG-strip}"
30 mkdirprog="${MKDIRPROG-mkdir}"
35 chmodcmd="$chmodprog 0755"
45 while [ x"$1" != x ]; do
55 -m) chmodcmd="$chmodprog $2"
60 -o) chowncmd="$chownprog $2"
65 -g) chgrpcmd="$chgrpprog $2"
70 -s) stripcmd="$stripprog"
74 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
78 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
86 # this colon is to work around a 386BSD /bin/sh bug
97 echo "install: no input file specified"
103 if [ x"$dir_arg" != x ]; then
114 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
115 # might cause directories to be created, which would be especially bad
116 # if $src (and thus $dsttmp) contains '*'.
118 if [ -f $src -o -d $src ]
122 echo "install: $src does not exist"
128 echo "install: no destination specified"
134 # If destination is a directory, append the input filename; if your system
135 # does not like double slashes in filenames, you may need to add some logic
139 dst="$dst"/`basename $src`
145 ## this sed command emulates the dirname command
146 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
148 # Make sure that the destination directory exists.
149 # this part is taken from Noah Friedman's mkinstalldirs script
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}/"
177 if [ x"$dir_arg" != x ]
179 $doit $instcmd $dst &&
181 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
182 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
183 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
184 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
187 # If we're going to rename the final executable, determine the name now.
189 if [ x"$transformarg" = x ]
191 dstfile=`basename $dst`
193 dstfile=`basename $dst $transformbasename |
194 sed $transformarg`$transformbasename
197 # don't allow the sed command to completely eliminate the filename
199 if [ x"$dstfile" = x ]
201 dstfile=`basename $dst`
206 # Make a temp file name in the proper directory.
208 dsttmp=$dstdir/#inst.$$#
210 # Move or copy the file name to the temp name
212 $doit $instcmd $src $dsttmp &&
214 trap "rm -f ${dsttmp}" 0 &&
216 # and set any options; do chmod last to preserve setuid bits
218 # If any of these fail, we abort the whole thing. If we want to
219 # ignore errors from any of these, just make sure not to ignore
220 # errors from the above "$doit $instcmd $src $dsttmp" command.
222 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
223 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
224 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
225 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
227 # Now rename the file to the real destination.
229 $doit $rmcmd -f $dstdir/$dstfile &&
230 $doit $mvcmd $dsttmp $dstdir/$dstfile