checkver revision 1.2
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.2Serh# checkver [-q] -d [installedlibdir [library name]]" 401.2Serh# checkver [-q] -s [setlistdir [library name]]" 411.2Serh# checkver [-q] -f liblistfile [library name]" 421.1Serh# 431.1Serh# This script must be run from a directory in which 441.1Serh# a shlib_version file resides. 451.1Serh# 461.2Serh# One of -d, -s or -f must be specified. 471.1Serh# 481.2Serh# all: If library name is not specified it is assumed to 491.2Serh# be the name of the current directory. 501.2Serh# 511.2Serh# -d: Checks the version against the installed libraries. 521.2Serh# If no further arguments are given "/usr/lib" is 531.2Serh# used as the location of installed libraries. 541.2Serh# 551.2Serh# -s: Checks the version against the sets. If no argument 561.2Serh# follows the sets directory defaults to "/usr/src/distrib/sets/lists". 571.2Serh# The directory may be specified as either the top of the 581.2Serh# source tree or as the lists directory. 591.2Serh# 601.2Serh# -f: Checks the version against the provided list. A filename 611.2Serh# must be supplied. 621.1Serh# 631.1Serh# This script produces no output if all library version are not 641.1Serh# large than the source version. If an installed library with a 651.1Serh# version greater than the source is found, checkver prints a 661.1Serh# header and a list of the names of the offending installed libraries. 671.1Serh# 681.1Serh# The header may be supressed by passing "-q" as the first argument. 691.1Serh# 701.1Serh 711.2SerhTMP=/tmp/checkver.$$ 721.2Serhtrap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15 731.2Serhtrap "[ -d $TMP ] && rm -rf $TMP" 0 741.1Serh 751.1SerhUsage ( ) { 761.2Serh echo "Usage: $1 [-q] -d [installedlibdir [library name]]" 771.2Serh echo " $1 [-q] -s [setlistdir [library name]]" 781.2Serh echo " $1 [-q] -f liblistfile [library name]" 791.1Serh} 801.1Serh 811.2Serhbasedir=/usr/src 821.2Serhsetsdir=$basedir/distrib/sets/lists 831.2Serhlibdir=/usr/lib 841.1Serh 851.2Serherror=0 861.2Serhquiet=0 871.2Serhusedir=0 881.2Serhusefile=0 891.2Serhusesets=0 901.2SerhCWD=`pwd` 911.2Serhargs=`getopt "df:shq" "$@"` 921.2Serhif [ $? -ne 0 ] ; then 931.1Serh Usage $0 941.1Serh exit 0 951.1Serhfi 961.1Serh 971.2Serhset -- $args 981.2Serh 991.2Serhwhile . ; do 1001.2Serh case "$1" in 1011.2Serh -d) usedir=1 ; shift 1021.2Serh if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 1031.2Serh Usage $0 ; exit 2 1041.2Serh fi;; 1051.2Serh -f) usefile=1 ; arg1=$2 ; shift ; shift 1061.2Serh if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 1071.2Serh Usage $0 ; exit 2 1081.2Serh fi;; 1091.2Serh -s) usesets=1 ; shift 1101.2Serh if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 1111.2Serh Usage $0 ; exit 2 1121.2Serh fi;; 1131.2Serh -h) Usage $0 ; exit 0;; 1141.2Serh -q) quiet=1 ; shift;; 1151.2Serh --) shift ; break;; 1161.2Serh esac 1171.2Serhdone 1181.2Serh 1191.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then 1201.2Serh Usage $0 ; exit 2 1211.2Serhfi 1221.2Serh 1231.2Serhif [ $usefile -eq 1 ] ; then 1241.2Serh LIBLIST="$arg1" 1251.1Serhelse 1261.2Serh if ! mkdir -m 0700 $TMP ; then 1271.2Serh echo "$0: Unable to create temp directory." 1281.2Serh exit 2 1291.2Serh fi 1301.2Serh LIBLIST=$TMP/libs.lst 1311.2Serhfi 1321.2Serh 1331.2Serh# Build list from the installed libraries. 1341.2Serhif [ $usedir -eq 1 ] ; then 1351.2Serh if [ "X$1" != "X" ] ; then 1361.2Serh libdir="$1" 1371.2Serh fi 1381.2Serh find $libdir -name 'lib*.so.*.*' > $LIBLIST 1391.1Serhfi 1401.1Serh 1411.2Serh# Build list from set lists. Parameter may be either 1421.2Serh# the "lists" directory or the top of the source tree. 1431.2Serhif [ $usesets -eq 1 ] ; then 1441.2Serh if [ "X$1" != "X" ] ; then 1451.2Serh setsdir="$1" 1461.2Serh if [ -d "$setsdir/distrib/sets/lists" ] ; then 1471.2Serh setsdir="$setsdir/distrib/sets/lists" 1481.2Serh fi 1491.2Serh fi 1501.2Serh (cd $setsdir ; 1511.2Serh cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \ 1521.2Serh | sort -u > $LIBLIST 1531.2Serh ) 1541.1Serhfi 1551.1Serh 1561.2Serh# 1571.2Serh# The file $LIBLIST now contains a list of libraries. 1581.2Serh# 1591.2Serh 1601.1Serhif [ "X$2" = "X" ] ; then 1611.2Serh makefile=$CWD/Makefile 1621.2Serh libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'` 1631.2Serh 1641.2Serh # Assume the library name is the name of the current directory. 1651.2Serh if [ -z $libname ]; then 1661.2Serh libname=`basename $CWD` 1671.2Serh fi 1681.2Serhelse 1691.1Serh libname="$2" 1701.2Serhfi 1711.2Serhif ! echo $libname | grep -q "^lib" ; then 1721.2Serh libname="lib$libname" 1731.2Serhfi 1741.1Serh 1751.1Serh 1761.1Serhif [ ! -f ./shlib_version ] ; then 1771.1Serh echo "$0: unable to find ./shlib_version" 1781.2Serh exit 2 1791.1Serhfi 1801.1Serh 1811.1Serh# Grab major and minor numbers from the source. 1821.2Serh. ./shlib_version 1831.1Serh 1841.1Serhif [ "X$minor" = "X" -o "X$major" = "X" ] ; then 1851.1Serh echo "$0: shlib_version doesn't contain the version." 1861.2Serh exit 2 1871.1Serhfi 1881.1Serh 1891.1Serh# Find every shared object library with the same base name. 1901.2Serh for instlib in `grep $libname.so "$LIBLIST" ` ; do 1911.1Serh # Grab the major and minor from the installed library. 1921.2Serh instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '` 1931.2Serh instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '` 1941.1Serh 1951.1Serh # If they're greater than the source, complain. 1961.1Serh if [ "0$major" -eq "0$instmajor" ] ; then 1971.1Serh if [ "0$minor" -lt "0$instminor" ] ; then 1981.2Serh if [ $error -eq 0 -a $quiet -eq 0 ]; then 1991.1Serh echo -n "The following libraries have versions greater" 2001.1Serh echo " than the source:" 2011.1Serh fi 2021.1Serh echo $instlib > /dev/stderr 2031.1Serh error=1 2041.1Serh fi 2051.1Serh elif [ "0$major" -lt "0$instmajor" ] ; then 2061.2Serh if [ $error -eq 0 -a $quiet -eq 0 ] ; then 2071.1Serh echo -n "The following libraries have versions greater" 2081.1Serh echo " than the source:" 2091.1Serh fi 2101.1Serh echo $instlib > /dev/stderr 2111.1Serh error=1 2121.1Serh fi 2131.1Serh done 2141.1Serh 2151.1Serhexit $error 216