checkver revision 1.16
11.5Schristos#!/bin/sh 21.16Schristos# $NetBSD: checkver,v 1.16 2013/02/17 02:36:21 christos 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# 191.1Serh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Serh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Serh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Serh# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Serh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Serh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Serh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Serh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Serh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Serh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Serh# POSSIBILITY OF SUCH DAMAGE. 301.1Serh# 311.1Serh 321.1Serh#--------------------------------------------------------------------# 331.9Serh# checkver - 341.9Serh# Check for libraries that appear to be newer than the 351.9Serh# one we're about to install. 361.9Serh# 371.6Ssimonb# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]" 381.6Ssimonb# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]" 391.6Ssimonb# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]" 401.1Serh# 411.2Serh# One of -d, -s or -f must be specified. 421.1Serh# 431.2Serh# all: If library name is not specified it is assumed to 441.2Serh# be the name of the current directory. 451.2Serh# 461.2Serh# -d: Checks the version against the installed libraries. 471.2Serh# If no further arguments are given "/usr/lib" is 481.2Serh# used as the location of installed libraries. 491.2Serh# 501.2Serh# -s: Checks the version against the sets. If no argument 511.2Serh# follows the sets directory defaults to "/usr/src/distrib/sets/lists". 521.2Serh# The directory may be specified as either the top of the 531.2Serh# source tree or as the lists directory. 541.2Serh# 551.2Serh# -f: Checks the version against the provided list. A filename 561.2Serh# must be supplied. 571.1Serh# 581.6Ssimonb# -v: Specify the filename of the shlib_version file. Defaults 591.6Ssimonb# to "./shlib_version". 601.6Ssimonb# 611.8Ssimonb# This script produces no output if all library version are not 621.1Serh# large than the source version. If an installed library with a 631.1Serh# version greater than the source is found, checkver prints a 641.1Serh# header and a list of the names of the offending installed libraries. 651.1Serh# 661.1Serh# The header may be supressed by passing "-q" as the first argument. 671.1Serh# 681.1Serh 691.2SerhTMP=/tmp/checkver.$$ 701.15SchristosPROG="$(basename "$0")" 711.5Schristos# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for 721.5Schristos# internal malloc! 731.5Schristostrap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15 741.2Serhtrap "[ -d $TMP ] && rm -rf $TMP" 0 751.1Serh 761.5SchristosUsage() { 771.14Schristoscat << EOF 1>&2 781.14SchristosUsage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]] 791.14Schristos $PROG [-q] [-v version_file] -s [setlistdir [library name]] 801.14Schristos $PROG [-q] [-v version_file] -f liblistfile [library name] 811.14Schristos $PROG is a script that looks for installed libraries with 821.14Schristos versions greater than that in the version file. 831.14Schristos For more information, read the comments. 841.14SchristosEOF 851.14Schristos exit 1 861.1Serh} 871.1Serh 881.2Serhbasedir=/usr/src 891.2Serhsetsdir=$basedir/distrib/sets/lists 901.2Serhlibdir=/usr/lib 911.6Ssimonbshlib_version=./shlib_version 921.1Serh 931.2Serherror=0 941.2Serhquiet=0 951.2Serhusedir=0 961.2Serhusefile=0 971.2Serhusesets=0 981.14SchristosCWD=$(pwd) 991.14Schristos 1001.14Schristosfixone() { 1011.14Schristos local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }') 1021.14Schristos local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }') 1031.14Schristos local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }') 1041.14Schristos local ms="The following libraries have versions greater than the source" 1051.14Schristos 1061.14Schristos # If they're greater than the source, complain. 1071.14Schristos if [ "0$major" -eq "0$instmajor" ]; then 1081.14Schristos if [ "0$minor" -eq "0$instminor" ]; then 1091.14Schristos if [ "0$teeny" -lt "0$instteeny" ]; then 1101.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1111.14Schristos echo "$ms" 1>&2 1121.14Schristos fi 1131.14Schristos echo $1 1>&2 1141.14Schristos error=1 1151.14Schristos fi 1161.14Schristos elif [ "0$minor" -lt "0$instminor" ]; then 1171.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1181.14Schristos echo "$ms" 1>&2 1191.14Schristos fi 1201.14Schristos echo $1 1>&2 1211.14Schristos error=1 1221.14Schristos fi 1231.14Schristos elif [ "0$major" -lt "0$instmajor" ]; then 1241.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1251.14Schristos echo "$ms" 1>&2 1261.14Schristos fi 1271.14Schristos echo $1 1>&2 1281.14Schristos error=1 1291.14Schristos fi 1301.14Schristos} 1311.14Schristos 1321.14Schristoswhile getopts df:shqv: f; do 1331.14Schristos case $f in 1341.14Schristos d) usedir=1 1351.14Schristos if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 1361.14Schristos Usage 1371.14Schristos fi;; 1381.14Schristos f) usefile=1; arg1=$OPTARG 1391.14Schristos if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 1401.14Schristos Usage 1411.14Schristos fi;; 1421.14Schristos s) usesets=1 1431.14Schristos if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 1441.14Schristos Usage 1451.14Schristos fi;; 1461.16Schristos v) shlib_version=$OPTARG;; 1471.16Schristos q) quiet=1;; 1481.14Schristos *) Usage;; 1491.14Schristos esac 1501.2Serhdone 1511.2Serh 1521.14Schristosshift $(($OPTIND - 1)) 1531.14Schristos 1541.14Schristosif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then 1551.14Schristos Usage 1561.2Serhfi 1571.2Serh 1581.14Schristosif [ $usefile -eq 1 ]; then 1591.14Schristos LIBLIST="$arg1" 1601.1Serhelse 1611.14Schristos if ! mkdir -m 0700 $TMP; then 1621.14Schristos echo "$PROG: Unable to create temp directory." 1>&2 1631.14Schristos exit 2 1641.14Schristos fi 1651.14Schristos LIBLIST=$TMP/libs.lst 1661.2Serhfi 1671.2Serh 1681.2Serh# Build list from the installed libraries. 1691.14Schristosif [ $usedir -eq 1 ]; then 1701.14Schristos if [ -n "$1" ]; then 1711.14Schristos libdir="$1" 1721.14Schristos fi 1731.14Schristos for f in $libdir; do 1741.14Schristos ls $f/lib*.so.*.* 1751.14Schristos done > $LIBLIST 2> /dev/null 1761.1Serhfi 1771.1Serh 1781.2Serh# Build list from set lists. Parameter may be either 1791.2Serh# the "lists" directory or the top of the source tree. 1801.14Schristosif [ $usesets -eq 1 ]; then 1811.14Schristos if [ -n "$1" ]; then 1821.14Schristos setsdir="$1" 1831.14Schristos if [ -d "$setsdir/distrib/sets/lists" ]; then 1841.14Schristos setsdir="$setsdir/distrib/sets/lists" 1851.14Schristos fi 1861.2Serh fi 1871.14Schristos (cd $setsdir; 1881.14Schristos cat */[a-z]* | 1891.14Schristos grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' | 1901.14Schristos sort -u > $LIBLIST) 1911.1Serhfi 1921.1Serh 1931.2Serh# 1941.2Serh# The file $LIBLIST now contains a list of libraries. 1951.2Serh# 1961.14Schristosif [ -z "$2" ]; then 1971.14Schristos makefile=$CWD/Makefile 1981.14Schristos libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//') 1991.14Schristos 2001.14Schristos # Assume the library name is the name of the current directory. 2011.14Schristos if [ -z "$libname" ]; then 2021.14Schristos libname=$(basename $CWD) 2031.14Schristos fi 2041.2Serhelse 2051.14Schristos libname="$2" 2061.2Serhfi 2071.5Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null 2081.5Schristosif [ $? != 0 ]; then 2091.14Schristos libname="lib$libname" 2101.2Serhfi 2111.1Serh 2121.1Serh 2131.14Schristosif [ ! -f $shlib_version ]; then 2141.14Schristos echo "$PROG: unable to find $shlib_version" 1>&2 2151.14Schristos exit 2 2161.1Serhfi 2171.1Serh 2181.1Serh# Grab major and minor numbers from the source. 2191.6Ssimonb. $shlib_version 2201.1Serh 2211.14Schristosif [ -z "$minor" -o -z "$major" ]; then 2221.14Schristos echo "$PROG: $shlib_version doesn't contain the version." 1>&2 2231.14Schristos exit 2 2241.1Serhfi 2251.1Serh 2261.1Serh# Find every shared object library with the same base name. 2271.14Schristosfor instlib in $(grep $libname.so "$LIBLIST"); do 2281.14Schristos # Grab the major and minor from the installed library. 2291.14Schristos fixone "$instlib" 2301.14Schristosdone 2311.1Serh 2321.1Serhexit $error 233