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
15 # set DOITPROG to echo to test this script
17 # Don't use :- since 4.3BSD and earlier shells don't like it.
20 # make sure ordinary users can access files installed by
21 # a restrictive root using umaks 0077
24 # put in absolute paths if you don't have them in your path; or use env. vars.
28 chmodprog="${CHMODPROG-chmod}"
29 chownprog="${CHOWNPROG-chown}"
30 chgrpprog="${CHGRPPROG-chgrp}"
31 stripprog="${STRIPPROG-strip}"
33 mkdirprog="${MKDIRPROG-mkdir}"
38 chmodcmd="$chmodprog 0755"
48 while [ x"$1" != x ]; do
58 -m) chmodcmd="$chmodprog $2"
63 -o) chowncmd="$chownprog $2"
68 -g) chgrpcmd="$chgrpprog $2"
73 -s) stripcmd="$stripprog"
77 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
81 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
89 # this colon is to work around a 386BSD /bin/sh bug
100 echo "install: no input file specified"
106 if [ x"$dir_arg" != x ]; then
117 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
118 # might cause directories to be created, which would be especially bad
119 # if $src (and thus $dsttmp) contains '*'.
121 if [ -f $src -o -d $src ]
125 echo "install: $src does not exist"
131 echo "install: no destination specified"
137 # If destination is a directory, append the input filename; if your system
138 # does not like double slashes in filenames, you may need to add some logic
142 dst="$dst"/`basename $src`
148 ## this sed command emulates the dirname command
149 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
151 # Make sure that the destination directory exists.
152 # this part is taken from Noah Friedman's mkinstalldirs script
154 # Skip lots of stat calls in the usual case.
155 if [ ! -d "$dstdir" ]; then
158 IFS="${IFS-${defaultIFS}}"
161 # Some sh's can't handle IFS=/ for some reason.
163 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
168 while [ $# -ne 0 ] ; do
169 pathcomp="${pathcomp}${1}"
172 if [ ! -d "${pathcomp}" ] ;
174 $mkdirprog "${pathcomp}"
179 pathcomp="${pathcomp}/"
183 if [ x"$dir_arg" != x ]
185 $doit $instcmd $dst &&
187 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
188 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
189 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
190 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
193 # If we're going to rename the final executable, determine the name now.
195 if [ x"$transformarg" = x ]
197 dstfile=`basename $dst`
199 dstfile=`basename $dst $transformbasename |
200 sed $transformarg`$transformbasename
203 # don't allow the sed command to completely eliminate the filename
205 if [ x"$dstfile" = x ]
207 dstfile=`basename $dst`
212 # Make a temp file name in the proper directory.
214 dsttmp=$dstdir/#inst.$$#
216 # Move or copy the file name to the temp name
218 $doit $instcmd $src $dsttmp &&
220 trap "rm -f ${dsttmp}" 0 &&
222 # and set any options; do chmod last to preserve setuid bits
224 # If any of these fail, we abort the whole thing. If we want to
225 # ignore errors from any of these, just make sure not to ignore
226 # errors from the above "$doit $instcmd $src $dsttmp" command.
228 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
229 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
230 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
231 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
233 # Now rename the file to the real destination.
235 $doit $rmcmd -f $dstdir/$dstfile &&
236 $doit $mvcmd $dsttmp $dstdir/$dstfile