checkver revision 1.9
11.5Schristos#!/bin/sh
21.9Serh#	$NetBSD: checkver,v 1.9 1999/11/05 20:16:56 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.9Serh# checkver - 
411.9Serh#	Check for libraries that appear to be newer than the
421.9Serh#	one we're about to install.
431.9Serh#
441.6Ssimonb# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
451.6Ssimonb# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
461.6Ssimonb# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
471.1Serh#
481.2Serh# One of -d, -s or -f must be specified.
491.1Serh#
501.2Serh# all: If library name is not specified it is assumed to
511.2Serh#	be the name of the current directory.
521.2Serh#
531.2Serh# -d: Checks the version against the installed libraries.
541.2Serh#	If no further arguments are given "/usr/lib" is
551.2Serh#	used as the location of installed libraries.
561.2Serh#
571.2Serh# -s: Checks the version against the sets.  If no argument
581.2Serh#	follows the sets directory defaults to "/usr/src/distrib/sets/lists".
591.2Serh#	The directory may be specified as either the top of the
601.2Serh#	source tree or as the lists directory.
611.2Serh#
621.2Serh# -f: Checks the version against the provided list.  A filename
631.2Serh#	must be supplied.
641.1Serh#
651.6Ssimonb# -v: Specify the filename of the shlib_version file.  Defaults
661.6Ssimonb#     to "./shlib_version".
671.6Ssimonb#
681.8Ssimonb# This script produces no output if all library version are not
691.1Serh# large than the source version.  If an installed library with a
701.1Serh# version greater than the source is found, checkver prints a
711.1Serh# header and a list of the names of the offending installed libraries.
721.1Serh#
731.1Serh# The header may be supressed by passing "-q" as the first argument.
741.1Serh#
751.1Serh
761.2SerhTMP=/tmp/checkver.$$
771.5Schristos# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
781.5Schristos# internal malloc!
791.5Schristostrap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
801.2Serhtrap "[ -d $TMP ] && rm -rf $TMP" 0
811.1Serh
821.5SchristosUsage() {
831.9Serh    echo "Usage: $1 [-q] [-v version_file] -d [installedlibdir [library name]]"
841.9Serh    echo "       $1 [-q] [-v version_file] -s [setlistdir [library name]]"
851.9Serh    echo "       $1 [-q] [-v version_file] -f liblistfile [library name]"
861.9Serh    echo "	$1 is a script that looks for installed libraries with"
871.9Serh    echo "	   versions greater than that in the version file."
881.9Serh    echo "	For more information, read the comments."
891.1Serh}
901.1Serh
911.2Serhbasedir=/usr/src
921.2Serhsetsdir=$basedir/distrib/sets/lists
931.2Serhlibdir=/usr/lib
941.6Ssimonbshlib_version=./shlib_version
951.1Serh
961.2Serherror=0
971.2Serhquiet=0
981.2Serhusedir=0
991.2Serhusefile=0
1001.2Serhusesets=0
1011.2SerhCWD=`pwd`
1021.6Ssimonbargs=`getopt "df:shqv:" "$@"`
1031.2Serhif [ $? -ne 0 ] ; then
1041.1Serh    Usage $0
1051.1Serh    exit 0
1061.1Serhfi
1071.1Serh
1081.2Serhset -- $args
1091.2Serh
1101.7Schristoswhile [ ! -z "$1" ]; do
1111.2Serh    case "$1" in
1121.2Serh	-d) usedir=1 ; shift
1131.2Serh	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
1141.2Serh		Usage $0 ; exit 2
1151.2Serh	    fi;;
1161.2Serh	-f) usefile=1 ; arg1=$2 ; shift ; shift
1171.2Serh	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
1181.2Serh		Usage $0 ; exit 2
1191.2Serh	    fi;;
1201.2Serh	-s) usesets=1 ; shift
1211.2Serh	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
1221.2Serh		Usage $0 ; exit 2
1231.2Serh	    fi;;
1241.6Ssimonb	-v) shlib_version=$2; shift ; shift ;;
1251.2Serh	-h) Usage $0 ; exit 0;;
1261.2Serh	-q) quiet=1 ; shift;;
1271.2Serh	--) shift ; break;;
1281.2Serh    esac
1291.2Serhdone
1301.2Serh
1311.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
1321.2Serh    Usage $0 ; exit 2
1331.2Serhfi
1341.2Serh
1351.2Serhif [ $usefile -eq 1 ] ; then
1361.2Serh   LIBLIST="$arg1"
1371.1Serhelse
1381.5Schristos   mkdir -m 0700 $TMP
1391.5Schristos   if [ $?  != 0 ]; then
1401.2Serh	echo "$0: Unable to create temp directory."
1411.2Serh	exit 2
1421.2Serh   fi
1431.2Serh   LIBLIST=$TMP/libs.lst
1441.2Serhfi
1451.2Serh
1461.2Serh# Build list from the installed libraries.
1471.2Serhif [ $usedir -eq 1 ] ; then
1481.2Serh    if [ "X$1" != "X" ] ; then
1491.2Serh	libdir="$1"
1501.2Serh    fi
1511.4Serh    for f in $libdir ; do
1521.4Serh	ls $f/lib*.so.*.*
1531.4Serh    done > $LIBLIST
1541.1Serhfi
1551.1Serh
1561.2Serh# Build list from set lists.  Parameter may be either
1571.2Serh# the "lists" directory or the top of the source tree.
1581.2Serhif [ $usesets -eq 1 ] ; then
1591.2Serh    if [ "X$1" != "X" ] ; then
1601.2Serh	setsdir="$1"
1611.2Serh	if [ -d "$setsdir/distrib/sets/lists" ] ; then
1621.2Serh	    setsdir="$setsdir/distrib/sets/lists"
1631.2Serh	fi
1641.2Serh    fi
1651.2Serh    (cd $setsdir ;
1661.2Serh     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
1671.2Serh		  | sort -u > $LIBLIST
1681.2Serh    )
1691.1Serhfi
1701.1Serh
1711.2Serh#
1721.2Serh# The file $LIBLIST now contains a list of libraries.
1731.2Serh#
1741.2Serh
1751.1Serhif [ "X$2" = "X" ] ; then
1761.2Serh    makefile=$CWD/Makefile
1771.2Serh    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
1781.2Serh
1791.2Serh    # Assume the library name is the name of the current directory.
1801.2Serh    if [ -z $libname ]; then
1811.2Serh	libname=`basename $CWD`
1821.2Serh    fi
1831.2Serhelse
1841.1Serh    libname="$2"
1851.2Serhfi
1861.5Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null
1871.5Schristosif [ $? != 0 ]; then
1881.2Serh    libname="lib$libname"
1891.2Serhfi
1901.1Serh
1911.1Serh
1921.6Ssimonbif [ ! -f $shlib_version ] ; then
1931.6Ssimonb    echo "$0: unable to find $shlib_version"
1941.2Serh    exit 2
1951.1Serhfi
1961.1Serh
1971.1Serh# Grab major and minor numbers from the source.
1981.6Ssimonb. $shlib_version
1991.1Serh
2001.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then
2011.6Ssimonb    echo "$0: $shlib_version doesn't contain the version."
2021.2Serh    exit 2
2031.1Serhfi
2041.1Serh
2051.1Serh# Find every shared object library with the same base name.
2061.2Serh for instlib in `grep $libname.so "$LIBLIST" ` ; do
2071.1Serh    # Grab the major and minor from the installed library.
2081.2Serh    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
2091.2Serh    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
2101.1Serh
2111.1Serh    # If they're greater than the source, complain.
2121.1Serh    if [ "0$major" -eq "0$instmajor" ] ; then
2131.1Serh	if [ "0$minor" -lt "0$instminor" ] ; then
2141.2Serh	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
2151.1Serh		echo -n "The following libraries have versions greater"
2161.1Serh		echo " than the source:"
2171.1Serh	    fi
2181.1Serh	    echo $instlib > /dev/stderr
2191.1Serh	    error=1
2201.1Serh	fi
2211.1Serh    elif [ "0$major" -lt "0$instmajor" ] ; then
2221.2Serh	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
2231.1Serh	    echo -n "The following libraries have versions greater"
2241.1Serh	    echo " than the source:"
2251.1Serh	fi
2261.1Serh	echo $instlib > /dev/stderr
2271.1Serh	error=1
2281.8Ssimonb    fi
2291.1Serh done
2301.1Serh
2311.1Serhexit $error
232