checkver revision 1.8
11.5Schristos#!/bin/sh
21.8Ssimonb#	$NetBSD: checkver,v 1.8 1999/07/02 15:12:15 simonb 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.6Ssimonb# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
411.6Ssimonb# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
421.6Ssimonb# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
431.1Serh#
441.2Serh# One of -d, -s or -f must be specified.
451.1Serh#
461.2Serh# all: If library name is not specified it is assumed to
471.2Serh#	be the name of the current directory.
481.2Serh#
491.2Serh# -d: Checks the version against the installed libraries.
501.2Serh#	If no further arguments are given "/usr/lib" is
511.2Serh#	used as the location of installed libraries.
521.2Serh#
531.2Serh# -s: Checks the version against the sets.  If no argument
541.2Serh#	follows the sets directory defaults to "/usr/src/distrib/sets/lists".
551.2Serh#	The directory may be specified as either the top of the
561.2Serh#	source tree or as the lists directory.
571.2Serh#
581.2Serh# -f: Checks the version against the provided list.  A filename
591.2Serh#	must be supplied.
601.1Serh#
611.6Ssimonb# -v: Specify the filename of the shlib_version file.  Defaults
621.6Ssimonb#     to "./shlib_version".
631.6Ssimonb#
641.8Ssimonb# 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.5Schristos# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
741.5Schristos# internal malloc!
751.5Schristostrap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
761.2Serhtrap "[ -d $TMP ] && rm -rf $TMP" 0
771.1Serh
781.5SchristosUsage() {
791.2Serh    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
801.2Serh    echo "       $1 [-q] -s [setlistdir [library name]]"
811.2Serh    echo "       $1 [-q] -f liblistfile [library name]"
821.1Serh}
831.1Serh
841.2Serhbasedir=/usr/src
851.2Serhsetsdir=$basedir/distrib/sets/lists
861.2Serhlibdir=/usr/lib
871.6Ssimonbshlib_version=./shlib_version
881.1Serh
891.2Serherror=0
901.2Serhquiet=0
911.2Serhusedir=0
921.2Serhusefile=0
931.2Serhusesets=0
941.2SerhCWD=`pwd`
951.6Ssimonbargs=`getopt "df:shqv:" "$@"`
961.2Serhif [ $? -ne 0 ] ; then
971.1Serh    Usage $0
981.1Serh    exit 0
991.1Serhfi
1001.1Serh
1011.2Serhset -- $args
1021.2Serh
1031.7Schristoswhile [ ! -z "$1" ]; do
1041.2Serh    case "$1" in
1051.2Serh	-d) usedir=1 ; shift
1061.2Serh	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
1071.2Serh		Usage $0 ; exit 2
1081.2Serh	    fi;;
1091.2Serh	-f) usefile=1 ; arg1=$2 ; shift ; shift
1101.2Serh	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
1111.2Serh		Usage $0 ; exit 2
1121.2Serh	    fi;;
1131.2Serh	-s) usesets=1 ; shift
1141.2Serh	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
1151.2Serh		Usage $0 ; exit 2
1161.2Serh	    fi;;
1171.6Ssimonb	-v) shlib_version=$2; shift ; shift ;;
1181.2Serh	-h) Usage $0 ; exit 0;;
1191.2Serh	-q) quiet=1 ; shift;;
1201.2Serh	--) shift ; break;;
1211.2Serh    esac
1221.2Serhdone
1231.2Serh
1241.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
1251.2Serh    Usage $0 ; exit 2
1261.2Serhfi
1271.2Serh
1281.2Serhif [ $usefile -eq 1 ] ; then
1291.2Serh   LIBLIST="$arg1"
1301.1Serhelse
1311.5Schristos   mkdir -m 0700 $TMP
1321.5Schristos   if [ $?  != 0 ]; then
1331.2Serh	echo "$0: Unable to create temp directory."
1341.2Serh	exit 2
1351.2Serh   fi
1361.2Serh   LIBLIST=$TMP/libs.lst
1371.2Serhfi
1381.2Serh
1391.2Serh# Build list from the installed libraries.
1401.2Serhif [ $usedir -eq 1 ] ; then
1411.2Serh    if [ "X$1" != "X" ] ; then
1421.2Serh	libdir="$1"
1431.2Serh    fi
1441.4Serh    for f in $libdir ; do
1451.4Serh	ls $f/lib*.so.*.*
1461.4Serh    done > $LIBLIST
1471.1Serhfi
1481.1Serh
1491.2Serh# Build list from set lists.  Parameter may be either
1501.2Serh# the "lists" directory or the top of the source tree.
1511.2Serhif [ $usesets -eq 1 ] ; then
1521.2Serh    if [ "X$1" != "X" ] ; then
1531.2Serh	setsdir="$1"
1541.2Serh	if [ -d "$setsdir/distrib/sets/lists" ] ; then
1551.2Serh	    setsdir="$setsdir/distrib/sets/lists"
1561.2Serh	fi
1571.2Serh    fi
1581.2Serh    (cd $setsdir ;
1591.2Serh     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
1601.2Serh		  | sort -u > $LIBLIST
1611.2Serh    )
1621.1Serhfi
1631.1Serh
1641.2Serh#
1651.2Serh# The file $LIBLIST now contains a list of libraries.
1661.2Serh#
1671.2Serh
1681.1Serhif [ "X$2" = "X" ] ; then
1691.2Serh    makefile=$CWD/Makefile
1701.2Serh    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
1711.2Serh
1721.2Serh    # Assume the library name is the name of the current directory.
1731.2Serh    if [ -z $libname ]; then
1741.2Serh	libname=`basename $CWD`
1751.2Serh    fi
1761.2Serhelse
1771.1Serh    libname="$2"
1781.2Serhfi
1791.5Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null
1801.5Schristosif [ $? != 0 ]; then
1811.2Serh    libname="lib$libname"
1821.2Serhfi
1831.1Serh
1841.1Serh
1851.6Ssimonbif [ ! -f $shlib_version ] ; then
1861.6Ssimonb    echo "$0: unable to find $shlib_version"
1871.2Serh    exit 2
1881.1Serhfi
1891.1Serh
1901.1Serh# Grab major and minor numbers from the source.
1911.6Ssimonb. $shlib_version
1921.1Serh
1931.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then
1941.6Ssimonb    echo "$0: $shlib_version doesn't contain the version."
1951.2Serh    exit 2
1961.1Serhfi
1971.1Serh
1981.1Serh# Find every shared object library with the same base name.
1991.2Serh for instlib in `grep $libname.so "$LIBLIST" ` ; do
2001.1Serh    # Grab the major and minor from the installed library.
2011.2Serh    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
2021.2Serh    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
2031.1Serh
2041.1Serh    # If they're greater than the source, complain.
2051.1Serh    if [ "0$major" -eq "0$instmajor" ] ; then
2061.1Serh	if [ "0$minor" -lt "0$instminor" ] ; then
2071.2Serh	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
2081.1Serh		echo -n "The following libraries have versions greater"
2091.1Serh		echo " than the source:"
2101.1Serh	    fi
2111.1Serh	    echo $instlib > /dev/stderr
2121.1Serh	    error=1
2131.1Serh	fi
2141.1Serh    elif [ "0$major" -lt "0$instmajor" ] ; then
2151.2Serh	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
2161.1Serh	    echo -n "The following libraries have versions greater"
2171.1Serh	    echo " than the source:"
2181.1Serh	fi
2191.1Serh	echo $instlib > /dev/stderr
2201.1Serh	error=1
2211.8Ssimonb    fi
2221.1Serh done
2231.1Serh
2241.1Serhexit $error
225