checkver revision 1.4
11.1Serh#!/bin/ksh
21.4Serh#	$NetBSD: checkver,v 1.4 1999/01/27 05:50:29 erh Exp $
31.1Serh#
41.1Serh# Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Serh# All rights reserved.
61.1Serh#
71.1Serh# This code is derived from software contributed to The NetBSD Foundation
81.1Serh# by Eric Haszlakiewicz.
91.1Serh#
101.1Serh# Redistribution and use in source and binary forms, with or without
111.1Serh# modification, are permitted provided that the following conditions
121.1Serh# are met:
131.1Serh# 1. Redistributions of source code must retain the above copyright
141.1Serh#    notice, this list of conditions and the following disclaimer.
151.1Serh# 2. Redistributions in binary form must reproduce the above copyright
161.1Serh#    notice, this list of conditions and the following disclaimer in the
171.1Serh#    documentation and/or other materials provided with the distribution.
181.1Serh# 3. All advertising materials mentioning features or use of this software
191.1Serh#    must display the following acknowledgement:
201.1Serh#        This product includes software developed by the NetBSD
211.1Serh#        Foundation, Inc. and its contributors.
221.1Serh# 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Serh#    contributors may be used to endorse or promote products derived
241.1Serh#    from this software without specific prior written permission.
251.1Serh#
261.1Serh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Serh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Serh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Serh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Serh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Serh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Serh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Serh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Serh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Serh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Serh# POSSIBILITY OF SUCH DAMAGE.
371.1Serh#
381.1Serh
391.1Serh#--------------------------------------------------------------------#
401.2Serh# checkver [-q] -d [installedlibdir [library name]]"
411.2Serh# checkver [-q] -s [setlistdir [library name]]"
421.2Serh# checkver [-q] -f liblistfile [library name]"
431.1Serh#
441.1Serh# This script must be run from a directory in which
451.1Serh# a shlib_version file resides.
461.1Serh#
471.2Serh# One of -d, -s or -f must be specified.
481.1Serh#
491.2Serh# all: If library name is not specified it is assumed to
501.2Serh#	be the name of the current directory.
511.2Serh#
521.2Serh# -d: Checks the version against the installed libraries.
531.2Serh#	If no further arguments are given "/usr/lib" is
541.2Serh#	used as the location of installed libraries.
551.2Serh#
561.2Serh# -s: Checks the version against the sets.  If no argument
571.2Serh#	follows the sets directory defaults to "/usr/src/distrib/sets/lists".
581.2Serh#	The directory may be specified as either the top of the
591.2Serh#	source tree or as the lists directory.
601.2Serh#
611.2Serh# -f: Checks the version against the provided list.  A filename
621.2Serh#	must be supplied.
631.1Serh#
641.1Serh# This script produces no output if all library version are not 
651.1Serh# large than the source version.  If an installed library with a
661.1Serh# version greater than the source is found, checkver prints a
671.1Serh# header and a list of the names of the offending installed libraries.
681.1Serh#
691.1Serh# The header may be supressed by passing "-q" as the first argument.
701.1Serh#
711.1Serh
721.2SerhTMP=/tmp/checkver.$$
731.2Serhtrap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
741.2Serhtrap "[ -d $TMP ] && rm -rf $TMP" 0
751.1Serh
761.1SerhUsage ( ) {
771.2Serh    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
781.2Serh    echo "       $1 [-q] -s [setlistdir [library name]]"
791.2Serh    echo "       $1 [-q] -f liblistfile [library name]"
801.1Serh}
811.1Serh
821.2Serhbasedir=/usr/src
831.2Serhsetsdir=$basedir/distrib/sets/lists
841.2Serhlibdir=/usr/lib
851.1Serh
861.2Serherror=0
871.2Serhquiet=0
881.2Serhusedir=0
891.2Serhusefile=0
901.2Serhusesets=0
911.2SerhCWD=`pwd`
921.2Serhargs=`getopt "df:shq" "$@"`
931.2Serhif [ $? -ne 0 ] ; then
941.1Serh    Usage $0
951.1Serh    exit 0
961.1Serhfi
971.1Serh
981.2Serhset -- $args
991.2Serh
1001.2Serhwhile . ; do
1011.2Serh    case "$1" in
1021.2Serh	-d) usedir=1 ; shift
1031.2Serh	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
1041.2Serh		Usage $0 ; exit 2
1051.2Serh	    fi;;
1061.2Serh	-f) usefile=1 ; arg1=$2 ; shift ; shift
1071.2Serh	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
1081.2Serh		Usage $0 ; exit 2
1091.2Serh	    fi;;
1101.2Serh	-s) usesets=1 ; shift
1111.2Serh	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
1121.2Serh		Usage $0 ; exit 2
1131.2Serh	    fi;;
1141.2Serh	-h) Usage $0 ; exit 0;;
1151.2Serh	-q) quiet=1 ; shift;;
1161.2Serh	--) shift ; break;;
1171.2Serh    esac
1181.2Serhdone
1191.2Serh
1201.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
1211.2Serh    Usage $0 ; exit 2
1221.2Serhfi
1231.2Serh
1241.2Serhif [ $usefile -eq 1 ] ; then
1251.2Serh   LIBLIST="$arg1"
1261.1Serhelse
1271.2Serh   if ! mkdir -m 0700 $TMP ; then
1281.2Serh	echo "$0: Unable to create temp directory."
1291.2Serh	exit 2
1301.2Serh   fi
1311.2Serh   LIBLIST=$TMP/libs.lst
1321.2Serhfi
1331.2Serh
1341.2Serh# Build list from the installed libraries.
1351.2Serhif [ $usedir -eq 1 ] ; then
1361.2Serh    if [ "X$1" != "X" ] ; then
1371.2Serh	libdir="$1"
1381.2Serh    fi
1391.4Serh    for f in $libdir ; do
1401.4Serh	ls $f/lib*.so.*.*
1411.4Serh    done > $LIBLIST
1421.1Serhfi
1431.1Serh
1441.2Serh# Build list from set lists.  Parameter may be either
1451.2Serh# the "lists" directory or the top of the source tree.
1461.2Serhif [ $usesets -eq 1 ] ; then
1471.2Serh    if [ "X$1" != "X" ] ; then
1481.2Serh	setsdir="$1"
1491.2Serh	if [ -d "$setsdir/distrib/sets/lists" ] ; then
1501.2Serh	    setsdir="$setsdir/distrib/sets/lists"
1511.2Serh	fi
1521.2Serh    fi
1531.2Serh    (cd $setsdir ;
1541.2Serh     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
1551.2Serh		  | sort -u > $LIBLIST
1561.2Serh    )
1571.1Serhfi
1581.1Serh
1591.2Serh#
1601.2Serh# The file $LIBLIST now contains a list of libraries.
1611.2Serh#
1621.2Serh
1631.1Serhif [ "X$2" = "X" ] ; then
1641.2Serh    makefile=$CWD/Makefile
1651.2Serh    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
1661.2Serh
1671.2Serh    # Assume the library name is the name of the current directory.
1681.2Serh    if [ -z $libname ]; then
1691.2Serh	libname=`basename $CWD`
1701.2Serh    fi
1711.2Serhelse
1721.1Serh    libname="$2"
1731.2Serhfi
1741.2Serhif ! echo $libname | grep -q "^lib" ; then
1751.2Serh    libname="lib$libname"
1761.2Serhfi
1771.1Serh
1781.1Serh
1791.1Serhif [ ! -f ./shlib_version ] ; then
1801.1Serh    echo "$0: unable to find ./shlib_version"
1811.2Serh    exit 2
1821.1Serhfi
1831.1Serh
1841.1Serh# Grab major and minor numbers from the source.
1851.2Serh. ./shlib_version
1861.1Serh
1871.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then
1881.1Serh    echo "$0: shlib_version doesn't contain the version."
1891.2Serh    exit 2
1901.1Serhfi
1911.1Serh
1921.1Serh# Find every shared object library with the same base name.
1931.2Serh for instlib in `grep $libname.so "$LIBLIST" ` ; do
1941.1Serh    # Grab the major and minor from the installed library.
1951.2Serh    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
1961.2Serh    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
1971.1Serh
1981.1Serh    # If they're greater than the source, complain.
1991.1Serh    if [ "0$major" -eq "0$instmajor" ] ; then
2001.1Serh	if [ "0$minor" -lt "0$instminor" ] ; then
2011.2Serh	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
2021.1Serh		echo -n "The following libraries have versions greater"
2031.1Serh		echo " than the source:"
2041.1Serh	    fi
2051.1Serh	    echo $instlib > /dev/stderr
2061.1Serh	    error=1
2071.1Serh	fi
2081.1Serh    elif [ "0$major" -lt "0$instmajor" ] ; then
2091.2Serh	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
2101.1Serh	    echo -n "The following libraries have versions greater"
2111.1Serh	    echo " than the source:"
2121.1Serh	fi
2131.1Serh	echo $instlib > /dev/stderr
2141.1Serh	error=1
2151.1Serh    fi 
2161.1Serh done
2171.1Serh
2181.1Serhexit $error
219