1#!/bin/ksh 2# $NetBSD: checkver,v 1.4 1999/01/27 05:50:29 erh Exp $ 3# 4# Copyright (c) 1998 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Eric Haszlakiewicz. 9# 10# Redistribution and use in source and binary forms, with or without 11# modification, are permitted provided that the following conditions 12# are met: 13# 1. Redistributions of source code must retain the above copyright 14# notice, this list of conditions and the following disclaimer. 15# 2. Redistributions in binary form must reproduce the above copyright 16# notice, this list of conditions and the following disclaimer in the 17# documentation and/or other materials provided with the distribution. 18# 3. All advertising materials mentioning features or use of this software 19# must display the following acknowledgement: 20# This product includes software developed by the NetBSD 21# Foundation, Inc. and its contributors. 22# 4. Neither the name of The NetBSD Foundation nor the names of its 23# contributors may be used to endorse or promote products derived 24# from this software without specific prior written permission. 25# 26# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36# POSSIBILITY OF SUCH DAMAGE. 37# 38 39#--------------------------------------------------------------------# 40# checkver [-q] -d [installedlibdir [library name]]" 41# checkver [-q] -s [setlistdir [library name]]" 42# checkver [-q] -f liblistfile [library name]" 43# 44# This script must be run from a directory in which 45# a shlib_version file resides. 46# 47# One of -d, -s or -f must be specified. 48# 49# all: If library name is not specified it is assumed to 50# be the name of the current directory. 51# 52# -d: Checks the version against the installed libraries. 53# If no further arguments are given "/usr/lib" is 54# used as the location of installed libraries. 55# 56# -s: Checks the version against the sets. If no argument 57# follows the sets directory defaults to "/usr/src/distrib/sets/lists". 58# The directory may be specified as either the top of the 59# source tree or as the lists directory. 60# 61# -f: Checks the version against the provided list. A filename 62# must be supplied. 63# 64# This script produces no output if all library version are not 65# large than the source version. If an installed library with a 66# version greater than the source is found, checkver prints a 67# header and a list of the names of the offending installed libraries. 68# 69# The header may be supressed by passing "-q" as the first argument. 70# 71 72TMP=/tmp/checkver.$$ 73trap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15 74trap "[ -d $TMP ] && rm -rf $TMP" 0 75 76Usage ( ) { 77 echo "Usage: $1 [-q] -d [installedlibdir [library name]]" 78 echo " $1 [-q] -s [setlistdir [library name]]" 79 echo " $1 [-q] -f liblistfile [library name]" 80} 81 82basedir=/usr/src 83setsdir=$basedir/distrib/sets/lists 84libdir=/usr/lib 85 86error=0 87quiet=0 88usedir=0 89usefile=0 90usesets=0 91CWD=`pwd` 92args=`getopt "df:shq" "$@"` 93if [ $? -ne 0 ] ; then 94 Usage $0 95 exit 0 96fi 97 98set -- $args 99 100while . ; do 101 case "$1" in 102 -d) usedir=1 ; shift 103 if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 104 Usage $0 ; exit 2 105 fi;; 106 -f) usefile=1 ; arg1=$2 ; shift ; shift 107 if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 108 Usage $0 ; exit 2 109 fi;; 110 -s) usesets=1 ; shift 111 if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 112 Usage $0 ; exit 2 113 fi;; 114 -h) Usage $0 ; exit 0;; 115 -q) quiet=1 ; shift;; 116 --) shift ; break;; 117 esac 118done 119 120if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then 121 Usage $0 ; exit 2 122fi 123 124if [ $usefile -eq 1 ] ; then 125 LIBLIST="$arg1" 126else 127 if ! mkdir -m 0700 $TMP ; then 128 echo "$0: Unable to create temp directory." 129 exit 2 130 fi 131 LIBLIST=$TMP/libs.lst 132fi 133 134# Build list from the installed libraries. 135if [ $usedir -eq 1 ] ; then 136 if [ "X$1" != "X" ] ; then 137 libdir="$1" 138 fi 139 for f in $libdir ; do 140 ls $f/lib*.so.*.* 141 done > $LIBLIST 142fi 143 144# Build list from set lists. Parameter may be either 145# the "lists" directory or the top of the source tree. 146if [ $usesets -eq 1 ] ; then 147 if [ "X$1" != "X" ] ; then 148 setsdir="$1" 149 if [ -d "$setsdir/distrib/sets/lists" ] ; then 150 setsdir="$setsdir/distrib/sets/lists" 151 fi 152 fi 153 (cd $setsdir ; 154 cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \ 155 | sort -u > $LIBLIST 156 ) 157fi 158 159# 160# The file $LIBLIST now contains a list of libraries. 161# 162 163if [ "X$2" = "X" ] ; then 164 makefile=$CWD/Makefile 165 libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'` 166 167 # Assume the library name is the name of the current directory. 168 if [ -z $libname ]; then 169 libname=`basename $CWD` 170 fi 171else 172 libname="$2" 173fi 174if ! echo $libname | grep -q "^lib" ; then 175 libname="lib$libname" 176fi 177 178 179if [ ! -f ./shlib_version ] ; then 180 echo "$0: unable to find ./shlib_version" 181 exit 2 182fi 183 184# Grab major and minor numbers from the source. 185. ./shlib_version 186 187if [ "X$minor" = "X" -o "X$major" = "X" ] ; then 188 echo "$0: shlib_version doesn't contain the version." 189 exit 2 190fi 191 192# Find every shared object library with the same base name. 193 for instlib in `grep $libname.so "$LIBLIST" ` ; do 194 # Grab the major and minor from the installed library. 195 instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '` 196 instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '` 197 198 # If they're greater than the source, complain. 199 if [ "0$major" -eq "0$instmajor" ] ; then 200 if [ "0$minor" -lt "0$instminor" ] ; then 201 if [ $error -eq 0 -a $quiet -eq 0 ]; then 202 echo -n "The following libraries have versions greater" 203 echo " than the source:" 204 fi 205 echo $instlib > /dev/stderr 206 error=1 207 fi 208 elif [ "0$major" -lt "0$instmajor" ] ; then 209 if [ $error -eq 0 -a $quiet -eq 0 ] ; then 210 echo -n "The following libraries have versions greater" 211 echo " than the source:" 212 fi 213 echo $instlib > /dev/stderr 214 error=1 215 fi 216 done 217 218exit $error 219