head 1.2; access; symbols SHTOOL_1_0_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.2 date 99.04.29.11.21.58; author rse; state dead; branches; next 1.1; 1.1 date 99.04.29.11.19.34; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.34; author rse; state Exp; branches; next ; desc @@ 1.2 log @*** empty log message *** @ text @#!/bin/sh ## ## shtool -- Shell Tool ## Version 1.0.0 (22-Apr-1999) ## ## ## ==================================================================== ## Copyright (c) 1994-1999 Ralf S. Engelschall. All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions ## are met: ## ## 1. Redistributions of source code must retain the above copyright ## notice, this list of conditions and the following disclaimer. ## ## 2. Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in ## the documentation and/or other materials provided with the ## distribution. ## ## 3. All advertising materials mentioning features or use of this ## software must display the following acknowledgment: ## "This product includes software developed by ## Ralf S. Engelschall ." ## ## 4. Redistributions of any form whatsoever must retain the following ## acknowledgment: ## "This product includes software developed by ## Ralf S. Engelschall ." ## ## THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY ## EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ## STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ## OF THE POSSIBILITY OF SUCH DAMAGE. ## ==================================================================== ## ## This product includes software developed by the Apache Group ## for use in the Apache HTTP server project (http://www.apache.org/) ## ## ## Usage: shtool ## ## Available commands: ## becho echo command using terminal bold mode ## buildinfo Determine Build Information ## checkheader Check whether a C header file exists ## findcpp Find out how to _directly_ run the C Pre-Processor (CPP) ## findperl Find a reasonable Perl interpreter ## findprg find one or more programs somwhere in PATH ## fixperm Fix file permission inside a source tree ## fp2rp Convert a Unix forward file path to a reverse dotted path ## guessos Simple OS/Platform guesser ## install Install a program, script or datafile ## mkdir Make a directory plus it's hierarchy ## mkshadow Create a shadow tree ## newvers Generate and maintain a version information file ## ppl Pretty print a colon-sperarated list by avoiding tr and fmt ## prop Process indication though a propeller ## slo Separate Linker Options by library class ## if [ $# -eq 0 ]; then echo 'shtool becho [-n] [-b] [-e] [...]' echo 'shtool buildinfo [-n] ' echo 'shtool checkheader ' echo 'shtool findcpp ' echo 'shtool findperl ' echo 'shtool findprg [-s] [-pPATH] []' echo 'shtool fixperm []' echo 'shtool fp2rp ' echo 'shtool guessos ' echo 'shtool install [-c] [-m ] [-o ] [-g ] [-s] [-S ] ' echo 'shtool mkdir ' echo 'shtool mkshadow ' echo 'shtool newvers [-l ] [-n ] [-p ] [-r .[.pb]

] [-i v|r|P|p|b|a|s] [-d short|long|libtool|hex] ' echo 'shtool ppl ' echo 'shtool prop ' echo 'shtool slo ... -Lxx -lxx ...' exit 1 fi util=$1 shift case $util in becho ) begin=no end=no nl="\n" text='' while [ ".$1" != . ]; do case $1 in -b) begin=yes; shift; continue ;; -e) end=yes; shift; continue ;; -n) nl=""; shift; continue ;; *) break; esac done text="$*" # start with nothing T_MD='' T_ME='' # some hard-coded terminal sequences case $TERM in xterm|xterm*|vt220|vt220*) T_MD=`echo dummy | awk '{ printf("%c%c%c%c", 27, 91, 49, 109); }'` T_ME=`echo dummy | awk '{ printf("%c%c%c", 27, 91, 109); }'` ;; vt100|vt100*) T_MD=`echo dummy | awk '{ printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }'` T_ME=`echo dummy | awk '{ printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }'` ;; esac # additionally try a vendor's tput program if [ ".$T_MD" = . -o ".$T_ME" = . ]; then MD="`tput md 2>/dev/null`" ME="`tput me 2>/dev/null`" if [ ".$MD" != . -a ".$ME" != . ]; then T_MD="$MD" T_ME="$ME" fi fi # result if [ ".$T_MD" = . -o ".$T_ME" = . ]; then echo "bold:Error: unable to determine terminal sequence for bold mode" 1>&2 exit 1 else if [ ".$begin" = .yes ]; then echo dummy |\ awk '{ printf("%s", T_MD); }' \ T_MD="$T_MD" fi if [ ".$end" = .yes ]; then echo dummy |\ awk '{ printf("%s", T_ME); }' \ T_ME="$T_ME" fi if [ ".$text" != . ]; then echo dummy |\ awk '{ printf("%s%s%s%s", T_MD, TEXT, T_ME, NL); }' \ T_MD="$T_MD" TEXT="$text" T_ME="$T_ME" NL="$nl" fi fi ;; buildinfo ) # # argument line handling # error=no if [ $# -ne 1 -a $# -ne 2 ]; then error=yes fi if [ $# -eq 2 -a ".$1" != ".-n" ]; then error=yes fi if [ $error = yes ]; then echo "$0:Error: invalid argument line" echo "$0:Usage: $0 [-n] " echo "Where can contain:" echo " %u ...... substituted by determined username (foo)" echo " %U ...... substituted by determined user id (42)" echo " %h ...... substituted by determined hostname (bar)" echo " %d ...... substituted by determined domainname (.com)" echo " %D ...... substituted by determined day (DD)" echo " %M ...... substituted by determined month (MM)" echo " %Y ...... substituted by determined year (YYYYY)" echo " %m ...... substituted by determined monthname (Jan)" exit 1 fi if [ $# -eq 2 ]; then newline=no format_string="$2" else newline=yes format_string="$1" fi # # initialization # username='' hostname='' domainname='' time_day='' time_month='' time_year='' time_monthname='' # # determine username # username="$LOGNAME" if [ ".$username" = . ]; then username="$USER" if [ ".$username" = . ]; then username="`(whoami) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$username" = . ]; then username="`(who am i) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$username" = . ]; then username='unknown' fi fi fi fi # # determine user id # userid="`(id -u) 2>/dev/null`" if [ ".$userid" = . ]; then str="`(id) 2>/dev/null`" if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'` fi if [ ".$userid" = . ]; then userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid='?' fi fi fi fi # # determine hostname and domainname # hostname="`(uname -n) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$hostname" = . ]; then hostname="`(hostname) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$hostname" = . ]; then hostname='unknown' fi fi case $hostname in *.* ) domainname=".`echo $hostname | cut -d. -f2-`" hostname="`echo $hostname | cut -d. -f1`" ;; esac if [ ".$domainname" = . ]; then if [ -f /etc/resolv.conf ]; then domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\ sed -e 's/.*domain//' \ -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ -e 's/^\.//' -e 's/^/./' |\ awk '{ printf("%s", $1); }'`" if [ ".$domainname" = . ]; then domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\ sed -e 's/.*search//' \ -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ -e 's/ .*//' -e 's/ .*//' \ -e 's/^\.//' -e 's/^/./' |\ awk '{ printf("%s", $1); }'`" fi fi fi # # determine current time # time_day="`date '+%d' | awk '{ printf("%s", $1); }'`" time_month="`date '+%m' | awk '{ printf("%s", $1); }'`" time_year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`" if test ".$time_year" = .; then time_year="`date '+%y' | awk '{ printf("%s", $1); }'`" case $time_year in 9[0-9]*) time_year="19$time_year" ;; *) time_year="20$time_year" ;; esac fi case $time_month in 1|01) time_monthname='Jan' ;; 2|02) time_monthname='Feb' ;; 3|03) time_monthname='Mar' ;; 4|04) time_monthname='Apr' ;; 5|05) time_monthname='May' ;; 6|06) time_monthname='Jun' ;; 7|07) time_monthname='Jul' ;; 8|08) time_monthname='Aug' ;; 9|09) time_monthname='Sep' ;; 10) time_monthname='Oct' ;; 11) time_monthname='Nov' ;; 12) time_monthname='Dec' ;; esac # # create result string # if [ ".$newline" = .yes ]; then echo $format_string |\ sed -e "s;%u;$username;g" \ -e "s;%U;$userid;g" \ -e "s;%h;$hostname;g" \ -e "s;%d;$domainname;g" \ -e "s;%D;$time_day;g" \ -e "s;%M;$time_month;g" \ -e "s;%Y;$time_year;g" \ -e "s;%m;$time_monthname;g" else echo "${format_string}&" |\ sed -e "s;%u;$username;g" \ -e "s;%U;$userid;g" \ -e "s;%h;$hostname;g" \ -e "s;%d;$domainname;g" \ -e "s;%D;$time_day;g" \ -e "s;%M;$time_month;g" \ -e "s;%Y;$time_year;g" \ -e "s;%m;$time_monthname;g" |\ awk '-F&' '{ printf("%s", $1); }' fi ;; checkheader ) header=$1 rc=1 if [ ".$CPP" = . ]; then CPP='NOT-AVAILABLE' fi if [ ".$CPP" != .NOT-AVAILABLE ]; then # create a test C source cat >conftest.c < Syntax Error EOT (eval "$CPP conftest.c >/dev/null") 2>conftest.out my_error=`grep -v '^ *+' conftest.out` if [ ".$my_error" = . ]; then rc=0 fi else if [ -f "/usr/include/$header" ]; then rc=0 fi fi rm -f conftest.* exit $rc ;; findcpp ) # create a test C source: # - has to use extension ".c" because some CPP only accept this one # - uses assert.h because this is a standard header and harmless to include # - contains a Syntax Error to make sure it passes only the preprocessor # but not the real compiler pass cat >conftest.c < Syntax Error EOT # some braindead systems have a CPP define for a directory :-( if [ ".$CPP" != . ]; then if [ -d "$CPP" ]; then CPP='' fi fi if [ ".$CPP" != . ]; then # case 1: user provided a default CPP variable (we only check) (eval "$CPP conftest.c >/dev/null") 2>conftest.out my_error=`grep -v '^ *+' conftest.out` if [ ".$my_error" != . ]; then CPP='' fi else # case 2: no default CPP variable (we have to find one) # 1. try the standard -E option CPP="${CC-cc} -E" (eval "$CPP conftest.c >/dev/null") 2>conftest.out my_error=`grep -v '^ *+' conftest.out` if [ ".$my_error" != . ]; then # 2. try the -E option and GCC's -traditional-ccp option CPP="${CC-cc} -E -traditional-cpp" (eval "$CPP conftest.c >/dev/null") 2>conftest.out my_error=`grep -v '^ *+' conftest.out` if [ ".$my_error" != . ]; then # 3. try a standalone cpp command in $PATH and lib dirs CPP="`./helpers/PrintPath cpp`" if [ ".$CPP" = . ]; then CPP="`./helpers/PrintPath -p/lib:/usr/lib:/usr/local/lib cpp`" fi if [ ".$CPP" != . ]; then (eval "$CPP conftest.c >/dev/null") 2>conftest.out my_error=`grep -v '^ *+' conftest.out` if [ ".$my_error" != . ]; then # ok, we gave up... CPP='' fi fi fi fi fi # cleanup after work rm -f conftest.* # Ok, empty CPP variable now means it's not available if [ ".$CPP" = . ]; then CPP='NOT-AVAILABLE' fi echo $CPP ;; findperl ) TMPFILE=/tmp/findperl.$$.tmp rm -f $TMPFILE touch $TMPFILE c=0 for dir in `echo $PATH | sed -e 's/:/ /g'`; do for perl in perl5 perl miniperl; do if test -f "$dir/$perl"; then perl="$dir/$perl" version=`$perl -v | grep version |\ sed -e 's/.* version //' -e 's/ built.*//' -e 's/ with.*//'` versionnum="`echo $version | sed -e 's/\.//g' -e 's/_//g'`" versionnum=`expr $versionnum - $c` echo "$versionnum $version $perl" >>$TMPFILE fi done c=`expr $c + 1` done perlvers="`cat $TMPFILE | sort -u | tail -1 | cut '-d ' -f2`" perlprog="`cat $TMPFILE | sort -u | tail -1 | cut '-d ' -f3`" rm -f $TMPFILE case $perlprog:$perlvers in *:5* ) ;; *:* ) echo "Ops, BnP needs an installed Perl 5.00x somewhere in $PATH" 1>&2 exit 1 ;; esac # switch to perl interpreter echo "$perlprog" ;; findprg ) # parameters silent=no pathlist=$PATH namelist='' # parse argument line for opt do case $opt in -s ) silent=yes ;; -p* ) pathlist="`echo $opt | cut -c3-`" ;; * ) namelist="$namelist $opt" ;; esac done # check whether the test command supports the -x option testfile="findprg.t.$$" cat >$testfile </dev/null; then minusx="-x" else minusx="-r" fi rm -f $testfile paths="`echo $pathlist |\ sed -e 's/^:/.:/' \ -e 's/::/:.:/g' \ -e 's/:$/:./' \ -e 's/:/ /g'`" # iterate over names for name in $namelist; do # iterate over paths for path in $paths; do if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then if [ "$silent" != "yes" ]; then echo "$path/$name" fi # found! exit 0 fi done done # not found! exit 1 ;; fixperm ) for p in $*; do for file in `find $p -depth -print`; do if [ -f $file ]; then if [ -x $file ]; then echo " $file (FILE/EXEC)" chmod 775 $file else echo " $file (FILE/REGULAR)" chmod 664 $file fi continue fi if [ -d $file ]; then echo " $file (DIR)" chmod 775 $file continue fi echo " $file (UNKNOWN)" done done ;; fp2rp ) if [ "x$1" = "x." ]; then rp='.' else rp='' for pe in `IFS="$IFS/"; echo $1`; do rp="../$rp" done fi echo $rp | sed -e 's:/$::' ;; guessos ) MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown" RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown" SYSTEM=`(uname -s) 2>/dev/null` || SYSTEM="unknown" VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown" XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'` if [ "x$XREL" != "x" ]; then if [ -f /etc/kconfig ]; then case "$XREL" in 4.0|4.1) echo "${MACHINE}-whatever-isc4"; exit 0 ;; esac else case "$XREL" in 3.2v4.2) echo "whatever-whatever-sco3"; exit 0 ;; 3.2v5.0*) echo "whatever-whatever-sco5"; exit 0 ;; 4.2MP) if [ "x$VERSION" = "x2.1.1" ]; then echo "${MACHINE}-whatever-unixware211"; exit 0 elif [ "x$VERSION" = "x2.1.2" ]; then echo "${MACHINE}-whatever-unixware212"; exit 0 else echo "${MACHINE}-whatever-unixware2"; exit 0 fi ;; 4.2) echo "whatever-whatever-unixware1"; exit 0 ;; 5) case "$VERSION" in 7*) echo "${MACHINE}-whatever-unixware7"; exit 0 ;; esac ;; esac fi fi case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in MiNT:*) echo "m68k-atari-mint"; exit 0 ;; A/UX:*) echo "m68k-apple-aux3"; exit 0 ;; AIX:*) echo "${MACHINE}-ibm-aix${VERSION}.${RELEASE}"; exit 0 ;; dgux:*) echo "${MACHINE}-dg-dgux"; exit 0 ;; HI-UX:*) echo "${MACHINE}-hi-hiux"; exit 0 ;; HP-UX:*) HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo "${MACHINE}-hp-hpux${HPUXVER}"; exit 0 ;; IRIX:*) if [ -f /usr/lib32/mips4/libm.so ]; then echo "${MACHINE}-sgi-irix32"; exit 0 else echo "${MACHINE}-sgi-irix"; exit 0 fi ;; IRIX64:*) echo "${MACHINE}-sgi-irix64"; exit 0 ;; Linux:[2-9].*) echo "${MACHINE}-whatever-linux2"; exit 0 ;; Linux:1.*) echo "${MACHINE}-whatever-linux1"; exit 0 ;; LynxOS:*) echo "${MACHINE}-lynx-lynxos"; exit 0 ;; BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*) echo "i486-whatever-bsdi"; exit 0 ;; BSD/386:*|BSD/OS:*) echo "${MACHINE}-whatever-bsdi"; exit 0 ;; FreeBSD:*:*:*486*) FREEBSDVERS=`echo ${RELEASE}|sed -e 's/[-(].*//'` echo "i486-pc-freebsd${FREEBSDVERS}"; exit 0 ;; FreeBSD:*) FREEBSDVERS=`echo ${RELEASE}|sed -e 's/[-(].*//'` echo "${MACHINE}-pc-freebsd${FREEBSDVERS}"; exit 0 ;; NetBSD:*:*:*486*) echo "i486-whatever-netbsd"; exit 0 ;; NetBSD:*) echo "${MACHINE}-whatever-netbsd"; exit 0 ;; OpenBSD:*) echo "${MACHINE}-whatever-openbsd"; exit 0 ;; OSF1:*:*:*alpha*) echo "${MACHINE}-dec-osf"; exit 0 ;; QNX:*) if [ "$VERSION" -gt 422 ]; then echo "${MACHINE}-qssl-qnx32" else echo "${MACHINE}-qssl-qnx" fi exit 0 ;; Paragon*:*:*:*) echo "i860-intel-osf1"; exit 0 ;; SunOS:5.*) SOLVER=`echo ${RELEASE}|awk -F. '{ if (NF < 3) printf "2%s0\n",$2 else printf "2%s%s\n",$2,$3 }'` echo "${MACHINE}-sun-solaris2.${SOLVER}"; exit 0 ;; SunOS:*) echo "${MACHINE}-sun-sunos4"; exit 0 ;; UNIX_System_V:4.*:*) echo "${MACHINE}-whatever-sysv4"; exit 0 ;; unix:3.0.9*:*:88k) echo "${MACHINE}-encore-sysv4"; exit 0 ;; *:4*:R4*:m88k) echo "${MACHINE}-whatever-sysv4"; exit 0 ;; UnixWare:5:99*:*) # Gemini, beta release of next rev of unixware echo "${MACHINE}-whatever-unixware212"; exit 0 ;; DYNIX/ptx:4*:*) echo "${MACHINE}-whatever-sysv4"; exit 0 ;; *:4.0:3.0:[345][0-9]?? | *:4.0:3.0:3[34]??[/,]* | library:*) echo "x86-ncr-sysv4"; exit 0 ;; ULTRIX:*) echo "${MACHINE}-unknown-ultrix"; exit 0 ;; SINIX-?:* | ReliantUNIX-?:*) echo "${MACHINE}-siemens-sysv4"; exit 0 ;; POSIX*BS2000) echo "${MACHINE}-siemens-sysv4"; exit 0 ;; machten:*) echo "${MACHINE}-tenon-${SYSTEM}"; exit 0; ;; ConvexOS:*:11.*:*) echo "${MACHINE}-v11-${SYSTEM}"; exit 0; ;; UNIX_SV:*:*:maxion) echo "${MACHINE}-ccur-sysv4"; exit 0; ;; PowerMAX_OS:*:*:Night_Hawk) MACHINE=`uname -p` echo "${MACHINE}-concurrent-powermax"; exit 0; ;; UNIX_SV:*) if [ -d /usr/nec ];then echo "mips-nec-sysv4"; exit 0; fi ;; NonStop-UX:4.[02]*:[BC]*:*) echo "${MACHINE}-tandem-sysv4"; exit 0; ;; Rhapsody:*:*:*) case "${MACHINE}" in Power*) MACHINE=powerpc ;; esac echo "${MACHINE}-apple-rhapsody${RELEASE}"; exit 0 ;; "RISC iX":*) echo "arm-whatever-riscix"; exit 0; ;; *:4.0:2:*) echo "whatever-unisys-sysv4"; exit 0; ;; *:*:dcosx:NILE*) echo "pyramid-pyramid-svr4"; exit 0; ;; *:*:*:"DRS 6000") echo "drs6000-whatever-whatever"; exit 0; ;; esac # existance of the /usr/apollo directory is proof enough for Apollo if [ -d /usr/apollo ]; then echo "whatever-apollo-whatever" exit 0 fi # Now NeXT ISNEXT=`hostinfo 2>/dev/null` case "$ISNEXT" in *NeXT*) # Swiped from a friendly uname clone for NEXT/OPEN Step. NEXTOSVER="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`" if [ "$NEXTOSVER" -gt 3.3 ]; then NEXTOS="openstep" else NEXTOS="nextstep" fi NEXTREL="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`" NEXTARCH=`arch` echo "${NEXTARCH}-next-${NEXTOS}${NEXTREL}" ; exit 0 ;; esac echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}" ;; install ) # # put in absolute paths if you don't have them in your path; # or use env. vars. # mvprog="${MVPROG-mv}" cpprog="${CPPROG-cp}" chmodprog="${CHMODPROG-chmod}" chownprog="${CHOWNPROG-chown}" chgrpprog="${CHGRPPROG-chgrp}" stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" # # parse argument line # instcmd="$mvprog" chmodcmd="" chowncmd="" chgrpcmd="" stripcmd="" rmcmd="$rmprog -f" mvcmd="$mvprog" src="" dst="" while [ ".$1" != . ]; do case $1 in -c) instcmd="$cpprog" shift; continue ;; -m) chmodcmd="$chmodprog $2" shift; shift; continue ;; -o) chowncmd="$chownprog $2" shift; shift; continue ;; -g) chgrpcmd="$chgrpprog $2" shift; shift; continue ;; -s) stripcmd="$stripprog" shift; continue;; -S) stripcmd="$stripprog $2" shift; shift; continue ;; *) if [ ".$src" = . ]; then src=$1 else dst=$1 fi shift; continue ;; esac done if [ ".$src" = . ]; then echo "install.sh: no input file specified" exit 1 fi if [ ".$dst" = . ]; then echo "install.sh: no destination specified" exit 1 fi # # If destination is a directory, append the input filename; if # your system does not like double slashes in filenames, you may # need to add some logic # if [ -d $dst ]; then dst="$dst/`basename $src`" fi # Make a temp file name in the proper directory. dstdir=`dirname $dst` dsttmp=$dstdir/#inst.$$# # Move or copy the file name to the temp name $instcmd $src $dsttmp # And set any options; do chmod last to preserve setuid bits if [ ".$chowncmd" != . ]; then $chowncmd $dsttmp; fi if [ ".$chgrpcmd" != . ]; then $chgrpcmd $dsttmp; fi if [ ".$stripcmd" != . ]; then $stripcmd $dsttmp; fi if [ ".$chmodcmd" != . ]; then $chmodcmd $dsttmp; fi # Now rename the file to the real destination. $rmcmd $dst $mvcmd $dsttmp $dst exit 0 ;; mkdir ) umask 022 errstatus=0 for file in ${1+"$@@"} ; do set fnord `echo ":$file" |\ sed -e 's/^:\//%/' -e 's/^://' -e 's/\// /g' -e 's/^%/\//'` shift pathcomp= for d in ${1+"$@@"}; do pathcomp="$pathcomp$d" case "$pathcomp" in -* ) pathcomp=./$pathcomp ;; esac if test ! -d "$pathcomp"; then echo "mkdir $pathcomp" 1>&2 mkdir "$pathcomp" || errstatus=$? fi pathcomp="$pathcomp/" done done exit $errstatus ;; mkshadow ) # default IFS DIFS=' ' # source and destination directory src=`echo $1 | sed -e 's:/$::'` dst=`echo $2 | sed -e 's:/$::'` # check whether source exists if [ ! -d $src ]; then echo "mkshadow.sh:Error: source directory not found" 1>&2 exit 1 fi # determine if one of the paths is an absolute path, # because then we have to use an absolute symlink oneisabs=0 case $src in /* ) oneisabs=1 ;; esac case $dst in /* ) oneisabs=1 ;; esac # determine reverse directory for destination directory dstrevdir='' if [ ".$oneisabs" = . ]; then # (inlined fp2rp) OIFS2="$IFS"; IFS='/' for pe in $dst; do dstrevdir="../$dstrevdir" done IFS="$OIFS2" else src="`cd $src; pwd`"; fi # create directory tree at destination if [ ! -d $dst ]; then mkdir $dst fi DIRS="`cd $src find . -type d -print |\ sed -e '/\/CVS/d' \ -e '/^\.$/d' \ -e 's:^\./::'`" OIFS="$IFS" IFS="$DIFS" for dir in $DIRS; do mkdir $dst/$dir done IFS="$OIFS" # fill directory tree with symlinks to files FILES="`cd $src find . -depth -print |\ sed -e '/\.o$/d' \ -e '/\.a$/d' \ -e '/\.so$/d' \ -e '/\.so-o$/d' \ -e '/\.cvsignore$/d' \ -e '/\/CVS/d' \ -e '/\.indent\.pro$/d' \ -e '/\.apaci.*/d' \ -e '/Makefile$/d' \ -e '/\/\.#/d' \ -e '/\.orig$/d' \ -e 's/^\.\///'`" OIFS="$IFS" IFS="$DIFS" for file in $FILES; do # don't use `-type f' above for find because of symlinks if [ -d $file ]; then continue fi basename=`echo $file | sed -e 's:^.*/::'` dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'` from="$src/$file" to="$dst/$dir$basename" if [ ".$oneisabs" = .0 ]; then if [ ".$dir" != . ]; then subdir=`echo $dir | sed -e 's:/$::'` # (inlined fp2rp) revdir='' OIFS2="$IFS"; IFS='/' for pe in $subdir; do revdir="../$revdir" done IFS="$OIFS2" # finalize from from="$revdir$from" fi from="$dstrevdir$from" fi echo " $to" ln -s $from $to done IFS="$OIFS" ;; newvers ) #!/bin/sh - LANGUAGE=txt NAME=unknown PREFIX=unknown FULLVERSION=unknown REPORT=NO INCREASE=P USAGE=NO FILE="" while [ ".$1" != . ]; do case $1 in -l) LANGUAGE=$2; shift; shift; continue ;; -n) NAME=$2; shift; shift; continue ;; -p) PREFIX=$2; shift; shift; continue ;; -r) FULLVERSION=$2; shift; shift; continue ;; -i) INCREASE=$2; shift; shift; continue ;; -d) REPORT=$2; shift; shift; continue ;; -h) USAGE=YES; shift; continue ;; *) break; esac done if [ $# -ne 1 ]; then USAGE=YES else FILE=$1 fi if [ ".$USAGE" = .YES ]; then echo "$0:Usage: newvers [options] file" echo "Options are:" echo "-l set language to one of 'txt', 'c' or 'perl'" echo "-n set program name" echo "-p set symbol prefix" echo "-r .[.pb]

