checkver revision 1.5
1#!/bin/sh
2#	$NetBSD: checkver,v 1.5 1999/03/16 18:57:31 christos 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.$$
73# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
74# internal malloc!
75trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
76trap "[ -d $TMP ] && rm -rf $TMP" 0
77
78Usage() {
79    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
80    echo "       $1 [-q] -s [setlistdir [library name]]"
81    echo "       $1 [-q] -f liblistfile [library name]"
82}
83
84basedir=/usr/src
85setsdir=$basedir/distrib/sets/lists
86libdir=/usr/lib
87
88error=0
89quiet=0
90usedir=0
91usefile=0
92usesets=0
93CWD=`pwd`
94args=`getopt "df:shq" "$@"`
95if [ $? -ne 0 ] ; then
96    Usage $0
97    exit 0
98fi
99
100set -- $args
101
102while . ; do
103    case "$1" in
104	-d) usedir=1 ; shift
105	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
106		Usage $0 ; exit 2
107	    fi;;
108	-f) usefile=1 ; arg1=$2 ; shift ; shift
109	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
110		Usage $0 ; exit 2
111	    fi;;
112	-s) usesets=1 ; shift
113	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
114		Usage $0 ; exit 2
115	    fi;;
116	-h) Usage $0 ; exit 0;;
117	-q) quiet=1 ; shift;;
118	--) shift ; break;;
119    esac
120done
121
122if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
123    Usage $0 ; exit 2
124fi
125
126if [ $usefile -eq 1 ] ; then
127   LIBLIST="$arg1"
128else
129   mkdir -m 0700 $TMP
130   if [ $?  != 0 ]; then
131	echo "$0: Unable to create temp directory."
132	exit 2
133   fi
134   LIBLIST=$TMP/libs.lst
135fi
136
137# Build list from the installed libraries.
138if [ $usedir -eq 1 ] ; then
139    if [ "X$1" != "X" ] ; then
140	libdir="$1"
141    fi
142    for f in $libdir ; do
143	ls $f/lib*.so.*.*
144    done > $LIBLIST
145fi
146
147# Build list from set lists.  Parameter may be either
148# the "lists" directory or the top of the source tree.
149if [ $usesets -eq 1 ] ; then
150    if [ "X$1" != "X" ] ; then
151	setsdir="$1"
152	if [ -d "$setsdir/distrib/sets/lists" ] ; then
153	    setsdir="$setsdir/distrib/sets/lists"
154	fi
155    fi
156    (cd $setsdir ;
157     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
158		  | sort -u > $LIBLIST
159    )
160fi
161
162#
163# The file $LIBLIST now contains a list of libraries.
164#
165
166if [ "X$2" = "X" ] ; then
167    makefile=$CWD/Makefile
168    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
169
170    # Assume the library name is the name of the current directory.
171    if [ -z $libname ]; then
172	libname=`basename $CWD`
173    fi
174else
175    libname="$2"
176fi
177echo $libname | grep "^lib" 1>&2 2> /dev/null
178if [ $? != 0 ]; then
179    libname="lib$libname"
180fi
181
182
183if [ ! -f ./shlib_version ] ; then
184    echo "$0: unable to find ./shlib_version"
185    exit 2
186fi
187
188# Grab major and minor numbers from the source.
189. ./shlib_version
190
191if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
192    echo "$0: shlib_version doesn't contain the version."
193    exit 2
194fi
195
196# Find every shared object library with the same base name.
197 for instlib in `grep $libname.so "$LIBLIST" ` ; do
198    # Grab the major and minor from the installed library.
199    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
200    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
201
202    # If they're greater than the source, complain.
203    if [ "0$major" -eq "0$instmajor" ] ; then
204	if [ "0$minor" -lt "0$instminor" ] ; then
205	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
206		echo -n "The following libraries have versions greater"
207		echo " than the source:"
208	    fi
209	    echo $instlib > /dev/stderr
210	    error=1
211	fi
212    elif [ "0$major" -lt "0$instmajor" ] ; then
213	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
214	    echo -n "The following libraries have versions greater"
215	    echo " than the source:"
216	fi
217	echo $instlib > /dev/stderr
218	error=1
219    fi 
220 done
221
222exit $error
223