[BACK]Return to checkver CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib

Annotation of src/lib/checkver, Revision 1.13

1.5       christos    1: #!/bin/sh
1.13    ! martin      2: #      $NetBSD: checkver,v 1.12 2000/07/22 16:04:57 erh Exp $
1.1       erh         3: #
                      4: # Copyright (c) 1998 The NetBSD Foundation, Inc.
                      5: # All rights reserved.
                      6: #
                      7: # This code is derived from software contributed to The NetBSD Foundation
                      8: # by Eric Haszlakiewicz.
                      9: #
                     10: # Redistribution and use in source and binary forms, with or without
                     11: # modification, are permitted provided that the following conditions
                     12: # are met:
                     13: # 1. Redistributions of source code must retain the above copyright
                     14: #    notice, this list of conditions and the following disclaimer.
                     15: # 2. Redistributions in binary form must reproduce the above copyright
                     16: #    notice, this list of conditions and the following disclaimer in the
                     17: #    documentation and/or other materials provided with the distribution.
                     18: #
                     19: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     20: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     21: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     22: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     23: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29: # POSSIBILITY OF SUCH DAMAGE.
                     30: #
                     31:
                     32: #--------------------------------------------------------------------#
1.9       erh        33: # checkver -
                     34: #      Check for libraries that appear to be newer than the
                     35: #      one we're about to install.
                     36: #
1.6       simonb     37: # checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
                     38: # checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
                     39: # checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
1.1       erh        40: #
1.2       erh        41: # One of -d, -s or -f must be specified.
1.1       erh        42: #
1.2       erh        43: # all: If library name is not specified it is assumed to
                     44: #      be the name of the current directory.
                     45: #
                     46: # -d: Checks the version against the installed libraries.
                     47: #      If no further arguments are given "/usr/lib" is
                     48: #      used as the location of installed libraries.
                     49: #
                     50: # -s: Checks the version against the sets.  If no argument
                     51: #      follows the sets directory defaults to "/usr/src/distrib/sets/lists".
                     52: #      The directory may be specified as either the top of the
                     53: #      source tree or as the lists directory.
                     54: #
                     55: # -f: Checks the version against the provided list.  A filename
                     56: #      must be supplied.
1.1       erh        57: #
1.6       simonb     58: # -v: Specify the filename of the shlib_version file.  Defaults
                     59: #     to "./shlib_version".
                     60: #
1.8       simonb     61: # This script produces no output if all library version are not
1.1       erh        62: # large than the source version.  If an installed library with a
                     63: # version greater than the source is found, checkver prints a
                     64: # header and a list of the names of the offending installed libraries.
                     65: #
                     66: # The header may be supressed by passing "-q" as the first argument.
                     67: #
                     68:
1.2       erh        69: TMP=/tmp/checkver.$$
1.5       christos   70: # Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
                     71: # internal malloc!
                     72: trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
1.2       erh        73: trap "[ -d $TMP ] && rm -rf $TMP" 0
1.1       erh        74:
1.5       christos   75: Usage() {
1.9       erh        76:     echo "Usage: $1 [-q] [-v version_file] -d [installedlibdir [library name]]"
                     77:     echo "       $1 [-q] [-v version_file] -s [setlistdir [library name]]"
                     78:     echo "       $1 [-q] [-v version_file] -f liblistfile [library name]"
                     79:     echo "     $1 is a script that looks for installed libraries with"
                     80:     echo "        versions greater than that in the version file."
                     81:     echo "     For more information, read the comments."
1.1       erh        82: }
                     83:
1.2       erh        84: basedir=/usr/src
                     85: setsdir=$basedir/distrib/sets/lists
                     86: libdir=/usr/lib
1.6       simonb     87: shlib_version=./shlib_version
1.1       erh        88:
1.2       erh        89: error=0
                     90: quiet=0
                     91: usedir=0
                     92: usefile=0
                     93: usesets=0
                     94: CWD=`pwd`
1.6       simonb     95: args=`getopt "df:shqv:" "$@"`
1.2       erh        96: if [ $? -ne 0 ] ; then
1.1       erh        97:     Usage $0
                     98:     exit 0
                     99: fi
                    100:
1.2       erh       101: set -- $args
                    102:
1.7       christos  103: while [ ! -z "$1" ]; do
1.2       erh       104:     case "$1" in
                    105:        -d) usedir=1 ; shift
                    106:            if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
                    107:                Usage $0 ; exit 2
                    108:            fi;;
                    109:        -f) usefile=1 ; arg1=$2 ; shift ; shift
                    110:            if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
                    111:                Usage $0 ; exit 2
                    112:            fi;;
                    113:        -s) usesets=1 ; shift
                    114:            if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
                    115:                Usage $0 ; exit 2
                    116:            fi;;
