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