Chris@39: #!/bin/sh Chris@39: # Chris@39: # install - install a program, script, or datafile Chris@39: # This comes from X11R5 (mit/util/scripts/install.sh). Chris@39: # Chris@39: # Copyright 1991 by the Massachusetts Institute of Technology Chris@39: # Chris@39: # Permission to use, copy, modify, distribute, and sell this software and its Chris@39: # documentation for any purpose is hereby granted without fee, provided that Chris@39: # the above copyright notice appear in all copies and that both that Chris@39: # copyright notice and this permission notice appear in supporting Chris@39: # documentation, and that the name of M.I.T. not be used in advertising or Chris@39: # publicity pertaining to distribution of the software without specific, Chris@39: # written prior permission. M.I.T. makes no representations about the Chris@39: # suitability of this software for any purpose. It is provided "as is" Chris@39: # without express or implied warranty. Chris@39: # Chris@39: # Calling this script install-sh is preferred over install.sh, to prevent Chris@39: # `make' implicit rules from creating a file called install from it Chris@39: # when there is no Makefile. Chris@39: # Chris@39: # This script is compatible with the BSD install script, but was written Chris@39: # from scratch. It can only install one file at a time, a restriction Chris@39: # shared with many OS's install programs. Chris@39: Chris@39: Chris@39: # set DOITPROG to echo to test this script Chris@39: Chris@39: # Don't use :- since 4.3BSD and earlier shells don't like it. Chris@39: doit="${DOITPROG-}" Chris@39: Chris@39: Chris@39: # put in absolute paths if you don't have them in your path; or use env. vars. Chris@39: Chris@39: mvprog="${MVPROG-mv}" Chris@39: cpprog="${CPPROG-cp}" Chris@39: chmodprog="${CHMODPROG-chmod}" Chris@39: chownprog="${CHOWNPROG-chown}" Chris@39: chgrpprog="${CHGRPPROG-chgrp}" Chris@39: stripprog="${STRIPPROG-strip}" Chris@39: rmprog="${RMPROG-rm}" Chris@39: mkdirprog="${MKDIRPROG-mkdir}" Chris@39: Chris@39: transformbasename="" Chris@39: transform_arg="" Chris@39: instcmd="$mvprog" Chris@39: chmodcmd="$chmodprog 0755" Chris@39: chowncmd="" Chris@39: chgrpcmd="" Chris@39: stripcmd="" Chris@39: rmcmd="$rmprog -f" Chris@39: mvcmd="$mvprog" Chris@39: src="" Chris@39: dst="" Chris@39: dir_arg="" Chris@39: Chris@39: while [ x"$1" != x ]; do Chris@39: case $1 in Chris@39: -c) instcmd="$cpprog" Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -d) dir_arg=true Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -m) chmodcmd="$chmodprog $2" Chris@39: shift Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -o) chowncmd="$chownprog $2" Chris@39: shift Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -g) chgrpcmd="$chgrpprog $2" Chris@39: shift Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -s) stripcmd="$stripprog" Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -t=*) transformarg=`echo $1 | sed 's/-t=//'` Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: -b=*) transformbasename=`echo $1 | sed 's/-b=//'` Chris@39: shift Chris@39: continue;; Chris@39: Chris@39: *) if [ x"$src" = x ] Chris@39: then Chris@39: src=$1 Chris@39: else Chris@39: # this colon is to work around a 386BSD /bin/sh bug Chris@39: : Chris@39: dst=$1 Chris@39: fi Chris@39: shift Chris@39: continue;; Chris@39: esac Chris@39: done Chris@39: Chris@39: if [ x"$src" = x ] Chris@39: then Chris@39: echo "install: no input file specified" Chris@39: exit 1 Chris@39: else Chris@39: true Chris@39: fi Chris@39: Chris@39: if [ x"$dir_arg" != x ]; then Chris@39: dst=$src Chris@39: src="" Chris@39: Chris@39: if [ -d $dst ]; then Chris@39: instcmd=: Chris@39: chmodcmd="" Chris@39: else Chris@39: instcmd=mkdir Chris@39: fi Chris@39: else Chris@39: Chris@39: # Waiting for this to be detected by the "$instcmd $src $dsttmp" command Chris@39: # might cause directories to be created, which would be especially bad Chris@39: # if $src (and thus $dsttmp) contains '*'. Chris@39: Chris@39: if [ -f $src -o -d $src ] Chris@39: then Chris@39: true Chris@39: else Chris@39: echo "install: $src does not exist" Chris@39: exit 1 Chris@39: fi Chris@39: Chris@39: if [ x"$dst" = x ] Chris@39: then Chris@39: echo "install: no destination specified" Chris@39: exit 1 Chris@39: else Chris@39: true Chris@39: fi Chris@39: Chris@39: # If destination is a directory, append the input filename; if your system Chris@39: # does not like double slashes in filenames, you may need to add some logic Chris@39: Chris@39: if [ -d $dst ] Chris@39: then Chris@39: dst="$dst"/`basename $src` Chris@39: else Chris@39: true Chris@39: fi Chris@39: fi Chris@39: Chris@39: ## this sed command emulates the dirname command Chris@39: dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` Chris@39: Chris@39: # Make sure that the destination directory exists. Chris@39: # this part is taken from Noah Friedman's mkinstalldirs script Chris@39: Chris@39: # Skip lots of stat calls in the usual case. Chris@39: if [ ! -d "$dstdir" ]; then Chris@39: defaultIFS=' Chris@39: ' Chris@39: IFS="${IFS-${defaultIFS}}" Chris@39: Chris@39: oIFS="${IFS}" Chris@39: # Some sh's can't handle IFS=/ for some reason. Chris@39: IFS='%' Chris@39: set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` Chris@39: IFS="${oIFS}" Chris@39: Chris@39: pathcomp='' Chris@39: Chris@39: while [ $# -ne 0 ] ; do Chris@39: pathcomp="${pathcomp}${1}" Chris@39: shift Chris@39: Chris@39: if [ ! -d "${pathcomp}" ] ; Chris@39: then Chris@39: $mkdirprog "${pathcomp}" Chris@39: else Chris@39: true Chris@39: fi Chris@39: Chris@39: pathcomp="${pathcomp}/" Chris@39: done Chris@39: fi Chris@39: Chris@39: if [ x"$dir_arg" != x ] Chris@39: then Chris@39: $doit $instcmd $dst && Chris@39: Chris@39: if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && Chris@39: if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && Chris@39: if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && Chris@39: if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi Chris@39: else Chris@39: Chris@39: # If we're going to rename the final executable, determine the name now. Chris@39: Chris@39: if [ x"$transformarg" = x ] Chris@39: then Chris@39: dstfile=`basename $dst` Chris@39: else Chris@39: dstfile=`basename $dst $transformbasename | Chris@39: sed $transformarg`$transformbasename Chris@39: fi Chris@39: Chris@39: # don't allow the sed command to completely eliminate the filename Chris@39: Chris@39: if [ x"$dstfile" = x ] Chris@39: then Chris@39: dstfile=`basename $dst` Chris@39: else Chris@39: true Chris@39: fi Chris@39: Chris@39: # Make a temp file name in the proper directory. Chris@39: Chris@39: dsttmp=$dstdir/#inst.$$# Chris@39: Chris@39: # Move or copy the file name to the temp name Chris@39: Chris@39: $doit $instcmd $src $dsttmp && Chris@39: Chris@39: trap "rm -f ${dsttmp}" 0 && Chris@39: Chris@39: # and set any options; do chmod last to preserve setuid bits Chris@39: Chris@39: # If any of these fail, we abort the whole thing. If we want to Chris@39: # ignore errors from any of these, just make sure not to ignore Chris@39: # errors from the above "$doit $instcmd $src $dsttmp" command. Chris@39: Chris@39: if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && Chris@39: if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && Chris@39: if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && Chris@39: if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && Chris@39: Chris@39: # Now rename the file to the real destination. Chris@39: Chris@39: $doit $rmcmd -f $dstdir/$dstfile && Chris@39: $doit $mvcmd $dsttmp $dstdir/$dstfile Chris@39: Chris@39: fi && Chris@39: Chris@39: Chris@39: exit 0