1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/install-sh Tue Nov 20 09:40:49 2007 +0000
1.6 +# install - install a program, script, or datafile
1.8 +# This originates from X11R5 (mit/util/scripts/install.sh), which was
1.9 +# later released in X11R6 (xc/config/util/install.sh) with the
1.10 +# following copyright and license.
1.12 +# Copyright (C) 1994 X Consortium
1.14 +# Permission is hereby granted, free of charge, to any person obtaining a copy
1.15 +# of this software and associated documentation files (the "Software"), to
1.16 +# deal in the Software without restriction, including without limitation the
1.17 +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1.18 +# sell copies of the Software, and to permit persons to whom the Software is
1.19 +# furnished to do so, subject to the following conditions:
1.21 +# The above copyright notice and this permission notice shall be included in
1.22 +# all copies or substantial portions of the Software.
1.24 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1.25 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1.26 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1.27 +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1.28 +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
1.29 +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.31 +# Except as contained in this notice, the name of the X Consortium shall not
1.32 +# be used in advertising or otherwise to promote the sale, use or other deal-
1.33 +# ings in this Software without prior written authorization from the X Consor-
1.37 +# FSF changes to this file are in the public domain.
1.39 +# Calling this script install-sh is preferred over install.sh, to prevent
1.40 +# `make' implicit rules from creating a file called install from it
1.41 +# when there is no Makefile.
1.43 +# This script is compatible with the BSD install script, but was written
1.44 +# from scratch. It can only install one file at a time, a restriction
1.45 +# shared with many OS's install programs.
1.48 +# set DOITPROG to echo to test this script
1.50 +# Don't use :- since 4.3BSD and earlier shells don't like it.
1.51 +doit="${DOITPROG-}"
1.54 +# put in absolute paths if you don't have them in your path; or use env. vars.
1.56 +mvprog="${MVPROG-mv}"
1.57 +cpprog="${CPPROG-cp}"
1.58 +chmodprog="${CHMODPROG-chmod}"
1.59 +chownprog="${CHOWNPROG-chown}"
1.60 +chgrpprog="${CHGRPPROG-chgrp}"
1.61 +stripprog="${STRIPPROG-strip}"
1.62 +rmprog="${RMPROG-rm}"
1.63 +mkdirprog="${MKDIRPROG-mkdir}"
1.65 +transformbasename=""
1.68 +chmodcmd="$chmodprog 0755"
1.78 +while [ x"$1" != x ]; do
1.80 + -c) instcmd=$cpprog
1.88 + -m) chmodcmd="$chmodprog $2"
1.93 + -o) chowncmd="$chownprog $2"
1.98 + -g) chgrpcmd="$chgrpprog $2"
1.103 + -s) stripcmd=$stripprog
1.107 + -t=*) transformarg=`echo $1 | sed 's/-t=//'`
1.111 + -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
1.115 + *) if [ x"$src" = x ]
1.119 + # this colon is to work around a 386BSD /bin/sh bug
1.128 +if [ x"$src" = x ]
1.130 + echo "$0: no input file specified" >&2
1.136 +if [ x"$dir_arg" != x ]; then
1.140 + if [ -d "$dst" ]; then
1.144 + instcmd=$mkdirprog
1.148 +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
1.149 +# might cause directories to be created, which would be especially bad
1.150 +# if $src (and thus $dsttmp) contains '*'.
1.152 + if [ -f "$src" ] || [ -d "$src" ]
1.156 + echo "$0: $src does not exist" >&2
1.160 + if [ x"$dst" = x ]
1.162 + echo "$0: no destination specified" >&2
1.168 +# If destination is a directory, append the input filename; if your system
1.169 +# does not like double slashes in filenames, you may need to add some logic
1.173 + dst=$dst/`basename "$src"`
1.179 +## this sed command emulates the dirname command
1.180 +dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
1.182 +# Make sure that the destination directory exists.
1.183 +# this part is taken from Noah Friedman's mkinstalldirs script
1.185 +# Skip lots of stat calls in the usual case.
1.186 +if [ ! -d "$dstdir" ]; then
1.189 +IFS="${IFS-$defaultIFS}"
1.192 +# Some sh's can't handle IFS=/ for some reason.
1.194 +set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
1.199 +while [ $# -ne 0 ] ; do
1.200 + pathcomp=$pathcomp$1
1.203 + if [ ! -d "$pathcomp" ] ;
1.205 + $mkdirprog "$pathcomp"
1.210 + pathcomp=$pathcomp/
1.214 +if [ x"$dir_arg" != x ]
1.216 + $doit $instcmd "$dst" &&
1.218 + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
1.219 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
1.220 + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
1.221 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
1.224 +# If we're going to rename the final executable, determine the name now.
1.226 + if [ x"$transformarg" = x ]
1.228 + dstfile=`basename "$dst"`
1.230 + dstfile=`basename "$dst" $transformbasename |
1.231 + sed $transformarg`$transformbasename
1.234 +# don't allow the sed command to completely eliminate the filename
1.236 + if [ x"$dstfile" = x ]
1.238 + dstfile=`basename "$dst"`
1.243 +# Make a couple of temp file names in the proper directory.
1.245 + dsttmp=$dstdir/_inst.$$_
1.246 + rmtmp=$dstdir/_rm.$$_
1.248 +# Trap to clean up temp files at exit.
1.250 + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
1.251 + trap '(exit $?); exit' 1 2 13 15
1.253 +# Move or copy the file name to the temp name
1.255 + $doit $instcmd "$src" "$dsttmp" &&
1.257 +# and set any options; do chmod last to preserve setuid bits
1.259 +# If any of these fail, we abort the whole thing. If we want to
1.260 +# ignore errors from any of these, just make sure not to ignore
1.261 +# errors from the above "$doit $instcmd $src $dsttmp" command.
1.263 + if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
1.264 + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
1.265 + if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
1.266 + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
1.268 +# Now remove or move aside any old file at destination location. We try this
1.269 +# two ways since rm can't unlink itself on some systems and the destination
1.270 +# file might be busy for other reasons. In this case, the final cleanup
1.271 +# might fail but the new file should still install successfully.
1.274 + if [ -f "$dstdir/$dstfile" ]
1.276 + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
1.277 + $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
1.279 + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
1.287 +# Now rename the file to the real destination.
1.289 + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
1.293 +# The final little trick to "correctly" pass the exit status to the exit trap.