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