1.6       simonb    117:        -v) shlib_version=$2; shift ; shift ;;
1.2       erh       118:        -h) Usage $0 ; exit 0;;
                    119:        -q) quiet=1 ; shift;;
                    120:        --) shift ; break;;
                    121:     esac
                    122: done
                    123:
                    124: if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
                    125:     Usage $0 ; exit 2
                    126: fi
                    127:
                    128: if [ $usefile -eq 1 ] ; then
                    129:    LIBLIST="$arg1"
1.1       erh       130: else
1.5       christos  131:    mkdir -m 0700 $TMP
                    132:    if [ $?  != 0 ]; then
1.2       erh       133:        echo "$0: Unable to create temp directory."
                    134:        exit 2
                    135:    fi
                    136:    LIBLIST=$TMP/libs.lst
                    137: fi
                    138:
                    139: # Build list from the installed libraries.
                    140: if [ $usedir -eq 1 ] ; then
                    141:     if [ "X$1" != "X" ] ; then
                    142:        libdir="$1"
                    143:     fi
1.4       erh       144:     for f in $libdir ; do
                    145:        ls $f/lib*.so.*.*
1.12      erh       146:     done > $LIBLIST 2> /dev/null
1.1       erh       147: fi
                    148:
1.2       erh       149: # Build list from set lists.  Parameter may be either
                    150: # the "lists" directory or the top of the source tree.
                    151: if [ $usesets -eq 1 ] ; then
                    152:     if [ "X$1" != "X" ] ; then
                    153:        setsdir="$1"
                    154:        if [ -d "$setsdir/distrib/sets/lists" ] ; then
                    155:            setsdir="$setsdir/distrib/sets/lists"
                    156:        fi
                    157:     fi
                    158:     (cd $setsdir ;
                    159:      cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
                    160:                  | sort -u > $LIBLIST
                    161:     )
1.1       erh       162: fi
                    163:
1.2       erh       164: #
                    165: # The file $LIBLIST now contains a list of libraries.
                    166: #
                    167:
1.1       erh       168: if [ "X$2" = "X" ] ; then
1.2       erh       169:     makefile=$CWD/Makefile
                    170:     libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
                    171:
                    172:     # Assume the library name is the name of the current directory.
                    173:     if [ -z $libname ]; then
                    174:        libname=`basename $CWD`
                    175:     fi
                    176: else
1.1       erh       177:     libname="$2"
1.2       erh       178: fi
1.5       christos  179: echo $libname | grep "^lib" 1>&2 2> /dev/null
                    180: if [ $? != 0 ]; then
1.2       erh       181:     libname="lib$libname"
                    182: fi
1.1       erh       183:
                    184:
1.6       simonb    185: if [ ! -f $shlib_version ] ; then
                    186:     echo "$0: unable to find $shlib_version"
1.2       erh       187:     exit 2
1.1       erh       188: fi
                    189:
                    190: # Grab major and minor numbers from the source.
1.6       simonb    191: . $shlib_version
1.1       erh       192:
                    193: if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
1.6       simonb    194:     echo "$0: $shlib_version doesn't contain the version."
1.2       erh       195:     exit 2
1.1       erh       196: fi
                    197:
                    198: # Find every shared object library with the same base name.
1.2       erh       199:  for instlib in `grep $libname.so "$LIBLIST" ` ; do
1.1       erh       200:     # Grab the major and minor from the installed library.
1.2       erh       201:     instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
                    202:     instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
1.11      he        203:     instteeny=`basename $instlib | awk 'BEGIN { FS="." } { print $5 + 0 } '`
1.1       erh       204:
                    205:     # If they're greater than the source, complain.
                    206:     if [ "0$major" -eq "0$instmajor" ] ; then
1.10      he        207:        if [ "0$minor" -eq "0$instminor" ] ; then
1.11      he        208:            if [ "0$teeny" -lt "0$instteeny" ] ; then
1.10      he        209:                if [ $error -eq 0 -a $quiet -eq 0 ]; then
                    210:                    echo -n "The following libraries have versions greater"
                    211:                    echo " than the source:"
                    212:                fi
                    213:                echo $instlib > /dev/stderr
                    214:                error=1
                    215:            fi
                    216:         elif [ "0$minor" -lt "0$instminor" ] ; then
1.2       erh       217:            if [ $error -eq 0 -a $quiet -eq 0 ]; then
1.1       erh       218:                echo -n "The following libraries have versions greater"
                    219:                echo " than the source:"
                    220:            fi
                    221:            echo $instlib > /dev/stderr
                    222:            error=1
                    223:        fi
                    224:     elif [ "0$major" -lt "0$instmajor" ] ; then
1.2       erh       225:        if [ $error -eq 0 -a $quiet -eq 0 ] ; then
1.1       erh       226:            echo -n "The following libraries have versions greater"
                    227:            echo " than the source:"
                    228:        fi
                    229:        echo $instlib > /dev/stderr
                    230:        error=1
1.8       simonb    231:     fi
1.1       erh       232:  done
                    233:
                    234: exit $error

CVSweb <webmaster@jp.NetBSD.org>