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