Home | History | Annotate | Line # | Download | only in lib
checkver revision 1.1
      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] [installedlibdir [library name]]
     40 #
     41 # This script must be run from a directory in which
     42 # a shlib_version file resides.
     43 #
     44 # If no arguments are passed the name of the current directory
     45 # is assumed to be the name of the library.  The directory
     46 # "/usr/lib" will be searched for problematic libraries.
     47 #
     48 # A list of directories of installed libraries may be specified.
     49 # This will replace the default of "/usr/lib" and search there
     50 # instead.
     51 #
     52 # An explicit library name may be passed.  If present, checkver
     53 # will use this name when searching the installed libraries.
     54 #
     55 # This script produces no output if all library version are not 
     56 # large than the source version.  If an installed library with a
     57 # version greater than the source is found, checkver prints a
     58 # header and a list of the names of the offending installed libraries.
     59 #
     60 # The header may be supressed by passing "-q" as the first argument.
     61 #
     62 
     63 trap "exit 1" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
     64 
     65 error=0
     66 
     67 Usage ( ) {
     68     echo "$1 [-q] [installedlibdir [library name]]"
     69 }
     70 
     71 
     72 if echo "$*" | egrep -q "[[:space:]]-h[[:space:]]|[[:space:]]--help*" ; then
     73     Usage $0
     74     exit 0
     75 fi
     76 
     77 if [ "X$1" = "X-q" ] ; then
     78     # Supress header.
     79     quiet="1"
     80     shift
     81 else
     82     quiet="0"
     83 fi
     84 
     85 if [ "X$1" != "X" ] ; then
     86     LIBDIR="$1"
     87 else
     88     LIBDIR="/usr/lib"
     89 fi
     90 
     91 if [ "X$2" = "X" ] ; then
     92     # Assume the library name is the
     93     # name of the current directory.
     94     libname=`pwd`
     95     libname=`basename $libname`
     96  else
     97     libname="$2"
     98  fi
     99  if ! echo $libname | grep -q "^lib" ; then
    100    libname="lib$libname"
    101  fi
    102 
    103 
    104 if [ ! -f ./shlib_version ] ; then
    105     echo "$0: unable to find ./shlib_version"
    106     exit 1
    107 fi
    108 
    109 # Grab major and minor numbers from the source.
    110  . ./shlib_version
    111 
    112 if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
    113     echo "$0: shlib_version doesn't contain the version."
    114     exit 1
    115 fi
    116 
    117 # Find every shared object library with the same base name.
    118  for instlib in `find $LIBDIR -name "$libname.so.*"` ; do
    119     # Grab the major and minor from the installed library.
    120     instmajor=`echo $instlib | awk 'BEGIN { FS="." } { print $3 } '`
    121     instminor=`echo $instlib | awk 'BEGIN { FS="." } { print $4 } '`
    122 
    123     # If they're greater than the source, complain.
    124     if [ "0$major" -eq "0$instmajor" ] ; then
    125 	if [ "0$minor" -lt "0$instminor" ] ; then
    126 	    if [ $error -eq 0 -a $quiet = "0"]; then
    127 		echo -n "The following libraries have versions greater"
    128 		echo " than the source:"
    129 	    fi
    130 	    echo $instlib > /dev/stderr
    131 	    error=1
    132 	fi
    133     elif [ "0$major" -lt "0$instmajor" ] ; then
    134 	if [ $error -eq 0 -a $quiet = "0" ] ; then
    135 	    echo -n "The following libraries have versions greater"
    136 	    echo " than the source:"
    137 	fi
    138 	echo $instlib > /dev/stderr
    139 	error=1
    140     fi 
    141  done
    142 
    143 exit $error
    144