18e3f60f3Schristos#!/bin/sh 2*8631329aSmsaitoh# $NetBSD: checkver,v 1.18 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#--------------------------------------------------------------------# 339aa5adaeSerh# checkver - 349aa5adaeSerh# Check for libraries that appear to be newer than the 359aa5adaeSerh# one we're about to install. 369aa5adaeSerh# 375b354a58Ssimonb# checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]" 385b354a58Ssimonb# checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]" 395b354a58Ssimonb# checkver [-q] [-v shlib_version_file] -f liblistfile [library name]" 407c323c9fSerh# 41792cde2dSerh# One of -d, -s or -f must be specified. 427c323c9fSerh# 43792cde2dSerh# all: If library name is not specified it is assumed to 44792cde2dSerh# be the name of the current directory. 457c323c9fSerh# 46792cde2dSerh# -d: Checks the version against the installed libraries. 47792cde2dSerh# If no further arguments are given "/usr/lib" is 48792cde2dSerh# used as the location of installed libraries. 49792cde2dSerh# 50792cde2dSerh# -s: Checks the version against the sets. If no argument 51792cde2dSerh# follows the sets directory defaults to "/usr/src/distrib/sets/lists". 52792cde2dSerh# The directory may be specified as either the top of the 53792cde2dSerh# source tree or as the lists directory. 54792cde2dSerh# 55792cde2dSerh# -f: Checks the version against the provided list. A filename 56792cde2dSerh# must be supplied. 577c323c9fSerh# 585b354a58Ssimonb# -v: Specify the filename of the shlib_version file. Defaults 595b354a58Ssimonb# to "./shlib_version". 605b354a58Ssimonb# 617c323c9fSerh# This script produces no output if all library version are not 627c323c9fSerh# large than the source version. If an installed library with a 637c323c9fSerh# version greater than the source is found, checkver prints a 647c323c9fSerh# header and a list of the names of the offending installed libraries. 657c323c9fSerh# 66*8631329aSmsaitoh# The header may be suppressed by passing "-q" as the first argument. 677c323c9fSerh# 687c323c9fSerh 69792cde2dSerhTMP=/tmp/checkver.$$ 703147a577SchristosPROG="$(basename "$0")" 718e3f60f3Schristos# Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for 728e3f60f3Schristos# internal malloc! 738e3f60f3Schristostrap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15 74792cde2dSerhtrap "[ -d $TMP ] && rm -rf $TMP" 0 757c323c9fSerh 767c323c9fSerhUsage() { 771591fd20Schristoscat << EOF 1>&2 781591fd20SchristosUsage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]] 791591fd20Schristos $PROG [-q] [-v version_file] -s [setlistdir [library name]] 801591fd20Schristos $PROG [-q] [-v version_file] -f liblistfile [library name] 811591fd20Schristos $PROG is a script that looks for installed libraries with 821591fd20Schristos versions greater than that in the version file. 831591fd20Schristos For more information, read the comments. 841591fd20SchristosEOF 851591fd20Schristos exit 1 867c323c9fSerh} 877c323c9fSerh 88792cde2dSerhbasedir=/usr/src 89792cde2dSerhsetsdir=$basedir/distrib/sets/lists 90792cde2dSerhlibdir=/usr/lib 915b354a58Ssimonbshlib_version=./shlib_version 927c323c9fSerh 93792cde2dSerherror=0 94792cde2dSerhquiet=0 95792cde2dSerhusedir=0 96792cde2dSerhusefile=0 97792cde2dSerhusesets=0 981591fd20SchristosCWD=$(pwd) 99bfaf7d3cSchristos: ${AWK:=awk} 1001591fd20Schristos 1011591fd20Schristosfixone() { 102bfaf7d3cSchristos eval $(${AWK} -v 'LIB=$1' ' 103bfaf7d3cSchristosBEGIN { 104bfaf7d3cSchristos gsub(".*\.so\.", "", LIB); 105bfaf7d3cSchristos split(LIB, VER, "."); 106bfaf7d3cSchristos printf("local instmajor=%d\n", V[1] + 0); 107bfaf7d3cSchristos printf("local instminor=%d\n", V[2] + 0); 108bfaf7d3cSchristos printf("local instteeny=%d\n", V[3] + 0); 109bfaf7d3cSchristos}') 1101591fd20Schristos local ms="The following libraries have versions greater than the source" 1111591fd20Schristos 1121591fd20Schristos # If they're greater than the source, complain. 1131591fd20Schristos if [ "0$major" -eq "0$instmajor" ]; then 1141591fd20Schristos if [ "0$minor" -eq "0$instminor" ]; then 1151591fd20Schristos if [ "0$teeny" -lt "0$instteeny" ]; then 1161591fd20Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1171591fd20Schristos echo "$ms" 1>&2 1187c323c9fSerh fi 1191591fd20Schristos echo $1 1>&2 1201591fd20Schristos error=1 1211591fd20Schristos fi 1221591fd20Schristos elif [ "0$minor" -lt "0$instminor" ]; then 1231591fd20Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1241591fd20Schristos echo "$ms" 1>&2 1251591fd20Schristos fi 1261591fd20Schristos echo $1 1>&2 1271591fd20Schristos error=1 1281591fd20Schristos fi 1291591fd20Schristos elif [ "0$major" -lt "0$instmajor" ]; then 1301591fd20Schristos if [ $error -eq 0 -a $quiet -eq 0 ]; then 1311591fd20Schristos echo "$ms" 1>&2 1321591fd20Schristos fi 1331591fd20Schristos echo $1 1>&2 1341591fd20Schristos error=1 1351591fd20Schristos fi 1361591fd20Schristos} 1377c323c9fSerh 1381591fd20Schristoswhile getopts df:shqv: f; do 1391591fd20Schristos case $f in 1401591fd20Schristos d) usedir=1 141792cde2dSerh if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 1421591fd20Schristos Usage 143792cde2dSerh fi;; 1441591fd20Schristos f) usefile=1; arg1=$OPTARG 145792cde2dSerh if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 1461591fd20Schristos Usage 147792cde2dSerh fi;; 1481591fd20Schristos s) usesets=1 149792cde2dSerh if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 1501591fd20Schristos Usage 151792cde2dSerh fi;; 1529ec489e5Schristos v) shlib_version=$OPTARG;; 1539ec489e5Schristos q) quiet=1;; 1541591fd20Schristos *) Usage;; 155792cde2dSerh esac 156792cde2dSerhdone 157792cde2dSerh 1581591fd20Schristosshift $(($OPTIND - 1)) 1591591fd20Schristos 160792cde2dSerhif [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then 1611591fd20Schristos Usage 1627c323c9fSerhfi 1637c323c9fSerh 164792cde2dSerhif [ $usefile -eq 1 ]; then 165792cde2dSerh LIBLIST="$arg1" 1667c323c9fSerhelse 1671591fd20Schristos if ! mkdir -m 0700 $TMP; then 1681591fd20Schristos echo "$PROG: Unable to create temp directory." 1>&2 169792cde2dSerh exit 2 1707c323c9fSerh fi 171792cde2dSerh LIBLIST=$TMP/libs.lst 172792cde2dSerhfi 173792cde2dSerh 174792cde2dSerh# Build list from the installed libraries. 175792cde2dSerhif [ $usedir -eq 1 ]; then 1761591fd20Schristos if [ -n "$1" ]; then 177792cde2dSerh libdir="$1" 178792cde2dSerh fi 179006c21d4Serh for f in $libdir; do 180006c21d4Serh ls $f/lib*.so.*.* 1818b8a7d2cSerh done > $LIBLIST 2> /dev/null 182792cde2dSerhfi 183792cde2dSerh 184792cde2dSerh# Build list from set lists. Parameter may be either 185792cde2dSerh# the "lists" directory or the top of the source tree. 186792cde2dSerhif [ $usesets -eq 1 ]; then 1871591fd20Schristos if [ -n "$1" ]; then 188792cde2dSerh setsdir="$1" 189792cde2dSerh if [ -d "$setsdir/distrib/sets/lists" ]; then 190792cde2dSerh setsdir="$setsdir/distrib/sets/lists" 191792cde2dSerh fi 192792cde2dSerh fi 193792cde2dSerh (cd $setsdir; 1941591fd20Schristos cat */[a-z]* | 1951591fd20Schristos grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' | 1961591fd20Schristos sort -u > $LIBLIST) 197792cde2dSerhfi 198792cde2dSerh 199792cde2dSerh# 200792cde2dSerh# The file $LIBLIST now contains a list of libraries. 201792cde2dSerh# 2021591fd20Schristosif [ -z "$2" ]; then 203792cde2dSerh makefile=$CWD/Makefile 2041591fd20Schristos libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//') 205792cde2dSerh 206792cde2dSerh # Assume the library name is the name of the current directory. 2071591fd20Schristos if [ -z "$libname" ]; then 2081591fd20Schristos libname=$(basename $CWD) 209792cde2dSerh fi 2107c323c9fSerhelse 2117c323c9fSerh libname="$2" 2127c323c9fSerhfi 2138e3f60f3Schristosecho $libname | grep "^lib" 1>&2 2> /dev/null 2148e3f60f3Schristosif [ $? != 0 ]; then 2157c323c9fSerh libname="lib$libname" 2167c323c9fSerhfi 2177c323c9fSerh 2187c323c9fSerh 2195b354a58Ssimonbif [ ! -f $shlib_version ]; then 2201591fd20Schristos echo "$PROG: unable to find $shlib_version" 1>&2 221792cde2dSerh exit 2 2227c323c9fSerhfi 2237c323c9fSerh 2247c323c9fSerh# Grab major and minor numbers from the source. 2255b354a58Ssimonb. $shlib_version 2267c323c9fSerh 2271591fd20Schristosif [ -z "$minor" -o -z "$major" ]; then 2281591fd20Schristos echo "$PROG: $shlib_version doesn't contain the version." 1>&2 229792cde2dSerh exit 2 2307c323c9fSerhfi 2317c323c9fSerh 2327c323c9fSerh# Find every shared object library with the same base name. 2331591fd20Schristosfor instlib in $(grep $libname.so "$LIBLIST"); do 2347c323c9fSerh # Grab the major and minor from the installed library. 2351591fd20Schristos fixone "$instlib" 2367c323c9fSerhdone 2377c323c9fSerh 2387c323c9fSerhexit $error 239