1 #!/bin/ksh 2 # $NetBSD: checkvers,v 1.9 2021/12/05 08:09:30 msaitoh Exp $ 3 # 4 # Copyright (c) 1998 The NetBSD Foundation, Inc. 5 # All rights reserved. 6 # 7 # This code is derived from software contributed to The NetBSD Foundation 8 # by Eric Haszlakiewicz. 9 # 10 # Redistribution and use in source and binary forms, with or without 11 # modification, are permitted provided that the following conditions 12 # are met: 13 # 1. Redistributions of source code must retain the above copyright 14 # notice, this list of conditions and the following disclaimer. 15 # 2. Redistributions in binary form must reproduce the above copyright 16 # notice, this list of conditions and the following disclaimer in the 17 # documentation and/or other materials provided with the distribution. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 # POSSIBILITY OF SUCH DAMAGE. 30 # 31 32 #--------------------------------------------------------------------# 33 # checkvers [-q] [systemlibdir [library name]] 34 # 35 # This is a wrapper script around checkver. It will find 36 # all directories within the current directory containing 37 # a shlib_version file and call checkver for each. 38 # 39 # As with checkver, a list of directories of installed libraries 40 # may be specified. This will replace the default of "/usr/lib" 41 # and search there instead. 42 # 43 # A library name may also be specified. However, this script 44 # will not work correctly if it finds shlib_version files 45 # corresponding to a different library. 46 # 47 # This script produces no output if all library versions are ok. 48 # If the versions aren't ok the header will be displayed once 49 # followed by a list of problematic libraries. 50 # 51 52 # checkvers: 53 # if "-s", build list, pass with -f to checkver. 54 # if "-d", build list, pass with -f to checkver. 55 # if "-f", pass with -f to checkver. 56 57 58 # Cleanup on exit. 59 TMP=/tmp/checkvers.$$ 60 trap "exit 2" 1 2 3 4 5 6 7 8 10 11 12 13 14 15 61 trap "rm -rf $TMP" 0 62 63 Usage ( ) { 64 echo "Usage: $1 [-q] -d [installedlibdir [library name]]" 65 echo " $1 [-q] -s [setlistdir [library name]]" 66 echo " $1 [-q] -f liblistfile [library name]" 67 } 68 69 basedir=/usr/src 70 setsdir=$basedir/distrib/sets/lists 71 libdir=/usr/lib 72 73 error=0 74 quiet=0 75 usedir=0 76 usefile=0 77 usesets=0 78 CWD=`pwd` 79 args=`getopt "df:shq" "$@"` 80 if [ $? -ne 0 ] ; then 81 Usage $0 82 exit 0 83 fi 84 85 set -- $args 86 87 while . ; do 88 case "$1" in 89 -d) usedir=1 ; shift 90 if [ $usefile -eq 1 -o $usesets -eq 1 ]; then 91 Usage $0 ; exit 2 92 fi;; 93 -f) usefile=1 ; arg1=$2 ; shift ; shift 94 if [ $usedir -eq 1 -o $usesets -eq 1 ]; then 95 Usage $0 ; exit 2 96 fi;; 97 -s) usesets=1 ; shift 98 if [ $usedir -eq 1 -o $usefile -eq 1 ]; then 99 Usage $0 ; exit 2 100 fi;; 101 -h) Usage $0 ; exit 0;; 102 -q) quiet=1 ; shift;; 103 --) shift ; break;; 104 esac 105 done 106 107 if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ] ; then 108 Usage $0 ; exit 2 109 fi 110 if [ $usefile -eq 0 -a $# -gt 2 ] ; then 111 Usage $0 ; exit 2 112 fi 113 if [ $usefile -eq 1 -a $# -gt 1 ] ; then 114 Usage $0 ; exit 2 115 fi 116 117 #-------------------------# 118 119 QUIET= 120 LIBNAME= 121 122 # Suppress header. 123 if [ quiet -eq 1 ] ; then 124 QUIET="-q" 125 fi 126 127 if ! mkdir -m 700 $TMP ; then 128 echo "$0: Unable to create temp directory." 129 exit 2 130 fi 131 132 if [ $usefile -eq 1 ] ; then 133 # Just pass the file name to checkver. 134 LIBLIST="$arg1" 135 else 136 LIBLIST=$TMP/libs.lst 137 fi 138 139 # Build list from the installed libraries. 140 if [ $usedir -eq 1 ] ; then 141 if [ "X$1" != "X" ] ; then 142 libdir="$1" 143 fi 144 for f in $libdir ; do 145 ls $f/lib*.so.*.* 146 done > $LIBLIST 2> /dev/null 147 fi 148 149 # Build list from set lists. Parameter may be either 150 # the "lists" directory or the top of the source tree. 151 if [ $usesets -eq 1 ] ; then 152 if [ "X$1" != "X" ] ; then 153 setsdir="$1" 154 if [ -d "$setsdir/distrib/sets/lists" ] ; then 155 setsdir="$setsdir/distrib/sets/lists" 156 fi 157 fi 158 (cd $setsdir ; 159 cat */[a-z]* | grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' \ 160 | sort -u > $LIBLIST 161 ) 162 fi 163 164 if [ "X$2" != "X" ] ; then 165 LIBNAME="$2" 166 fi 167 168 EXECDIR=`eval "(cd \`dirname $0\` ; pwd)"` 169 170 CWD=`pwd` 171 VERFILES=`find $CWD -name shlib_version -print` 172 173 for f in $VERFILES ; do 174 # Call checkver. We always have a list of libraries 175 # here, whether given to us or built, so always 176 # pass the -f flag. 177 (cd `dirname $f` ; 178 "sh $EXECDIR"/checkver $QUIET -f "$LIBLIST" "$LIBNAME" ; 179 exit $?) 180 ERR=$? 181 if [ $ERR -eq 2 ] ; then 182 echo "$0: checkver failed. LIBLIST=$LIBLIST $LIBNAME=$LIBNAME" 183 exit 2 184 fi 185 if [ $ERR -ne 0 ] ; then 186 QUIET="-q" 187 error=1 188 fi 189 190 if [ "X$LIBNAME" = "X" ] ; then 191 # Build the library name from the directory it's in. 192 libname=`dirname $f` 193 libname=`basename $libname` 194 if ! echo $libname | grep -q "^lib" ; then 195 libname="lib$libname" 196 fi 197 else 198 libname="$LIBNAME" 199 fi 200 201 if [ -e $TMP/$libname ] ; then 202 echo "Warning: $libname sources encountered multiple times." 203 echo " Previous location: `cat $TMP/$libname`" 204 echo " Current location: `dirname $f`" 205 fi 206 echo "`dirname $f`" > $TMP/$libname 207 208 done 209 210 exit $error 211