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