1 1.5 christos #!/bin/sh 2 1.18 msaitoh # $NetBSD: checkver,v 1.18 2021/12/05 08:09:30 msaitoh Exp $ 3 1.1 erh # 4 1.1 erh # Copyright (c) 1998 The NetBSD Foundation, Inc. 5 1.1 erh # All rights reserved. 6 1.1 erh # 7 1.1 erh # This code is derived from software contributed to The NetBSD Foundation 8 1.1 erh # by Eric Haszlakiewicz. 9 1.1 erh # 10 1.1 erh # Redistribution and use in source and binary forms, with or without 11 1.1 erh # modification, are permitted provided that the following conditions 12 1.1 erh # are met: 13 1.1 erh # 1. Redistributions of source code must retain the above copyright 14 1.1 erh # notice, this list of conditions and the following disclaimer. 15 1.1 erh # 2. Redistributions in binary form must reproduce the above copyright 16 1.1 erh # notice, this list of conditions and the following disclaimer in the 17 1.1 erh # documentation and/or other materials provided with the distribution. 18 1.1 erh # 19 1.1 erh # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 erh # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 erh # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 erh # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 erh # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 erh # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 erh # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 erh # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 erh # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 erh # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 erh # POSSIBILITY OF SUCH DAMAGE. 30 1.1 erh # 31 1.1 erh 32 1.1 erh #--------------------------------------------------------------------# 33 1.9 erh # checkver - 34 1.9 erh # Check for libraries that appear to be newer than the 35 1.9 erh # one we're about to install. 36 1.9 erh # 37 1.6 simonb # checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]" 38 1.6 simonb # checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]" 39 1.6 simonb # checkver [-q] [-v shlib_version_file] -f liblistfile [library name]" 40 1.1 erh # 41 1.2 erh # One of -d, -s or -f must be specified. 42 1.1 erh # 43 1.2 erh # all: If library name is not specified it is assumed to 44 1.2 erh # be the name of the current directory. 45 1.2 erh # 46 1.2 erh # -d: Checks the version against the installed libraries. 47 1.2 erh # If no further arguments are given "/usr/lib" is 48 1.2 erh # used as the location of installed libraries. 49 1.2 erh # 50 1.2 erh # -s: Checks the version against the sets. If no argument 51 1.2 erh # follows the sets directory defaults to "/usr/src/distrib/sets/lists". 52 1.2 erh # The directory may be specified as either the top of the 53 1.2 erh # source tree or as the lists directory. 54 1.2 erh # 55 1.2 erh # -f: Checks the version against the provided list. A filename 56 1.2 erh # must be supplied. 57 1.1 erh # 58 1.6 simonb # -v: Specify the filename of the shlib_version file. Defaults 59 1.6 simonb # to "./shlib_version". 60 1.6 simonb # 61 1.8 simonb # This script produces no output if all library version are not 62 1.1 erh # large than the source version. If an installed library with a 63 1.1 erh # version greater than the source is found, checkver prints a 64 1.1 erh # header and a list of the names of the offending installed libraries. 65 1.1 erh # 66 1.18 msaitoh # The header may be suppressed by passing "-q" as the first argument. 67 1.1 erh # 68 1.1 erh 69 1.2 erh TMP=/tmp/checkver.$$ 70 1.15 christos PROG="$(basename "$0")" 71 1.5 christos # Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for 72 1.5 christos # internal malloc! 73 1.5 christos trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15 74 1.2 erh trap "[ -d $TMP ] && rm -rf $TMP" 0 75 1.1 erh 76 1.5 christos Usage() { 77 1.14 christos cat << EOF 1>&2 78 1.14 christos Usage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]] 79 1.14 christos $PROG [-q] [-v version_file] -s [setlistdir [library name]] 80 1.14 christos $PROG [-q] [-v version_file] -f liblistfile [library name] 81 1.14 christos $PROG is a script that looks for installed libraries with 82 1.14 christos versions greater than that in the version file. 83 1.14 christos For more information, read the comments. 84 1.14 christos EOF 85 1.14 christos exit 1 86 1.1 erh } 87 1.1 erh 88 1.2 erh basedir=/usr/src 89 1.2 erh setsdir=$basedir/distrib/sets/lists 90 1.2 erh libdir=/usr/lib 91 1.6 simonb shlib_version=./shlib_version 92 1.1 erh 93 1.2 erh error=0 94 1.2 erh quiet=0 95 1.2 erh usedir=0 96 1.2 erh usefile=0 97 1.2 erh usesets=0 98 1.14 christos CWD=$(pwd) 99 1.17 christos : ${AWK:=awk} 100 1.14 christos 101 1.14 christos fixone() { 102 1.17 christos eval $(${AWK} -v 'LIB=$1' ' 103 1.17 christos BEGIN { 104 1.17 christos gsub(".*\.so\.", "", LIB); 105 1.17 christos split(LIB, VER, "."); 106 1.17 christos printf("local instmajor=%d\n", V[1] + 0); 107 1.17 christos printf("local instminor=%d\n", V[2] + 0); 108 1.17 christos printf("local instteeny=%d\n", V[3] + 0); 109 1.17 christos }') 110 1.14 christos local ms="The following libraries have versions greater than the source" 111 1.14 christos 112 1.14 christos # If they're greater than the source, complain. 113 1.14 christos if [ "0$major" -eq "0$instmajor" ]; then 114 1.14 christos if [ "0$minor" -eq "0$instminor" ]; then 115 1.14 christos if [ "0$teeny" -lt "0$instteeny" ]; then 116 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then 117 1.14 christos echo "$ms" 1>&2 118 1.14 christos fi 119 1.14 christos echo $1 1>&2 120 1.14 christos error=1 121 1.14 christos fi 122 1.14 christos elif [ "0$minor" -lt "0$instminor" ]; then 123 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then 124 1.14 christos echo "$ms" 1>&2 125 1.14 christos fi 126 1.14 christos echo $1 1>&2 127 1.14 christos error=1 128 1.14 christos fi 129 1.14 christos elif [ "0$major" -lt "0$instmajor" ]; then 130 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then 131 1.14 christos echo "$ms" 1>&2 132 1.14 christos fi 133 1.14 christos echo $1 1>&2 134 1.14 christos error=1 135 1.14 christos fi 136 1.14 christos } 137 1.14 christos 138 1.14 christos while getopts df:shqv: f; do 139 1.14 christos case $f in 140 1.14 christos d) usedir=1 141 1.14 christos if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 142 1.14 christos Usage 143 1.14 christos fi;; 144 1.14 christos f) usefile=1; arg1=$OPTARG 145 1.14 christos if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 146 1.14 christos Usage 147 1.14 christos fi;; 148 1.14 christos s) usesets=1 149 1.14 christos if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 150 1.14 christos Usage 151 1.14 christos fi;; 152 1.16 christos v) shlib_version=$OPTARG;; 153 1.16 christos q) quiet=1;; 154 1.14 christos *) Usage;; 155 1.14 christos esac 156 1.2 erh done 157 1.2 erh 158 1.14 christos shift $(($OPTIND - 1)) 159 1.14 christos 160 1.14 christos if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then 161 1.14 christos Usage 162 1.2 erh fi 163 1.2 erh 164 1.14 christos if [ $usefile -eq 1 ]; then 165 1.14 christos LIBLIST="$arg1" 166 1.1 erh else 167 1.14 christos if ! mkdir -m 0700 $TMP; then 168 1.14 christos echo "$PROG: Unable to create temp directory." 1>&2 169 1.14 christos exit 2 170 1.14 christos fi 171 1.14 christos LIBLIST=$TMP/libs.lst 172 1.2 erh fi 173 1.2 erh 174 1.2 erh # Build list from the installed libraries. 175 1.14 christos if [ $usedir -eq 1 ]; then 176 1.14 christos if [ -n "$1" ]; then 177 1.14 christos libdir="$1" 178 1.14 christos fi 179 1.14 christos for f in $libdir; do 180 1.14 christos ls $f/lib*.so.*.* 181 1.14 christos done > $LIBLIST 2> /dev/null 182 1.1 erh fi 183 1.1 erh 184 1.2 erh # Build list from set lists. Parameter may be either 185 1.2 erh # the "lists" directory or the top of the source tree. 186 1.14 christos if [ $usesets -eq 1 ]; then 187 1.14 christos if [ -n "$1" ]; then 188 1.14 christos setsdir="$1" 189 1.14 christos if [ -d "$setsdir/distrib/sets/lists" ]; then 190 1.14 christos setsdir="$setsdir/distrib/sets/lists" 191 1.14 christos fi 192 1.2 erh fi 193 1.14 christos (cd $setsdir; 194 1.14 christos cat */[a-z]* | 195 1.14 christos grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' | 196 1.14 christos sort -u > $LIBLIST) 197 1.1 erh fi 198 1.1 erh 199 1.2 erh # 200 1.2 erh # The file $LIBLIST now contains a list of libraries. 201 1.2 erh # 202 1.14 christos if [ -z "$2" ]; then 203 1.14 christos makefile=$CWD/Makefile 204 1.14 christos libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//') 205 1.14 christos 206 1.14 christos # Assume the library name is the name of the current directory. 207 1.14 christos if [ -z "$libname" ]; then 208 1.14 christos libname=$(basename $CWD) 209 1.14 christos fi 210 1.2 erh else 211 1.14 christos libname="$2" 212 1.2 erh fi 213 1.5 christos echo $libname | grep "^lib" 1>&2 2> /dev/null 214 1.5 christos if [ $? != 0 ]; then 215 1.14 christos libname="lib$libname" 216 1.2 erh fi 217 1.1 erh 218 1.1 erh 219 1.14 christos if [ ! -f $shlib_version ]; then 220 1.14 christos echo "$PROG: unable to find $shlib_version" 1>&2 221 1.14 christos exit 2 222 1.1 erh fi 223 1.1 erh 224 1.1 erh # Grab major and minor numbers from the source. 225 1.6 simonb . $shlib_version 226 1.1 erh 227 1.14 christos if [ -z "$minor" -o -z "$major" ]; then 228 1.14 christos echo "$PROG: $shlib_version doesn't contain the version." 1>&2 229 1.14 christos exit 2 230 1.1 erh fi 231 1.1 erh 232 1.1 erh # Find every shared object library with the same base name. 233 1.14 christos for instlib in $(grep $libname.so "$LIBLIST"); do 234 1.14 christos # Grab the major and minor from the installed library. 235 1.14 christos fixone "$instlib" 236 1.14 christos done 237 1.1 erh 238 1.1 erh exit $error 239