set release version string" echo "-i v|r|P|p|b|a|s increase version, revision or {alpha,batch,patch,snap} level" echo "-d short|long|libtool|hex display current version only" echo "-h print this page" exit 0 fi # determine language if [ ".$LANGUAGE" = .unknown ]; then case $FILE in *.txt ) LANGUAGE=txt ;; *.c ) LANGUAGE=c ;; *.pl | *.pm ) LANGUAGE=perl ;; * ) echo "$0:Error: Unknown language type" 1>&2; exit 1 ;; esac fi # determine prefix from name and vice versa if [ ".$PREFIX" = . -o ".$PREFIX" = .unknown ]; then if [ ".$NAME" != . -a ".$NAME" != .unknown ]; then PREFIX="$NAME" fi fi if [ ".$NAME" = . -o ".$NAME" = .unknown ]; then if [ ".$PREFIX" != . -a ".$PREFIX" != .unknown ]; then NAME="$PREFIX" fi fi # determine version date=unknown if [ ".$FULLVERSION" = .unknown ]; then if [ -r "$FILE" ]; then # grep out current information id=`grep 'Version [0-9]*.[0-9]*[.abps][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $FILE | \ head -1 | \ sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\1:\2:\3:\4:\5%'` version=`echo $id | awk -F: '{ print $1 }'` revision=`echo $id | awk -F: '{ print $2 }'` bptype=`echo $id | awk -F: '{ print $3 }'` bplevel=`echo $id | awk -F: '{ print $4 }'` date=`echo $id | awk -F: '{ print $5 }'` if [ .$REPORT = .NO ]; then case $INCREASE in b ) bplevel=`expr $bplevel + 1` bptype=b ;; a ) bplevel=`expr $bplevel + 1` bptype=a ;; s ) bplevel=`expr $bplevel + 1` bptype=s ;; P ) bplevel=`expr $bplevel + 1` bptype=. ;; p ) bplevel=`expr $bplevel + 1` bptype=p ;; r ) revision=`expr $revision + 1` bplevel=0 ;; v ) version=`expr $version + 1` revision=0 bplevel=0 ;; esac date=calc fi FULLVERSION="$version.$revision$bptype$bplevel" else # intialise to first version version=0 revision=5 bptype=b bplevel=0 date=calc fi else # take given version V=`echo $FULLVERSION | sed -e 's%\([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\).*%\1:\2:\3:\4%'` version=`echo $V | awk -F: '{ print $1 }'` revision=`echo $V | awk -F: '{ print $2 }'` bptype=`echo $V | awk -F: '{ print $3 }'` bplevel=`echo $V | awk -F: '{ print $4 }'` date=calc fi # determine hex value of version case $FULLVERSION in *.*a* ) HEX=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' && echo "$FULLVERSION" | sed -e 's/.*a//' | awk '{ printf("0%02d", $1); }'` ;; *.*b* ) HEX=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' && echo "$FULLVERSION" | sed -e 's/.*b//' | awk '{ printf("1%02d", $1); }'` ;; *.*.* ) HEX=`echo "$FULLVERSION" | awk -F. '{ printf("%d%02d2%02d", $1, $2, $3); }'` ;; esac # determine libtool version case $FULLVERSION in *.*a* ) LTV=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'` ;; *.*b* ) LTV=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'` ;; *.*.* ) LTV=`echo "$FULLVERSION" | awk -F. '{ printf("%d:%d", $1*10+$2, $3); }'` ;; esac # determine string out of filename FILESTR=`echo "$FILE" | tr '[a-z./%+\-]' '[A-Z______]'` # determine date if [ ".$date" = .calc ]; then day="`date '+%d' | awk '{ printf("%s", $1); }'`" month="`date '+%m' | awk '{ printf("%s", $1); }'`" year="`date '+%Y' 2>/dev/null | awk '{ printf("%s", $1); }'`" if test ".$time_year" = .; then year="`date '+%y' | awk '{ printf("%s", $1); }'`" case $year in 9[0-9]*) year="19$year" ;; *) year="20$year" ;; esac fi case $month in 1|01) month='Jan' ;; 2|02) month='Feb' ;; 3|03) month='Mar' ;; 4|04) month='Apr' ;; 5|05) month='May' ;; 6|06) month='Jun' ;; 7|07) month='Jul' ;; 8|08) month='Aug' ;; 9|09) month='Sep' ;; 10) month='Oct' ;; 11) month='Nov' ;; 12) month='Dec' ;; esac date="${day}-${month}-${year}" fi if [ .$REPORT != .NO ]; then case $REPORT in long ) echo "$version.$revision$bptype$bplevel ($date)" ;; short ) echo "$version.$revision$bptype$bplevel" ;; libtool ) echo "$LTV" ;; hex ) echo "0x$HEX" ;; esac exit 0 fi # create the version file according the the selected language echo "new version: $version.$revision$bptype$bplevel ($date)" tmpfile="/tmp/newvers.tmp.$$" rm -f $tmpfile >/dev/null 2>&1 case $LANGUAGE in txt ) cat >$tmpfile <<'EOT' This is @@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@) EOT ;; c ) cat >$tmpfile <<'EOT' /* ** @@FILE@@ -- Version File (automatically generated and maintained by NEWVERS) */ #ifdef AS_HEADER #ifndef @@FILESTR@@ #define @@FILESTR@@ #define @@PREFIX@@_VERSION 0x@@HEX@@ extern const int @@PREFIX@@_Version; extern const char @@PREFIX@@_VersionStr[]; extern const char @@PREFIX@@_Hello[]; extern const char @@PREFIX@@_GNUVersion[]; extern const char @@PREFIX@@_WhatID[]; extern const char @@PREFIX@@_RCSIdentID[]; extern const char @@PREFIX@@_WebID[]; extern const char @@PREFIX@@_PlainID[]; #endif #else const int @@PREFIX@@_Version = 0x@@HEX@@; const char @@PREFIX@@_VersionStr[] = "@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; const char @@PREFIX@@_Hello[] = "This is @@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; const char @@PREFIX@@_GNUVersion[] = "@@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; const char @@PREFIX@@_WhatID[] = "@@(#)@@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; const char @@PREFIX@@_RCSIdentID[] = "$Id: shtool,v 1.1 1999/04/29 11:19:34 rse Exp $"; const char @@PREFIX@@_WebID[] = "@@NAME@@/@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; const char @@PREFIX@@_PlainID[] = "@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; #endif EOT ;; perl ) cat >$tmpfile <<'EOT' $@@PREFIX@@_Version = 0x@@HEX@@; $@@PREFIX@@_VersionStr = "@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; $@@PREFIX@@_Hello = "This is @@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; $@@PREFIX@@_GNUVersion = "@@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; $@@PREFIX@@_WhatID = "@@(#)@@NAME@@ Version @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ (@@DAY@@-@@MONTH@@-@@YEAR@@)"; $@@PREFIX@@_RCSIdentID = "\$Id: shtool,v 1.1 1999/04/29 11:19:34 rse Exp $"; $@@PREFIX@@_WebID = "@@NAME@@/@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; $@@PREFIX@@_PlainID = "@@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@"; 1; EOT ;; esac # now create the version file rm -f $FILE >/dev/null 2>&1 sed \ -e "s|@@FILE@@|$FILE|g" \ -e "s|@@FILESTR@@|$FILESTR|g" \ -e "s|@@PREFIX@@|$PREFIX|g" \ -e "s|@@NAME@@|$NAME|g" \ -e "s|@@HEX@@|$HEX|g" \ -e "s|@@VERSION@@|$version|g" \ -e "s|@@REVISION@@|$revision|g" \ -e "s|@@BPTYPE@@|$bptype|g" \ -e "s|@@BPLEVEL@@|$bplevel|g" \ -e "s|@@YEAR@@|$year|g" \ -e "s|@@MONTH@@|$month|g" \ -e "s|@@DAY@@|$day|g" <$tmpfile >$FILE rm -f $tmpfile >/dev/null 2>&1 exit 0 ;; ppl ) list=` IFS=: for entry in $*; do if [ "x$entry" != "x" ]; then echo $entry fi done |\ sort |\ awk ' BEGIN { list = ""; n = 0; } { list = list $1; n = n + 1; if (n == 1 || n == 2) { list = list ":"; } if (n == 3) { list = list "\n"; n = 0; } } END { print list; } '` IFS=' ' for entry in $list; do echo $entry |\ awk -F: ' { printf("%-15s %-15s %-15s\n", $1, $2, $3); } ' done |\ awk '{ if (length($0) > 48) { printf("%s\n", substr($0, 0, 47)); } else { print $0; } }' |\ sed -e 's/^/ [/' -e 's/$/]/' ;; prop ) line="$*" perl='' for dir in `echo $PATH | sed -e 's/:/ /g'` .; do if [ -f "$dir/perl" ]; then perl="$dir/perl" break fi done if [ ".$perl" != . ]; then # # Perl is preferred because writing to STDERR in # Perl really writes immediately as one would expect # $perl -e ' @@p = ("|","/","-","\\"); $i = 0; while () { printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]); $i = 0 if ($i > 3); } printf(STDERR "\r%s \n", $ARGV[0]); ' "$line" else # # But when Perl doesn't exists we use Awk even # some Awk's buffer even the /dev/stderr writing :-( # awk ' BEGIN { split("|#/#-#\\", p, "#"); i = 1; } { printf("\r%s%c\b", line, p[i++]) > "/dev/stderr"; if (i > 4) { i = 1; } } END { printf("\r%s \n", line) > "/dev/stderr"; } ' "line=$line" fi ;; slo ) DIFS=' ' # # parse out -L and -l options from command line # DIRS='' LIBS='' ARGV='' optprev="" OIFS="$IFS" IFS="$DIFS" for opt do # concatenate with previous option if exists if [ ".$optprev" != . ]; then opt="${optprev}${opt}"; optprev='' fi # remember options for arg when used stand-alone if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then optprev="$opt" continue; fi # split argument into option plus option argument arg="`echo $opt | cut -c3-`" opt="`echo $opt | cut -c1-2`" # store into containers case $opt in -L) DIRS="$DIRS:$arg" ;; -l) LIBS="$LIBS:$arg" ;; *) ARGV="$ARGV $opt" ;; esac done IFS="$OIFS" # # set linker default directories # DIRS_DEFAULT='/lib:/usr/lib' if [ ".$LD_LIBRARY_PATH" != . ]; then DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH" fi # # sort options by class # DIRS_OBJ='' LIBS_OBJ='' DIRS_PIC='' LIBS_PIC='' DIRS_DSO='' LIBS_DSO='' # for each library... OIFS="$IFS" IFS=':' for lib in $LIBS; do [ ".$lib" = . ] && continue found='no' found_indefdir='no' found_type='' found_dir='' # for each directory... OIFS2="$IFS" IFS=":$DIFS" for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do [ ".$dir" = . ] && continue [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes [ ! -d $dir ] && continue # search the file OIFS3="$IFS" IFS="$DIFS" for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do [ ".$file" = . ] && continue case $file in *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* ) found=yes; found_type=DSO; break ;; *.lo|*.la ) found=yes; found_type=PIC ;; *.a ) if [ ".$found_type" = . ]; then found=yes found_type=OBJ fi ;; esac done IFS="$OIFS3" if [ ".$found" = .yes ]; then found_dir="$dir" break fi done IFS="$OIFS2" if [ ".$found" = .yes ]; then if [ ".$found_indefdir" != .yes ]; then eval "dirlist=\"\${DIRS_${found_type}}:\"" if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" fi eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" else eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" fi else LIBS_OBJ="$LIBS_OBJ:$lib" #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`" #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1 #echo "slo:Warning: $dirlist" 1>&1 fi done IFS="$OIFS" # # also pass-through unused dirs even if it's useless # OIFS="$IFS" IFS=':' for dir in $DIRS; do dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:" if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then DIRS_OBJ="$DIRS_OBJ:$dir" fi done IFS="$OIFS" # # reassemble the options but seperated by type # OIFS="$IFS" IFS="$DIFS" for type in OBJ PIC DSO; do OIFS2="$IFS" IFS=':' eval "libs=\"\$LIBS_${type}\"" opts='' for lib in $libs; do [ ".$lib" = . ] && continue opts="$opts -l$lib" done eval "LIBS_${type}=\"$opts\"" eval "dirs=\"\$DIRS_${type}\"" opts='' for dir in $dirs; do [ ".$dir" = . ] && continue opts="$opts -L$dir" done eval "DIRS_${type}=\"$opts\"" IFS="$OIFS2" done IFS="$OIFS" # # give back results # OIFS="$IFS" IFS="$DIFS" for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do eval "val=\"\$${var}\"" val="`echo $val | sed -e 's/^ *//'`" echo "SLO_${var}=\"${val}\"" done IFS="$OIFS" ;; * ) echo "shtool:Error: Unknown command" exit 1 ;; esac ##EOF## @ 1.1 log @Initial revision @ text @d1223 1 a1223 1 const char @@PREFIX@@_RCSIdentID[] = "$Id: @@NAME@@ @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ @@DAY@@-@@MONTH@@-@@YEAR@@ $"; d1238 1 a1238 1 $@@PREFIX@@_RCSIdentID = "\$Id: @@NAME@@ @@VERSION@@.@@REVISION@@@@BPTYPE@@@@BPLEVEL@@ @@DAY@@-@@MONTH@@-@@YEAR@@ \$"; @ 1.1.1.1 log @Import of shtool 1.0.0 @ text @@