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