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