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