checkver revision 1.5
11.5Schristos#!/bin/sh 21.5Schristos# $NetBSD: checkver,v 1.5 1999/03/16 18:57:31 christos 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.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.1Serh 881.2Serherror=0 891.2Serhquiet=0 901.2Serhusedir=0 911.2Serhusefile=0 921.2Serhusesets=0 931.2SerhCWD=`pwd` 941.2Serhargs=`getopt "df:shq" "$@"` 951.2Serhif [ $? -ne 0 ] ; then 961.1Serh Usage $0 971.1Serh exit 0 981.1Serhfi 991.1Serh 1001.2Serhset -- $args 1011.2Serh 1021.2Serhwhile . ; do 1031.2Serh case "$1" in 1041.2Serh -d) usedir=1 ; shift 1051.2Serh if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 1061.2Serh Usage $0 ; exit 2 1071.2Serh fi;; 1081.2Serh -f) usefile=1 ; arg1=$2 ; shift ; shift 1091.2Serh if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 1101.2Serh Usage $0 ; exit 2 1111.2Serh fi;; 1121.2Serh -s) usesets=1 ; shift 1131.2Serh if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 1141.2Serh Usage $0 ; exit 2 1151.2Serh fi;; 1161.2Serh -h) Usage $0 ; exit 0;; 1171.2Serh -q) quiet=1 ; shift;; 1181.2Serh --) shift ; break;; 1191.2Serh esac 1201.2Serhdone 1211.2Serh 1221.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then 1231.2Serh Usage $0 ; exit 2 1241.2Serhfi 1251.2Serh 1261.2Serhif [ $usefile -eq 1 ] ; then 1271.2Serh LIBLIST="$arg1" 1281.1Serhelse 1291.5Schristos mkdir -m 0700 $TMP 1301.5Schristos if [ $? != 0 ]; then 1311.2Serh echo "$0: Unable to create temp directory." 1321.2Serh exit 2 1331.2Serh fi 1341.2Serh LIBLIST=$TMP/libs.lst 1351.2Serhfi 1361.2Serh 1371.2Serh# Build list from the installed libraries. 1381.2Serhif [ $usedir -eq 1 ] ; then 1391.2Serh if [ "X$1" != "X" ] ; then 1401.2Serh libdir="$1" 1411.2Serh fi 1421.4Serh for f in $libdir ; do 1431.4Serh ls $f/lib*.so.*.* 1441.4Serh done > $LIBLIST 1451.1Serhfi 1461.1Serh 1471.2Serh# Build list from set lists. Parameter may be either 1481.2Serh# the "lists" directory or the top of the source tree. 1491.2Serhif [ $usesets -eq 1 ] ; then 1501.2Serh if [ "X$1" != "X" ] ; then 1511.2Serh setsdir="$1" 1521.2Serh if [ -d "$setsdir/distrib/sets/lists" ] ; then 1531.2Serh setsdir="$setsdir/distrib/sets/lists" 1541.2Serh fi 1551.2Serh fi 1561.2Serh (cd $setsdir ; 1571.2Serh cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \ 1581.2Serh | sort -u > $LIBLIST 1591.2Serh ) 1601.1Serhfi 1611.1Serh 1621.2Serh# 1631.2Serh# The file $LIBLIST now contains a list of libraries. 1641.2Serh# 1651.2Serh 1661.1Serhif [ "X$2" = "X" ] ; then 1671.2Serh makefile=$CWD/Makefile 1681.2Serh libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'` 1691.2Serh 1701.2Serh # Assume the library name is the name of the current directory. 1711.2Serh if [ -z $libname ]; then 1721.2Serh libname=`basename $CWD` 1731.2Serh fi 1741.2Serhelse 1751.1Serh libname="$2" 1761.2Serhfi 1771.5Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null 1781.5Schristosif [ $? != 0 ]; then 1791.2Serh libname="lib$libname" 1801.2Serhfi 1811.1Serh 1821.1Serh 1831.1Serhif [ ! -f ./shlib_version ] ; then 1841.1Serh echo "$0: unable to find ./shlib_version" 1851.2Serh exit 2 1861.1Serhfi 1871.1Serh 1881.1Serh# Grab major and minor numbers from the source. 1891.2Serh. ./shlib_version 1901.1Serh 1911.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then 1921.1Serh echo "$0: shlib_version doesn't contain the version." 1931.2Serh exit 2 1941.1Serhfi 1951.1Serh 1961.1Serh# Find every shared object library with the same base name. 1971.2Serh for instlib in `grep $libname.so "$LIBLIST" ` ; do 1981.1Serh # Grab the major and minor from the installed library. 1991.2Serh instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '` 2001.2Serh instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '` 2011.1Serh 2021.1Serh # If they're greater than the source, complain. 2031.1Serh if [ "0$major" -eq "0$instmajor" ] ; then 2041.1Serh if [ "0$minor" -lt "0$instminor" ] ; then 2051.2Serh if [ $error -eq 0 -a $quiet -eq 0 ]; then 2061.1Serh echo -n "The following libraries have versions greater" 2071.1Serh echo " than the source:" 2081.1Serh fi 2091.1Serh echo $instlib > /dev/stderr 2101.1Serh error=1 2111.1Serh fi 2121.1Serh elif [ "0$major" -lt "0$instmajor" ] ; then 2131.2Serh if [ $error -eq 0 -a $quiet -eq 0 ] ; then 2141.1Serh echo -n "The following libraries have versions greater" 2151.1Serh echo " than the source:" 2161.1Serh fi 2171.1Serh echo $instlib > /dev/stderr 2181.1Serh error=1 2191.1Serh fi 2201.1Serh done 2211.1Serh 2221.1Serhexit $error 223