1#!/bin/ksh
2#	$NetBSD: checkvers,v 1.6 2000/08/09 23:41:27 gmcgarry 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#
19# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32#--------------------------------------------------------------------#
33# checkvers [-q] [systemlibdir [library name]]
34#
35# This is a wrapper script around checkver.  It will find
36# all directories withing the current directory containing
37# a shlib_version file and call checkver for each.
38#
39# As with checkver, a list of directories of installed libraries
40# may be specified.  This will replace the default of "/usr/lib"
41# and search there instead.
42#
43# A library name may also be specified.  However, this script
44# will not work correctly if it finds shlib_version files
45# corresponding to a different library.
46#
47# This script produces no output if all library version are ok.
48# If the versions aren't ok the header will be displayed once
49# followed by a list of problematic libraries.
50#
51
52# checkvers:
53#	if "-s", build list, pass with -f to checkver.
54#	if "-d", build list, pass with -f to checkver.
55#	if "-f", pass with -f to checkver.
56
57
58# Cleanup on exit.
59TMP=/tmp/checkvers.$$
60trap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
61trap "rm -rf $TMP" 0
62
63Usage ( ) {
64    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
65    echo "       $1 [-q] -s [setlistdir [library name]]"
66    echo "       $1 [-q] -f liblistfile [library name]"
67}
68
69basedir=/usr/src
70setsdir=$basedir/distrib/sets/lists
71libdir=/usr/lib
72
73error=0
74quiet=0
75usedir=0
76usefile=0
77usesets=0
78CWD=`pwd`
79args=`getopt "df:shq" "$@"`
80if [ $? -ne 0 ] ; then
81    Usage $0
82    exit 0
83fi
84
85set -- $args
86
87while . ; do
88    case "$1" in
89	-d) usedir=1 ; shift
90	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
91		Usage $0 ; exit 2
92	    fi;;
93	-f) usefile=1 ; arg1=$2 ; shift ; shift
94	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
95		Usage $0 ; exit 2
96	    fi;;
97	-s) usesets=1 ; shift
98	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
99		Usage $0 ; exit 2
100	    fi;;
101	-h) Usage $0 ; exit 0;;
102	-q) quiet=1 ; shift;;
103	--) shift ; break;;
104    esac
105done
106
107if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
108    Usage $0 ; exit 2
109fi
110if [ $usefile -eq 0 -a $# -gt 2 ] ; then
111    Usage $0 ; exit 2
112fi
113if [ $usefile -eq 1 -a $# -gt 1 ] ; then
114    Usage $0 ; exit 2
115fi
116
117#-------------------------#
118
119QUIET=
120LIBNAME=
121
122# Supress header.
123if [ quiet -eq 1 ] ; then
124    QUIET="-q"
125fi
126
127if ! mkdir -m 700 $TMP ; then
128    echo "$0: Unable to create temp directory."
129    exit 2
130fi
131
132if [ $usefile -eq 1 ] ; then
133    # Just pass the file name to checkver.
134    LIBLIST="$arg1"
135else
136    LIBLIST=$TMP/libs.lst
137fi
138
139# Build list from the installed libraries.
140if [ $usedir -eq 1 ] ; then
141    if [ "X$1" != "X" ] ; then
142	libdir="$1"
143    fi
144    for f in $libdir ; do
145	ls $f/lib*.so.*.*
146    done > $LIBLIST 2> /dev/null
147fi
148
149# Build list from set lists.  Parameter may be either
150# the "lists" directory or the top of the source tree.
151if [ $usesets -eq 1 ] ; then
152    if [ "X$1" != "X" ] ; then
153	setsdir="$1"
154	if [ -d "$setsdir/distrib/sets/lists" ] ; then
155	    setsdir="$setsdir/distrib/sets/lists"
156	fi
157    fi
158    (cd $setsdir ;
159     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
160		  | sort -u > $LIBLIST
161    )
162fi
163
164if [ "X$2" != "X" ] ; then
165    LIBNAME="$2"
166fi
167
168EXECDIR=`eval "(cd \`dirname $0\` ; pwd)"`
169
170CWD=`pwd`
171VERFILES=`find $CWD -name shlib_version -print`
172
173for f in $VERFILES ; do
174    # Call checkver.  We always have a list of libraries
175    # here, whether given to us or built, so always
176    # pass the -f flag.
177    (cd `dirname $f` ;
178    "sh $EXECDIR"/checkver $QUIET -f "$LIBLIST" "$LIBNAME" ;
179    exit $?)
180    ERR=$?
181    if [ $ERR -eq 2 ] ; then
182	echo "$0: checkver failed. LIBLIST=$LIBLIST $LIBNAME=$LIBNAME"
183	exit 2
184    fi
185    if [ $ERR -ne 0 ] ; then
186	QUIET="-q"
187	error=1
188    fi
189
190    if [ "X$LIBNAME" = "X" ] ; then
191	# Build the library name from the directory it's in.
192	libname=`dirname $f`
193	libname=`basename $libname`
194	if ! echo $libname | grep -q "^lib" ; then
195	    libname="lib$libname"
196	fi
197    else
198	libname="$LIBNAME"
199    fi
200
201    if [ -e $TMP/$libname ] ; then
202	echo "Warning: $libname sources encountered multiple times."
203	echo "         Previous location: `cat $TMP/$libname`"
204	echo "         Current location: `dirname $f`"
205    fi
206    echo "`dirname $f`" > $TMP/$libname
207
208done
209
210exit $error
211