checkvers revision 1.3
11.1Serh#!/bin/ksh
21.3Serh#	$NetBSD: checkvers,v 1.3 1999/01/27 05:50:29 erh Exp $
31.1Serh#
41.1Serh# Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Serh# All rights reserved.
61.1Serh#
71.1Serh# This code is derived from software contributed to The NetBSD Foundation
81.1Serh# by Eric Haszlakiewicz.
91.1Serh#
101.1Serh# Redistribution and use in source and binary forms, with or without
111.1Serh# modification, are permitted provided that the following conditions
121.1Serh# are met:
131.1Serh# 1. Redistributions of source code must retain the above copyright
141.1Serh#    notice, this list of conditions and the following disclaimer.
151.1Serh# 2. Redistributions in binary form must reproduce the above copyright
161.1Serh#    notice, this list of conditions and the following disclaimer in the
171.1Serh#    documentation and/or other materials provided with the distribution.
181.1Serh# 3. All advertising materials mentioning features or use of this software
191.1Serh#    must display the following acknowledgement:
201.1Serh#        This product includes software developed by the NetBSD
211.1Serh#        Foundation, Inc. and its contributors.
221.1Serh# 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Serh#    contributors may be used to endorse or promote products derived
241.1Serh#    from this software without specific prior written permission.
251.1Serh#
261.1Serh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Serh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Serh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Serh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Serh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Serh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Serh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Serh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Serh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Serh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Serh# POSSIBILITY OF SUCH DAMAGE.
371.1Serh#
381.1Serh
391.1Serh#--------------------------------------------------------------------#
401.1Serh# checkvers [-q] [systemlibdir [library name]]
411.1Serh#
421.1Serh# This is a wrapper script around checkver.  It will find
431.1Serh# all directories withing the current directory containing
441.1Serh# a shlib_version file and call checkver for each.
451.1Serh#
461.1Serh# As with checkver, a list of directories of installed libraries
471.1Serh# may be specified.  This will replace the default of "/usr/lib"
481.1Serh# and search there instead.
491.1Serh# 
501.1Serh# A library name may also be specified.  However, this script
511.1Serh# will not work correctly if it finds shlib_version files
521.1Serh# corresponding to a different library.
531.1Serh#
541.1Serh# This script produces no output if all library version are ok.
551.1Serh# If the versions aren't ok the header will be displayed once
561.1Serh# followed by a list of problematic libraries.
571.1Serh#
581.1Serh
591.2Serh# checkvers:
601.2Serh#	if "-s", build list, pass with -f to checkver.
611.2Serh#	if "-d", build list, pass with -f to checkver.
621.2Serh#	if "-f", pass with -f to checkver.
631.2Serh
641.1Serh
651.1Serh# Cleanup on exit.
661.2SerhTMP=/tmp/checkvers.$$
671.2Serhtrap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
681.1Serhtrap "rm -rf $TMP" 0
691.1Serh
701.1SerhUsage ( ) {
711.2Serh    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
721.2Serh    echo "       $1 [-q] -s [setlistdir [library name]]"
731.2Serh    echo "       $1 [-q] -f liblistfile [library name]"
741.1Serh}
751.1Serh
761.2Serhbasedir=/usr/src
771.2Serhsetsdir=$basedir/distrib/sets/lists
781.2Serhlibdir=/usr/lib
791.2Serh
801.2Serherror=0
811.2Serhquiet=0
821.2Serhusedir=0
831.2Serhusefile=0
841.2Serhusesets=0
851.2SerhCWD=`pwd`
861.2Serhargs=`getopt "df:shq" "$@"`
871.2Serhif [ $? -ne 0 ] ; then
881.1Serh    Usage $0
891.1Serh    exit 0
901.1Serhfi
911.1Serh
921.2Serhset -- $args
931.2Serh
941.2Serhwhile . ; do
951.2Serh    case "$1" in
961.2Serh	-d) usedir=1 ; shift
971.2Serh	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
981.2Serh		Usage $0 ; exit 2
991.2Serh	    fi;;
1001.2Serh	-f) usefile=1 ; arg1=$2 ; shift ; shift
1011.2Serh	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
1021.2Serh		Usage $0 ; exit 2
1031.2Serh	    fi;;
1041.2Serh	-s) usesets=1 ; shift
1051.2Serh	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
1061.2Serh		Usage $0 ; exit 2
1071.2Serh	    fi;;
1081.2Serh	-h) Usage $0 ; exit 0;;
1091.2Serh	-q) quiet=1 ; shift;;
1101.2Serh	--) shift ; break;;
1111.2Serh    esac
1121.2Serhdone
1131.2Serh
1141.2Serhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
1151.2Serh    Usage $0 ; exit 2
1161.2Serhfi
1171.2Serhif [ $usefile -eq 0 -a $# -gt 2 ] ; then
1181.2Serh    Usage $0 ; exit 2
1191.2Serhfi
1201.2Serhif [ $usefile -eq 1 -a $# -gt 1 ] ; then
1211.2Serh    Usage $0 ; exit 2
1221.2Serhfi
1231.2Serh
1241.2Serh#-------------------------#
1251.2Serh
1261.2SerhQUIET=
1271.2SerhLIBNAME=
1281.2Serh
1291.2Serh# Supress header.
1301.2Serhif [ quiet -eq 1 ] ; then
1311.1Serh    QUIET="-q"
1321.2Serhfi
1331.2Serh
1341.2Serhif ! mkdir -m 700 $TMP ; then
1351.2Serh    echo "$0: Unable to create temp directory."
1361.2Serh    exit 2
1371.2Serhfi
1381.2Serh
1391.2Serhif [ $usefile -eq 1 ] ; then
1401.2Serh    # Just pass the file name to checkver.
1411.2Serh    LIBLIST="$arg1"
1421.1Serhelse
1431.2Serh    LIBLIST=$TMP/libs.lst
1441.2Serhfi
1451.2Serh
1461.2Serh# Build list from the installed libraries.
1471.2Serhif [ $usedir -eq 1 ] ; then
1481.2Serh    if [ "X$1" != "X" ] ; then
1491.2Serh	libdir="$1"
1501.2Serh    fi
1511.3Serh    for f in $libdir ; do
1521.3Serh	ls $f/lib*.so.*.*
1531.3Serh    done > $LIBLIST
1541.1Serhfi
1551.1Serh
1561.2Serh# Build list from set lists.  Parameter may be either
1571.2Serh# the "lists" directory or the top of the source tree.
1581.2Serhif [ $usesets -eq 1 ] ; then
1591.2Serh    if [ "X$1" != "X" ] ; then
1601.2Serh	setsdir="$1"
1611.2Serh	if [ -d "$setsdir/distrib/sets/lists" ] ; then
1621.2Serh	    setsdir="$setsdir/distrib/sets/lists"
1631.2Serh	fi
1641.2Serh    fi
1651.2Serh    (cd $setsdir ;
1661.2Serh     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
1671.2Serh		  | sort -u > $LIBLIST
1681.2Serh    )
1691.1Serhfi
1701.2Serh
1711.1Serhif [ "X$2" != "X" ] ; then
1721.1Serh    LIBNAME="$2"
1731.1Serhfi
1741.1Serh
1751.1SerhEXECDIR=`eval "(cd \`dirname $0\` ; pwd)"`
1761.1Serh
1771.1SerhCWD=`pwd`
1781.1SerhVERFILES=`find $CWD -name shlib_version -print`
1791.1Serh
1801.1Serhfor f in $VERFILES ; do
1811.2Serh    # Call checkver.  We always have a list of libraries
1821.2Serh    # here, whether given to us or built, so always
1831.2Serh    # pass the -f flag.
1841.1Serh    (cd `dirname $f` ;
1851.2Serh    "$EXECDIR"/checkver $QUIET -f "$LIBLIST" "$LIBNAME" ;
1861.1Serh    exit $?)
1871.2Serh    ERR=$?
1881.2Serh    if [ $ERR -eq 2 ] ; then
1891.2Serh	echo "$0: checkver failed. LIBLIST=$LIBLIST $LIBNAME=$LIBNAME"
1901.2Serh	exit 2
1911.2Serh    fi
1921.2Serh    if [ $ERR -ne 0 ] ; then
1931.1Serh	QUIET="-q"
1941.1Serh	error=1
1951.1Serh    fi
1961.1Serh
1971.1Serh    if [ "X$LIBNAME" = "X" ] ; then
1981.1Serh	# Build the library name from the directory it's in.
1991.1Serh	libname=`dirname $f`
2001.1Serh	libname=`basename $libname`
2011.1Serh	if ! echo $libname | grep -q "^lib" ; then
2021.1Serh	    libname="lib$libname"
2031.1Serh	fi
2041.1Serh    else
2051.1Serh	libname="$LIBNAME"
2061.1Serh    fi
2071.1Serh
2081.1Serh    if [ -e $TMP/$libname ] ; then
2091.1Serh	echo "Warning: $libname sources encountered multiple times."
2101.1Serh	echo "         Previous location: `cat $TMP/$libname`"
2111.1Serh	echo "         Current location: `dirname $f`"
2121.1Serh    fi
2131.1Serh    echo "`dirname $f`" > $TMP/$libname
2141.1Serh
2151.1Serhdone
2161.1Serh
2171.2Serhexit $error
218