1999-03-16 21:57:31 +03:00
|
|
|
#!/bin/sh
|
2013-02-17 06:36:21 +04:00
|
|
|
# $NetBSD: checkver,v 1.16 2013/02/17 02:36:21 christos Exp $
|
1998-11-07 12:36:54 +03:00
|
|
|
#
|
|
|
|
# Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
# by Eric Haszlakiewicz.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------#
|
1999-11-05 23:16:56 +03:00
|
|
|
# checkver -
|
|
|
|
# Check for libraries that appear to be newer than the
|
|
|
|
# one we're about to install.
|
|
|
|
#
|
1999-06-10 04:32:23 +04:00
|
|
|
# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
|
|
|
|
# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
|
|
|
|
# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
|
1998-11-07 12:36:54 +03:00
|
|
|
#
|
1998-11-12 08:39:45 +03:00
|
|
|
# One of -d, -s or -f must be specified.
|
1998-11-07 12:36:54 +03:00
|
|
|
#
|
1998-11-12 08:39:45 +03:00
|
|
|
# all: If library name is not specified it is assumed to
|
|
|
|
# be the name of the current directory.
|
1998-11-07 12:36:54 +03:00
|
|
|
#
|
1998-11-12 08:39:45 +03:00
|
|
|
# -d: Checks the version against the installed libraries.
|
|
|
|
# If no further arguments are given "/usr/lib" is
|
|
|
|
# used as the location of installed libraries.
|
|
|
|
#
|
|
|
|
# -s: Checks the version against the sets. If no argument
|
|
|
|
# follows the sets directory defaults to "/usr/src/distrib/sets/lists".
|
|
|
|
# The directory may be specified as either the top of the
|
|
|
|
# source tree or as the lists directory.
|
|
|
|
#
|
|
|
|
# -f: Checks the version against the provided list. A filename
|
|
|
|
# must be supplied.
|
1998-11-07 12:36:54 +03:00
|
|
|
#
|
1999-06-10 04:32:23 +04:00
|
|
|
# -v: Specify the filename of the shlib_version file. Defaults
|
|
|
|
# to "./shlib_version".
|
|
|
|
#
|
1999-07-02 19:12:15 +04:00
|
|
|
# This script produces no output if all library version are not
|
1998-11-07 12:36:54 +03:00
|
|
|
# large than the source version. If an installed library with a
|
|
|
|
# version greater than the source is found, checkver prints a
|
|
|
|
# header and a list of the names of the offending installed libraries.
|
|
|
|
#
|
|
|
|
# The header may be supressed by passing "-q" as the first argument.
|
|
|
|
#
|
|
|
|
|
1998-11-12 08:39:45 +03:00
|
|
|
TMP=/tmp/checkver.$$
|
2013-02-17 05:26:47 +04:00
|
|
|
PROG="$(basename "$0")"
|
1999-03-16 21:57:31 +03:00
|
|
|
# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
|
|
|
|
# internal malloc!
|
|
|
|
trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
|
1998-11-12 08:39:45 +03:00
|
|
|
trap "[ -d $TMP ] && rm -rf $TMP" 0
|
1998-11-07 12:36:54 +03:00
|
|
|
|
1999-03-16 21:57:31 +03:00
|
|
|
Usage() {
|
2013-02-17 05:20:57 +04:00
|
|
|
cat << EOF 1>&2
|
|
|
|
Usage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]]
|
|
|
|
$PROG [-q] [-v version_file] -s [setlistdir [library name]]
|
|
|
|
$PROG [-q] [-v version_file] -f liblistfile [library name]
|
|
|
|
$PROG is a script that looks for installed libraries with
|
|
|
|
versions greater than that in the version file.
|
|
|
|
For more information, read the comments.
|
|
|
|
EOF
|
|
|
|
exit 1
|
1998-11-07 12:36:54 +03:00
|
|
|
}
|
|
|
|
|
1998-11-12 08:39:45 +03:00
|
|
|
basedir=/usr/src
|
|
|
|
setsdir=$basedir/distrib/sets/lists
|
|
|
|
libdir=/usr/lib
|
1999-06-10 04:32:23 +04:00
|
|
|
shlib_version=./shlib_version
|
1998-11-07 12:36:54 +03:00
|
|
|
|
1998-11-12 08:39:45 +03:00
|
|
|
error=0
|
|
|
|
quiet=0
|
|
|
|
usedir=0
|
|
|
|
usefile=0
|
|
|
|
usesets=0
|
2013-02-17 05:20:57 +04:00
|
|
|
CWD=$(pwd)
|
|
|
|
|
|
|
|
fixone() {
|
|
|
|
local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }')
|
|
|
|
local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }')
|
|
|
|
local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }')
|
|
|
|
local ms="The following libraries have versions greater than the source"
|
|
|
|
|
|
|
|
# If they're greater than the source, complain.
|
|
|
|
if [ "0$major" -eq "0$instmajor" ]; then
|
|
|
|
if [ "0$minor" -eq "0$instminor" ]; then
|
|
|
|
if [ "0$teeny" -lt "0$instteeny" ]; then
|
|
|
|
if [ $error -eq 0 -a $quiet -eq 0 ]; then
|
|
|
|
echo "$ms" 1>&2
|
|
|
|
fi
|
|
|
|
echo $1 1>&2
|
|
|
|
error=1
|
|
|
|
fi
|
|
|
|
elif [ "0$minor" -lt "0$instminor" ]; then
|
|
|
|
if [ $error -eq 0 -a $quiet -eq 0 ]; then
|
|
|
|
echo "$ms" 1>&2
|
|
|
|
fi
|
|
|
|
echo $1 1>&2
|
|
|
|
error=1
|
|
|
|
fi
|
|
|
|
elif [ "0$major" -lt "0$instmajor" ]; then
|
|
|
|
if [ $error -eq 0 -a $quiet -eq 0 ]; then
|
|
|
|
echo "$ms" 1>&2
|
|
|
|
fi
|
|
|
|
echo $1 1>&2
|
|
|
|
error=1
|
|
|
|
fi
|
|
|
|
}
|
1998-11-07 12:36:54 +03:00
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
while getopts df:shqv: f; do
|
|
|
|
case $f in
|
|
|
|
d) usedir=1
|
|
|
|
if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
|
|
|
|
Usage
|
|
|
|
fi;;
|
|
|
|
f) usefile=1; arg1=$OPTARG
|
|
|
|
if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
|
|
|
|
Usage
|
|
|
|
fi;;
|
|
|
|
s) usesets=1
|
|
|
|
if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
|
|
|
|
Usage
|
|
|
|
fi;;
|
2013-02-17 06:36:21 +04:00
|
|
|
v) shlib_version=$OPTARG;;
|
|
|
|
q) quiet=1;;
|
2013-02-17 05:20:57 +04:00
|
|
|
*) Usage;;
|
|
|
|
esac
|
1998-11-12 08:39:45 +03:00
|
|
|
done
|
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then
|
|
|
|
Usage
|
1998-11-07 12:36:54 +03:00
|
|
|
fi
|
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ $usefile -eq 1 ]; then
|
|
|
|
LIBLIST="$arg1"
|
1998-11-07 12:36:54 +03:00
|
|
|
else
|
2013-02-17 05:20:57 +04:00
|
|
|
if ! mkdir -m 0700 $TMP; then
|
|
|
|
echo "$PROG: Unable to create temp directory." 1>&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
LIBLIST=$TMP/libs.lst
|
1998-11-12 08:39:45 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build list from the installed libraries.
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ $usedir -eq 1 ]; then
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
libdir="$1"
|
|
|
|
fi
|
|
|
|
for f in $libdir; do
|
|
|
|
ls $f/lib*.so.*.*
|
|
|
|
done > $LIBLIST 2> /dev/null
|
1998-11-12 08:39:45 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build list from set lists. Parameter may be either
|
|
|
|
# the "lists" directory or the top of the source tree.
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ $usesets -eq 1 ]; then
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
setsdir="$1"
|
|
|
|
if [ -d "$setsdir/distrib/sets/lists" ]; then
|
|
|
|
setsdir="$setsdir/distrib/sets/lists"
|
|
|
|
fi
|
1998-11-12 08:39:45 +03:00
|
|
|
fi
|
2013-02-17 05:20:57 +04:00
|
|
|
(cd $setsdir;
|
|
|
|
cat */[a-z]* |
|
|
|
|
grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' |
|
|
|
|
sort -u > $LIBLIST)
|
1998-11-07 12:36:54 +03:00
|
|
|
fi
|
|
|
|
|
1998-11-12 08:39:45 +03:00
|
|
|
#
|
|
|
|
# The file $LIBLIST now contains a list of libraries.
|
|
|
|
#
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ -z "$2" ]; then
|
|
|
|
makefile=$CWD/Makefile
|
|
|
|
libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//')
|
1998-11-12 08:39:45 +03:00
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
# Assume the library name is the name of the current directory.
|
|
|
|
if [ -z "$libname" ]; then
|
|
|
|
libname=$(basename $CWD)
|
|
|
|
fi
|
1998-11-12 08:39:45 +03:00
|
|
|
else
|
2013-02-17 05:20:57 +04:00
|
|
|
libname="$2"
|
1998-11-12 08:39:45 +03:00
|
|
|
fi
|
1999-03-16 21:57:31 +03:00
|
|
|
echo $libname | grep "^lib" 1>&2 2> /dev/null
|
|
|
|
if [ $? != 0 ]; then
|
2013-02-17 05:20:57 +04:00
|
|
|
libname="lib$libname"
|
1998-11-12 08:39:45 +03:00
|
|
|
fi
|
1998-11-07 12:36:54 +03:00
|
|
|
|
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ ! -f $shlib_version ]; then
|
|
|
|
echo "$PROG: unable to find $shlib_version" 1>&2
|
|
|
|
exit 2
|
1998-11-07 12:36:54 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Grab major and minor numbers from the source.
|
1999-06-10 04:32:23 +04:00
|
|
|
. $shlib_version
|
1998-11-07 12:36:54 +03:00
|
|
|
|
2013-02-17 05:20:57 +04:00
|
|
|
if [ -z "$minor" -o -z "$major" ]; then
|
|
|
|
echo "$PROG: $shlib_version doesn't contain the version." 1>&2
|
|
|
|
exit 2
|
1998-11-07 12:36:54 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Find every shared object library with the same base name.
|
2013-02-17 05:20:57 +04:00
|
|
|
for instlib in $(grep $libname.so "$LIBLIST"); do
|
|
|
|
# Grab the major and minor from the installed library.
|
|
|
|
fixone "$instlib"
|
|
|
|
done
|
1998-11-07 12:36:54 +03:00
|
|
|
|
|
|
|
exit $error
|