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