xref: /netbsd-src/lib/checkvers (revision 73b5f8505bd95e1f3ddcb8a105c21486501ec05e)
17c323c9fSerh#!/bin/ksh
2*73b5f850Smsaitoh#	$NetBSD: checkvers,v 1.9 2021/12/05 08:09:30 msaitoh Exp $
37c323c9fSerh#
47c323c9fSerh# Copyright (c) 1998 The NetBSD Foundation, Inc.
57c323c9fSerh# All rights reserved.
67c323c9fSerh#
77c323c9fSerh# This code is derived from software contributed to The NetBSD Foundation
87c323c9fSerh# by Eric Haszlakiewicz.
97c323c9fSerh#
107c323c9fSerh# Redistribution and use in source and binary forms, with or without
117c323c9fSerh# modification, are permitted provided that the following conditions
127c323c9fSerh# are met:
137c323c9fSerh# 1. Redistributions of source code must retain the above copyright
147c323c9fSerh#    notice, this list of conditions and the following disclaimer.
157c323c9fSerh# 2. Redistributions in binary form must reproduce the above copyright
167c323c9fSerh#    notice, this list of conditions and the following disclaimer in the
177c323c9fSerh#    documentation and/or other materials provided with the distribution.
187c323c9fSerh#
197c323c9fSerh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207c323c9fSerh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
217c323c9fSerh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
227c323c9fSerh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
237c323c9fSerh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
247c323c9fSerh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257c323c9fSerh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
267c323c9fSerh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277c323c9fSerh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
287c323c9fSerh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
297c323c9fSerh# POSSIBILITY OF SUCH DAMAGE.
307c323c9fSerh#
317c323c9fSerh
327c323c9fSerh#--------------------------------------------------------------------#
337c323c9fSerh# checkvers [-q] [systemlibdir [library name]]
347c323c9fSerh#
357c323c9fSerh# This is a wrapper script around checkver.  It will find
36d1c4e519Sandvar# all directories within the current directory containing
377c323c9fSerh# a shlib_version file and call checkver for each.
387c323c9fSerh#
397c323c9fSerh# As with checkver, a list of directories of installed libraries
407c323c9fSerh# may be specified.  This will replace the default of "/usr/lib"
417c323c9fSerh# and search there instead.
427c323c9fSerh#
437c323c9fSerh# A library name may also be specified.  However, this script
447c323c9fSerh# will not work correctly if it finds shlib_version files
457c323c9fSerh# corresponding to a different library.
467c323c9fSerh#
47d1c4e519Sandvar# This script produces no output if all library versions are ok.
487c323c9fSerh# If the versions aren't ok the header will be displayed once
497c323c9fSerh# followed by a list of problematic libraries.
507c323c9fSerh#
517c323c9fSerh
52792cde2dSerh# checkvers:
53792cde2dSerh#	if "-s", build list, pass with -f to checkver.
54792cde2dSerh#	if "-d", build list, pass with -f to checkver.
55792cde2dSerh#	if "-f", pass with -f to checkver.
56792cde2dSerh
577c323c9fSerh
587c323c9fSerh# Cleanup on exit.
59792cde2dSerhTMP=/tmp/checkvers.$$
60792cde2dSerhtrap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
617c323c9fSerhtrap "rm -rf $TMP" 0
627c323c9fSerh
637c323c9fSerhUsage ( ) {
64792cde2dSerh    echo "Usage: $1 [-q] -d [installedlibdir [library name]]"
65792cde2dSerh    echo "       $1 [-q] -s [setlistdir [library name]]"
66792cde2dSerh    echo "       $1 [-q] -f liblistfile [library name]"
677c323c9fSerh}
687c323c9fSerh
69792cde2dSerhbasedir=/usr/src
70792cde2dSerhsetsdir=$basedir/distrib/sets/lists
71792cde2dSerhlibdir=/usr/lib
72792cde2dSerh
73792cde2dSerherror=0
74792cde2dSerhquiet=0
75792cde2dSerhusedir=0
76792cde2dSerhusefile=0
77792cde2dSerhusesets=0
78792cde2dSerhCWD=`pwd`
79792cde2dSerhargs=`getopt "df:shq" "$@"`
80792cde2dSerhif [ $? -ne 0 ] ; then
817c323c9fSerh    Usage $0
827c323c9fSerh    exit 0
837c323c9fSerhfi
847c323c9fSerh
85792cde2dSerhset -- $args
86792cde2dSerh
87792cde2dSerhwhile . ; do
88792cde2dSerh    case "$1" in
89792cde2dSerh	-d) usedir=1 ; shift
90792cde2dSerh	    if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
91792cde2dSerh		Usage $0 ; exit 2
92792cde2dSerh	    fi;;
93792cde2dSerh	-f) usefile=1 ; arg1=$2 ; shift ; shift
94792cde2dSerh	    if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
95792cde2dSerh		Usage $0 ; exit 2
96792cde2dSerh	    fi;;
97792cde2dSerh	-s) usesets=1 ; shift
98792cde2dSerh	    if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
99792cde2dSerh		Usage $0 ; exit 2
100792cde2dSerh	    fi;;
101792cde2dSerh	-h) Usage $0 ; exit 0;;
102792cde2dSerh	-q) quiet=1 ; shift;;
103792cde2dSerh	--) shift ; break;;
104792cde2dSerh    esac
105792cde2dSerhdone
106792cde2dSerh
107792cde2dSerhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then
108792cde2dSerh    Usage $0 ; exit 2
109792cde2dSerhfi
110792cde2dSerhif [ $usefile -eq 0 -a $# -gt 2 ] ; then
111792cde2dSerh    Usage $0 ; exit 2
112792cde2dSerhfi
113792cde2dSerhif [ $usefile -eq 1 -a $# -gt 1 ] ; then
114792cde2dSerh    Usage $0 ; exit 2
1157c323c9fSerhfi
1167c323c9fSerh
117792cde2dSerh#-------------------------#
118792cde2dSerh
119792cde2dSerhQUIET=
1207c323c9fSerhLIBNAME=
121792cde2dSerh
122*73b5f850Smsaitoh# Suppress header.
123792cde2dSerhif [ quiet -eq 1 ] ; then
124792cde2dSerh    QUIET="-q"
1257c323c9fSerhfi
1267c323c9fSerh
1277c323c9fSerhif ! mkdir -m 700 $TMP ; then
128792cde2dSerh    echo "$0: Unable to create temp directory."
129792cde2dSerh    exit 2
130792cde2dSerhfi
131792cde2dSerh
132792cde2dSerhif [ $usefile -eq 1 ] ; then
133792cde2dSerh    # Just pass the file name to checkver.
134792cde2dSerh    LIBLIST="$arg1"
135792cde2dSerhelse
136792cde2dSerh    LIBLIST=$TMP/libs.lst
137792cde2dSerhfi
138792cde2dSerh
139792cde2dSerh# Build list from the installed libraries.
140792cde2dSerhif [ $usedir -eq 1 ] ; then
141792cde2dSerh    if [ "X$1" != "X" ] ; then
142792cde2dSerh	libdir="$1"
143792cde2dSerh    fi
144006c21d4Serh    for f in $libdir ; do
145006c21d4Serh	ls $f/lib*.so.*.*
1468b8a7d2cSerh    done > $LIBLIST 2> /dev/null
147792cde2dSerhfi
148792cde2dSerh
149792cde2dSerh# Build list from set lists.  Parameter may be either
150792cde2dSerh# the "lists" directory or the top of the source tree.
151792cde2dSerhif [ $usesets -eq 1 ] ; then
152792cde2dSerh    if [ "X$1" != "X" ] ; then
153792cde2dSerh	setsdir="$1"
154792cde2dSerh	if [ -d "$setsdir/distrib/sets/lists" ] ; then
155792cde2dSerh	    setsdir="$setsdir/distrib/sets/lists"
156792cde2dSerh	fi
157792cde2dSerh    fi
158792cde2dSerh    (cd $setsdir ;
159792cde2dSerh     cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \
160792cde2dSerh		  | sort -u > $LIBLIST
161792cde2dSerh    )
162792cde2dSerhfi
163792cde2dSerh
164792cde2dSerhif [ "X$2" != "X" ] ; then
165792cde2dSerh    LIBNAME="$2"
1667c323c9fSerhfi
1677c323c9fSerh
1687c323c9fSerhEXECDIR=`eval "(cd \`dirname $0\` ; pwd)"`
1697c323c9fSerh
1707c323c9fSerhCWD=`pwd`
1717c323c9fSerhVERFILES=`find $CWD -name shlib_version -print`
1727c323c9fSerh
1737c323c9fSerhfor f in $VERFILES ; do
174792cde2dSerh    # Call checkver.  We always have a list of libraries
175792cde2dSerh    # here, whether given to us or built, so always
176792cde2dSerh    # pass the -f flag.
1777c323c9fSerh    (cd `dirname $f` ;
17868e607a3Sgmcgarry    "sh $EXECDIR"/checkver $QUIET -f "$LIBLIST" "$LIBNAME" ;
1797c323c9fSerh    exit $?)
180792cde2dSerh    ERR=$?
181792cde2dSerh    if [ $ERR -eq 2 ] ; then
182792cde2dSerh	echo "$0: checkver failed. LIBLIST=$LIBLIST $LIBNAME=$LIBNAME"
183792cde2dSerh	exit 2
184792cde2dSerh    fi
185792cde2dSerh    if [ $ERR -ne 0 ] ; then
1867c323c9fSerh	QUIET="-q"
1877c323c9fSerh	error=1
1887c323c9fSerh    fi
1897c323c9fSerh
1907c323c9fSerh    if [ "X$LIBNAME" = "X" ] ; then
1917c323c9fSerh	# Build the library name from the directory it's in.
1927c323c9fSerh	libname=`dirname $f`
1937c323c9fSerh	libname=`basename $libname`
1947c323c9fSerh	if ! echo $libname | grep -q "^lib" ; then
1957c323c9fSerh	    libname="lib$libname"
1967c323c9fSerh	fi
1977c323c9fSerh    else
1987c323c9fSerh	libname="$LIBNAME"
1997c323c9fSerh    fi
2007c323c9fSerh
2017c323c9fSerh    if [ -e $TMP/$libname ] ; then
2027c323c9fSerh	echo "Warning: $libname sources encountered multiple times."
2037c323c9fSerh	echo "         Previous location: `cat $TMP/$libname`"
2047c323c9fSerh	echo "         Current location: `dirname $f`"
2057c323c9fSerh    fi
2067c323c9fSerh    echo "`dirname $f`" > $TMP/$libname
2077c323c9fSerh
2087c323c9fSerhdone
2097c323c9fSerh
210792cde2dSerhexit $error
211