checkver revision 1.1
11.1Serh#!/bin/ksh
21.1Serh#
31.1Serh# Copyright (c) 1998 The NetBSD Foundation, Inc.
41.1Serh# All rights reserved.
51.1Serh#
61.1Serh# This code is derived from software contributed to The NetBSD Foundation
71.1Serh# by Eric Haszlakiewicz.
81.1Serh#
91.1Serh# Redistribution and use in source and binary forms, with or without
101.1Serh# modification, are permitted provided that the following conditions
111.1Serh# are met:
121.1Serh# 1. Redistributions of source code must retain the above copyright
131.1Serh#    notice, this list of conditions and the following disclaimer.
141.1Serh# 2. Redistributions in binary form must reproduce the above copyright
151.1Serh#    notice, this list of conditions and the following disclaimer in the
161.1Serh#    documentation and/or other materials provided with the distribution.
171.1Serh# 3. All advertising materials mentioning features or use of this software
181.1Serh#    must display the following acknowledgement:
191.1Serh#        This product includes software developed by the NetBSD
201.1Serh#        Foundation, Inc. and its contributors.
211.1Serh# 4. Neither the name of The NetBSD Foundation nor the names of its
221.1Serh#    contributors may be used to endorse or promote products derived
231.1Serh#    from this software without specific prior written permission.
241.1Serh#
251.1Serh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
261.1Serh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Serh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Serh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
291.1Serh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Serh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Serh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Serh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Serh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Serh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Serh# POSSIBILITY OF SUCH DAMAGE.
361.1Serh#
371.1Serh
381.1Serh#--------------------------------------------------------------------#
391.1Serh# checkver [-q] [installedlibdir [library name]]
401.1Serh#
411.1Serh# This script must be run from a directory in which
421.1Serh# a shlib_version file resides.
431.1Serh#
441.1Serh# If no arguments are passed the name of the current directory
451.1Serh# is assumed to be the name of the library.  The directory
461.1Serh# "/usr/lib" will be searched for problematic libraries.
471.1Serh#
481.1Serh# A list of directories of installed libraries may be specified.
491.1Serh# This will replace the default of "/usr/lib" and search there
501.1Serh# instead.
511.1Serh#
521.1Serh# An explicit library name may be passed.  If present, checkver
531.1Serh# will use this name when searching the installed libraries.
541.1Serh#
551.1Serh# This script produces no output if all library version are not 
561.1Serh# large than the source version.  If an installed library with a
571.1Serh# version greater than the source is found, checkver prints a
581.1Serh# header and a list of the names of the offending installed libraries.
591.1Serh#
601.1Serh# The header may be supressed by passing "-q" as the first argument.
611.1Serh#
621.1Serh
631.1Serhtrap "exit 1" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
641.1Serh
651.1Serherror=0
661.1Serh
671.1SerhUsage ( ) {
681.1Serh    echo "$1 [-q] [installedlibdir [library name]]"
691.1Serh}
701.1Serh
711.1Serh
721.1Serhif echo "$*" | egrep -q "[[:space:]]-h[[:space:]]|[[:space:]]--help*" ; then
731.1Serh    Usage $0
741.1Serh    exit 0
751.1Serhfi
761.1Serh
771.1Serhif [ "X$1" = "X-q" ] ; then
781.1Serh    # Supress header.
791.1Serh    quiet="1"
801.1Serh    shift
811.1Serhelse
821.1Serh    quiet="0"
831.1Serhfi
841.1Serh
851.1Serhif [ "X$1" != "X" ] ; then
861.1Serh    LIBDIR="$1"
871.1Serhelse
881.1Serh    LIBDIR="/usr/lib"
891.1Serhfi
901.1Serh
911.1Serhif [ "X$2" = "X" ] ; then
921.1Serh    # Assume the library name is the
931.1Serh    # name of the current directory.
941.1Serh    libname=`pwd`
951.1Serh    libname=`basename $libname`
961.1Serh else
971.1Serh    libname="$2"
981.1Serh fi
991.1Serh if ! echo $libname | grep -q "^lib" ; then
1001.1Serh   libname="lib$libname"
1011.1Serh fi
1021.1Serh
1031.1Serh
1041.1Serhif [ ! -f ./shlib_version ] ; then
1051.1Serh    echo "$0: unable to find ./shlib_version"
1061.1Serh    exit 1
1071.1Serhfi
1081.1Serh
1091.1Serh# Grab major and minor numbers from the source.
1101.1Serh . ./shlib_version
1111.1Serh
1121.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then
1131.1Serh    echo "$0: shlib_version doesn't contain the version."
1141.1Serh    exit 1
1151.1Serhfi
1161.1Serh
1171.1Serh# Find every shared object library with the same base name.
1181.1Serh for instlib in `find $LIBDIR -name "$libname.so.*"` ; do
1191.1Serh    # Grab the major and minor from the installed library.
1201.1Serh    instmajor=`echo $instlib | awk 'BEGIN { FS="." } { print $3 } '`
1211.1Serh    instminor=`echo $instlib | awk 'BEGIN { FS="." } { print $4 } '`
1221.1Serh
1231.1Serh    # If they're greater than the source, complain.
1241.1Serh    if [ "0$major" -eq "0$instmajor" ] ; then
1251.1Serh	if [ "0$minor" -lt "0$instminor" ] ; then
1261.1Serh	    if [ $error -eq 0 -a $quiet = "0"]; then
1271.1Serh		echo -n "The following libraries have versions greater"
1281.1Serh		echo " than the source:"
1291.1Serh	    fi
1301.1Serh	    echo $instlib > /dev/stderr
1311.1Serh	    error=1
1321.1Serh	fi
1331.1Serh    elif [ "0$major" -lt "0$instmajor" ] ; then
1341.1Serh	if [ $error -eq 0 -a $quiet = "0" ] ; then
1351.1Serh	    echo -n "The following libraries have versions greater"
1361.1Serh	    echo " than the source:"
1371.1Serh	fi
1381.1Serh	echo $instlib > /dev/stderr
1391.1Serh	error=1
1401.1Serh    fi 
1411.1Serh done
1421.1Serh
1431.1Serhexit $error
144