xref: /netbsd/lib/checkver (revision bf9ec67e)
1#!/bin/sh
2#	$NetBSD: checkver,v 1.12 2000/07/22 16:04:57 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 -
41#	Check for libraries that appear to be newer than the
42#	one we're about to install.
43#
44# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
45# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
46# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
47#
48# One of -d, -s or -f must be specified.
49#
50# all: If library name is not specified it is assumed to
51#	be the name of the current directory.
52#
53# -d: Checks the version against the installed libraries.
54#	If no further arguments are given "/usr/lib" is
55#	used as the location of installed libraries.
56#
57# -s: Checks the version against the sets.  If no argument
58#	follows the sets directory defaults to "/usr/src/distrib/sets/lists".
59#	The directory may be specified as either the top of the
60#	source tree or as the lists directory.
61#
62# -f: Checks the version against the provided list.  A filename
63#	must be supplied.
64#
65# -v: Specify the filename of the shlib_version file.  Defaults
66#     to "./shlib_version".
67#
68# This script produces no output if all library version are not
69# large than the source version.  If an installed library with a
70# version greater than the source is found, checkver prints a
71# header and a list of the names of the offending installed libraries.
72#
73# The header may be supressed by passing "-q" as the first argument.
74#
75
76TMP=/tmp/checkver.$$
77# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
78# internal malloc!
79trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
80trap "[ -d $TMP ] && rm -rf $TMP" 0
81
82Usage() {
83    echo "Usage: $1 [-q] [-v version_file] -d [installedlibdir [library name]]"
84    echo "       $1 [-q] [-v version_file] -s [setlistdir [library name]]"
85    echo "       $1 [-q] [-v version_file] -f liblistfile [library name]"
86    echo "	$1 is a script that looks for installed libraries with"
87    echo "	   versions greater than that in the version file."
88    echo "	For more information, read the comments."
89}
90
91basedir=/usr/src
92setsdir=$basedir/distrib/sets/lists
93libdir=/usr/lib
94shlib_version=./shlib_version
95
96error=0
97quiet=0
98usedir=0
99usefile=0
100usesets=0
101CWD=`pwd`
102args=`getopt "df:shqv:" "$@"`
103if [ $? -ne 0 ] ; then
104    Usage $0
105    exit 0
106fi
107
108set -- $args
109
110while [ ! -z "$1" ]; do
111    case "$1" in
112	-d) usedir=1 ; shift
113	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
114		Usage $0 ; exit 2
115	    fi;;
116	-f) usefile=1 ; arg1=$2 ; shift ; shift
117	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
118		Usage $0 ; exit 2
119	    fi;;
120	-s) usesets=1 ; shift
121	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
122		Usage $0 ; exit 2
123	    fi;;
124	-v) shlib_version=$2; shift ; shift ;;
125	-h) Usage $0 ; exit 0;;
126	-q) quiet=1 ; shift;;
127	--) shift ; break;;
128    esac
129done
130
131if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
132    Usage $0 ; exit 2
133fi
134
135if [ $usefile -eq 1 ] ; then
136   LIBLIST="$arg1"
137else
138   mkdir -m 0700 $TMP
139   if [ $?  != 0 ]; then
140	echo "$0: Unable to create temp directory."
141	exit 2
142   fi
143   LIBLIST=$TMP/libs.lst
144fi
145
146# Build list from the installed libraries.
147if [ $usedir -eq 1 ] ; then
148    if [ "X$1" != "X" ] ; then
149	libdir="$1"
150    fi
151    for f in $libdir ; do
152	ls $f/lib*.so.*.*
153    done > $LIBLIST 2> /dev/null
154fi
155
156# Build list from set lists.  Parameter may be either
157# the "lists" directory or the top of the source tree.
158if [ $usesets -eq 1 ] ; then
159    if [ "X$1" != "X" ] ; then
160	setsdir="$1"
161	if [ -d "$setsdir/distrib/sets/lists" ] ; then
162	    setsdir="$setsdir/distrib/sets/lists"
163	fi
164    fi
165    (cd $setsdir ;
166     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
167		  | sort -u > $LIBLIST
168    )
169fi
170
171#
172# The file $LIBLIST now contains a list of libraries.
173#
174
175if [ "X$2" = "X" ] ; then
176    makefile=$CWD/Makefile
177    libname=`grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//'`
178
179    # Assume the library name is the name of the current directory.
180    if [ -z $libname ]; then
181	libname=`basename $CWD`
182    fi
183else
184    libname="$2"
185fi
186echo $libname | grep "^lib" 1>&2 2> /dev/null
187if [ $? != 0 ]; then
188    libname="lib$libname"
189fi
190
191
192if [ ! -f $shlib_version ] ; then
193    echo "$0: unable to find $shlib_version"
194    exit 2
195fi
196
197# Grab major and minor numbers from the source.
198. $shlib_version
199
200if [ "X$minor" = "X" -o "X$major" = "X" ] ; then
201    echo "$0: $shlib_version doesn't contain the version."
202    exit 2
203fi
204
205# Find every shared object library with the same base name.
206 for instlib in `grep $libname.so "$LIBLIST" ` ; do
207    # Grab the major and minor from the installed library.
208    instmajor=`basename $instlib | awk 'BEGIN { FS="." } { print $3 } '`
209    instminor=`basename $instlib | awk 'BEGIN { FS="." } { print $4 } '`
210    instteeny=`basename $instlib | awk 'BEGIN { FS="." } { print $5 + 0 } '`
211
212    # If they're greater than the source, complain.
213    if [ "0$major" -eq "0$instmajor" ] ; then
214	if [ "0$minor" -eq "0$instminor" ] ; then
215	    if [ "0$teeny" -lt "0$instteeny" ] ; then
216		if [ $error -eq 0 -a $quiet -eq 0 ]; then
217		    echo -n "The following libraries have versions greater"
218		    echo " than the source:"
219	        fi
220		echo $instlib > /dev/stderr
221		error=1
222	    fi
223        elif [ "0$minor" -lt "0$instminor" ] ; then
224	    if [ $error -eq 0 -a $quiet -eq 0 ]; then
225		echo -n "The following libraries have versions greater"
226		echo " than the source:"
227	    fi
228	    echo $instlib > /dev/stderr
229	    error=1
230	fi
231    elif [ "0$major" -lt "0$instmajor" ] ; then
232	if [ $error -eq 0 -a $quiet -eq 0 ] ; then
233	    echo -n "The following libraries have versions greater"
234	    echo " than the source:"
235	fi
236	echo $instlib > /dev/stderr
237	error=1
238    fi
239 done
240
241exit $error
242