11.5Schristos#!/bin/sh 21.18Smsaitoh# $NetBSD: checkver,v 1.18 2021/12/05 08:09:30 msaitoh 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.18Smsaitoh# The header may be suppressed 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.17Schristos: ${AWK:=awk} 1001.14Schristos 1011.14Schristosfixone() { 1021.17Schristos eval $(${AWK} -v 'LIB=$1' ' 1031.17SchristosBEGIN { 1041.17Schristos gsub(".*\.so\.", "", LIB); 1051.17Schristos split(LIB, VER, "."); 1061.17Schristos printf("local instmajor=%d\n", V[1] + 0); 1071.17Schristos printf("local instminor=%d\n", V[2] + 0); 1081.17Schristos printf("local instteeny=%d\n", V[3] + 0); 1091.17Schristos}') 1101.14Schristos local ms="The following libraries have versions greater than the source" 1111.14Schristos 1121.14Schristos # If they're greater than the source, complain. 1131.14Schristos if [ "0$major" -eq "0$instmajor" ]; then 1141.14Schristos if [ "0$minor" -eq "0$instminor" ]; then 1151.14Schristos if [ "0$teeny" -lt "0$instteeny" ]; then 1161.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1171.14Schristos echo "$ms" 1>&2 1181.14Schristos fi 1191.14Schristos echo $1 1>&2 1201.14Schristos error=1 1211.14Schristos fi 1221.14Schristos elif [ "0$minor" -lt "0$instminor" ]; then 1231.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1241.14Schristos echo "$ms" 1>&2 1251.14Schristos fi 1261.14Schristos echo $1 1>&2 1271.14Schristos error=1 1281.14Schristos fi 1291.14Schristos elif [ "0$major" -lt "0$instmajor" ]; then 1301.14Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1311.14Schristos echo "$ms" 1>&2 1321.14Schristos fi 1331.14Schristos echo $1 1>&2 1341.14Schristos error=1 1351.14Schristos fi 1361.14Schristos} 1371.14Schristos 1381.14Schristoswhile getopts df:shqv: f; do 1391.14Schristos case $f in 1401.14Schristos d) usedir=1 1411.14Schristos if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 1421.14Schristos Usage 1431.14Schristos fi;; 1441.14Schristos f) usefile=1; arg1=$OPTARG 1451.14Schristos if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 1461.14Schristos Usage 1471.14Schristos fi;; 1481.14Schristos s) usesets=1 1491.14Schristos if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 1501.14Schristos Usage 1511.14Schristos fi;; 1521.16Schristos v) shlib_version=$OPTARG;; 1531.16Schristos q) quiet=1;; 1541.14Schristos *) Usage;; 1551.14Schristos esac 1561.2Serhdone 1571.2Serh 1581.14Schristosshift $(($OPTIND - 1)) 1591.14Schristos 1601.14Schristosif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then 1611.14Schristos Usage 1621.2Serhfi 1631.2Serh 1641.14Schristosif [ $usefile -eq 1 ]; then 1651.14Schristos LIBLIST="$arg1" 1661.1Serhelse 1671.14Schristos if ! mkdir -m 0700 $TMP; then 1681.14Schristos echo "$PROG: Unable to create temp directory." 1>&2 1691.14Schristos exit 2 1701.14Schristos fi 1711.14Schristos LIBLIST=$TMP/libs.lst 1721.2Serhfi 1731.2Serh 1741.2Serh# Build list from the installed libraries. 1751.14Schristosif [ $usedir -eq 1 ]; then 1761.14Schristos if [ -n "$1" ]; then 1771.14Schristos libdir="$1" 1781.14Schristos fi 1791.14Schristos for f in $libdir; do 1801.14Schristos ls $f/lib*.so.*.* 1811.14Schristos done > $LIBLIST 2> /dev/null 1821.1Serhfi 1831.1Serh 1841.2Serh# Build list from set lists. Parameter may be either 1851.2Serh# the "lists" directory or the top of the source tree. 1861.14Schristosif [ $usesets -eq 1 ]; then 1871.14Schristos if [ -n "$1" ]; then 1881.14Schristos setsdir="$1" 1891.14Schristos if [ -d "$setsdir/distrib/sets/lists" ]; then 1901.14Schristos setsdir="$setsdir/distrib/sets/lists" 1911.14Schristos fi 1921.2Serh fi 1931.14Schristos (cd $setsdir; 1941.14Schristos cat */[a-z]* | 1951.14Schristos grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' | 1961.14Schristos sort -u > $LIBLIST) 1971.1Serhfi 1981.1Serh 1991.2Serh# 2001.2Serh# The file $LIBLIST now contains a list of libraries. 2011.2Serh# 2021.14Schristosif [ -z "$2" ]; then 2031.14Schristos makefile=$CWD/Makefile 2041.14Schristos libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//') 2051.14Schristos 2061.14Schristos # Assume the library name is the name of the current directory. 2071.14Schristos if [ -z "$libname" ]; then 2081.14Schristos libname=$(basename $CWD) 2091.14Schristos fi 2101.2Serhelse 2111.14Schristos libname="$2" 2121.2Serhfi 2131.5Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null 2141.5Schristosif [ $? != 0 ]; then 2151.14Schristos libname="lib$libname" 2161.2Serhfi 2171.1Serh 2181.1Serh 2191.14Schristosif [ ! -f $shlib_version ]; then 2201.14Schristos echo "$PROG: unable to find $shlib_version" 1>&2 2211.14Schristos exit 2 2221.1Serhfi 2231.1Serh 2241.1Serh# Grab major and minor numbers from the source. 2251.6Ssimonb. $shlib_version 2261.1Serh 2271.14Schristosif [ -z "$minor" -o -z "$major" ]; then 2281.14Schristos echo "$PROG: $shlib_version doesn't contain the version." 1>&2 2291.14Schristos exit 2 2301.1Serhfi 2311.1Serh 2321.1Serh# Find every shared object library with the same base name. 2331.14Schristosfor instlib in $(grep $libname.so "$LIBLIST"); do 2341.14Schristos # Grab the major and minor from the installed library. 2351.14Schristos fixone "$instlib" 2361.14Schristosdone 2371.1Serh 2381.1Serhexit $error 239