checkver revision 1.3
1#!/bin/ksh
2#	$NetBSD: checkver,v 1.3 1999/01/27 00:02:55 hubertf 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    find $libdir -name 'lib*.so.*.*' > $LIBLIST
140fi
141
142# Build list from set lists.  Parameter may be either
143# the "lists" directory or the top of the source tree.
144if [ $usesets -eq 1 ] ; then
145    if [ "X$1" != "X" ] ; then
146	setsdir="$1"
147	if [ -d "$setsdir/distrib/sets/lists" ] ; then
148	    setsdir="$setsdir/distrib/sets/lists"
149	fi
150    fi
151    (cd $setsdir ;
152     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
153		  | sort -u > $LIBLIST
154    )
155fi
156
157#
158# The file $LIBLIST now contains a list of libraries.
159#
160
161if [ "X$2" = "X" ] ; then
162    makefile=$CWD/Makefile
163    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
164
165    # Assume the library name is the name of the current directory.
166    if [ -z $libname ]; then
167	libname=`basename $CWD`
168    fi
169else
170    libname="$2"
171fi
172if ! echo $libname | grep -q "^lib" ; then
173    libname="lib$libname"
174fi
175
176
177if [ ! -f ./shlib_version ] ; then
178    echo "$0: unable to find ./shlib_version"
179    exit 2
180fi
181
182# Grab major and minor numbers from the source.
183. ./shlib_version
184
185if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
186    echo "$0: shlib_version doesn't contain the version."
187    exit 2
188fi
189
190# Find every shared object library with the same base name.
191 for instlib in `grep $libname.so "$LIBLIST" ` ; do
192    # Grab the major and minor from the installed library.
193    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
194    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
195
196    # If they're greater than the source, complain.
197    if [ "0$major" -eq "0$instmajor" ] ; then
198	if [ "0$minor" -lt "0$instminor" ] ; then
199	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
200		echo -n "The following libraries have versions greater"
201		echo " than the source:"
202	    fi
203	    echo $instlib > /dev/stderr
204	    error=1
205	fi
206    elif [ "0$major" -lt "0$instmajor" ] ; then
207	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
208	    echo -n "The following libraries have versions greater"
209	    echo " than the source:"
210	fi
211	echo $instlib > /dev/stderr
212	error=1
213    fi 
214 done
215
216exit $error
217