Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!dalcs!silvert From: silvert@dalcs.UUCP (Bill Silvert) Newsgroups: net.sources Subject: New version of install(1) Message-ID: <2293@dalcs.UUCP> Date: Mon, 29-Dec-86 17:42:15 EST Article-I.D.: dalcs.2293 Posted: Mon Dec 29 17:42:15 1986 Date-Received: Mon, 29-Dec-86 21:54:47 EST Organization: Marine Ecology Lab. Lines: 209 Keywords: Fast, needs getopt, includes which(1) Here is a new version of the install utility for copying a file into the appropriate directory. It uses a modified version of the which(1) utility which was posted a while back. That version of which is very fast, and so is this version of install. The options are completely different from those in the old version, so check the documention in the shell script before using. I haven't bothered with the chmod commands (other than +x) since I don't use them, but they are trivial to add. Contents: install script and which.c #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # install # which.c # This archive created: Mon Dec 29 18:37:05 1986 # By: Bill Silvert (Marine Ecology Lab.) export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'install' then echo shar: "will not over-write existing file 'install'" else cat << \SHAR_EOF > 'install' : # install files on existing paths USAGE="Usage: `basename $0` [-mrsx] [-d dir] [-f file] filename" ACT=cp REMOVE=: STRIP=: # parse options, -s for strip, -m for move, -r for remove, -x for chmod +x # -d forces installation in directory, -f gives new file name set -- `getopt mrsxd:f: $*` if [ $? != 0 ] then echo $USAGE; exit 2 fi for i do case $i in -m) ACT=mv; shift;; -r) REMOVE=rm; shift;; -s) STRIP=strip; shift;; -x) STRIP='chmod +x'; shift;; -d) DIR=$2; shift 2;; -f) OLD=$2; shift 2;; --) shift; break;; esac done for i do if [ -f $i ] then $STRIP $i if [ $DIR ] then if [ -d $DIR ] then OLD=$DIR/`basename $i` else echo "$DIR is not a directory" exit 2 fi else if [ $OLD ] then if [ $# -ne 1 ] then echo "-f option only installs one file" exit 2 fi else OLD=`which -oq $i` if [ $OLD ] then : else echo "old version of $i not found" exit 3 fi fi fi $ACT $i $OLD $REMOVE $i echo "$i installed as $OLD" else echo "file $i not found" exit 4 fi done SHAR_EOF chmod +x 'install' fi if test -f 'which.c' then echo shar: "will not over-write existing file 'which.c'" else cat << \SHAR_EOF > 'which.c' #includestatic char SCCSID[] = "@(#)which.c Ver. 1.1, 86/12/29 13:46:31"; char *progname; int all = 0; /* find all occurrences */ int cwd = 1; /* check cwd */ int warn = 1; /* give a warning if not found */ main(argc,argv) int argc; char *argv[]; { char *getenv(), *path = getenv("PATH"); int c, getopt(); extern int optind; extern char *optarg; progname = *argv; while((c = getopt(argc, argv, "aohq")) != EOF) switch(c) { case 'a': all++; break; case 'o': cwd = 0; break; case 'q': warn = 0; break; case 'h': default: help(); exit(1); } switch(argc - optind) { case 0: help(); break; default: for(; optind