Home | History | Annotate | Line # | Download | only in lib
checkver revision 1.13.4.1
      1       1.5  christos #!/bin/sh
      2  1.13.4.1      yamt #	$NetBSD: checkver,v 1.13.4.1 2014/05/22 11:36:43 yamt 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.1       erh # The header may be supressed by passing "-q" as the first argument.
     67       1.1       erh #
     68       1.1       erh 
     69       1.2       erh TMP=/tmp/checkver.$$
     70  1.13.4.1      yamt 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.13.4.1      yamt cat << EOF 1>&2
     78  1.13.4.1      yamt Usage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]]
     79  1.13.4.1      yamt        $PROG [-q] [-v version_file] -s [setlistdir [library name]]
     80  1.13.4.1      yamt        $PROG [-q] [-v version_file] -f liblistfile [library name]
     81  1.13.4.1      yamt        $PROG is a script that looks for installed libraries with
     82  1.13.4.1      yamt        versions greater than that in the version file.
     83  1.13.4.1      yamt        For more information, read the comments.
     84  1.13.4.1      yamt EOF
     85  1.13.4.1      yamt 	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.13.4.1      yamt CWD=$(pwd)
     99  1.13.4.1      yamt 
    100  1.13.4.1      yamt fixone() {
    101  1.13.4.1      yamt 	local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }')
    102  1.13.4.1      yamt 	local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }')
    103  1.13.4.1      yamt 	local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }')
    104  1.13.4.1      yamt 	local ms="The following libraries have versions greater than the source"
    105  1.13.4.1      yamt 
    106  1.13.4.1      yamt 	# If they're greater than the source, complain.
    107  1.13.4.1      yamt 	if [ "0$major" -eq "0$instmajor" ]; then
    108  1.13.4.1      yamt 		if [ "0$minor" -eq "0$instminor" ]; then
    109  1.13.4.1      yamt 			if [ "0$teeny" -lt "0$instteeny" ]; then
    110  1.13.4.1      yamt 				if [ $error -eq 0 -a $quiet -eq 0 ]; then
    111  1.13.4.1      yamt 					echo "$ms" 1>&2
    112  1.13.4.1      yamt 				fi
    113  1.13.4.1      yamt 				echo $1 1>&2
    114  1.13.4.1      yamt 				error=1
    115  1.13.4.1      yamt 			fi
    116  1.13.4.1      yamt 		elif [ "0$minor" -lt "0$instminor" ]; then
    117  1.13.4.1      yamt 			if [ $error -eq 0 -a $quiet -eq 0 ]; then
    118  1.13.4.1      yamt 				echo "$ms" 1>&2
    119  1.13.4.1      yamt 			fi
    120  1.13.4.1      yamt 			echo $1 1>&2
    121  1.13.4.1      yamt 			error=1
    122  1.13.4.1      yamt 		fi
    123  1.13.4.1      yamt 	elif [ "0$major" -lt "0$instmajor" ]; then
    124  1.13.4.1      yamt 		if [ $error -eq 0 -a $quiet -eq 0 ]; then
    125  1.13.4.1      yamt 			echo "$ms" 1>&2
    126  1.13.4.1      yamt 		fi
    127  1.13.4.1      yamt 		echo $1 1>&2
    128  1.13.4.1      yamt 		error=1
    129  1.13.4.1      yamt 	fi
    130  1.13.4.1      yamt }
    131  1.13.4.1      yamt 
    132  1.13.4.1      yamt while getopts df:shqv: f; do
    133  1.13.4.1      yamt 	case $f in
    134  1.13.4.1      yamt 	d)	usedir=1 
    135  1.13.4.1      yamt 		if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
    136  1.13.4.1      yamt 			Usage
    137  1.13.4.1      yamt 		fi;;
    138  1.13.4.1      yamt 	f)	usefile=1; arg1=$OPTARG
    139  1.13.4.1      yamt 		if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
    140  1.13.4.1      yamt 			Usage 
    141  1.13.4.1      yamt 		fi;;
    142  1.13.4.1      yamt 	s)	usesets=1 
    143  1.13.4.1      yamt 		if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
    144  1.13.4.1      yamt 			Usage
    145  1.13.4.1      yamt 		fi;;
    146  1.13.4.1      yamt 	v)	shlib_version=$OPTARG;;
    147  1.13.4.1      yamt 	q)	quiet=1;;
    148  1.13.4.1      yamt 	*)	Usage;;
    149  1.13.4.1      yamt 	esac
    150       1.2       erh done
    151       1.2       erh 
    152  1.13.4.1      yamt shift $(($OPTIND - 1))
    153  1.13.4.1      yamt 
    154  1.13.4.1      yamt if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then
    155  1.13.4.1      yamt 	Usage
    156       1.2       erh fi
    157       1.2       erh 
    158  1.13.4.1      yamt if [ $usefile -eq 1 ]; then
    159  1.13.4.1      yamt 	LIBLIST="$arg1"
    160       1.1       erh else
    161  1.13.4.1      yamt 	if ! mkdir -m 0700 $TMP; then
    162  1.13.4.1      yamt 		echo "$PROG: Unable to create temp directory." 1>&2
    163  1.13.4.1      yamt 		exit 2
    164  1.13.4.1      yamt 	fi
    165  1.13.4.1      yamt 	LIBLIST=$TMP/libs.lst
    166       1.2       erh fi
    167       1.2       erh 
    168       1.2       erh # Build list from the installed libraries.
    169  1.13.4.1      yamt if [ $usedir -eq 1 ]; then
    170  1.13.4.1      yamt 	if [ -n "$1" ]; then
    171  1.13.4.1      yamt 		libdir="$1"
    172  1.13.4.1      yamt 	fi
    173  1.13.4.1      yamt 	for f in $libdir; do
    174  1.13.4.1      yamt 		ls $f/lib*.so.*.*
    175  1.13.4.1      yamt 	done > $LIBLIST 2> /dev/null
    176       1.1       erh fi
    177       1.1       erh 
    178       1.2       erh # Build list from set lists.  Parameter may be either
    179       1.2       erh # the "lists" directory or the top of the source tree.
    180  1.13.4.1      yamt if [ $usesets -eq 1 ]; then
    181  1.13.4.1      yamt 	if [ -n "$1" ]; then
    182  1.13.4.1      yamt 		setsdir="$1"
    183  1.13.4.1      yamt 		if [ -d "$setsdir/distrib/sets/lists" ]; then
    184  1.13.4.1      yamt 			setsdir="$setsdir/distrib/sets/lists"
    185  1.13.4.1      yamt 		fi
    186       1.2       erh 	fi
    187  1.13.4.1      yamt 	(cd $setsdir;
    188  1.13.4.1      yamt 	 cat */[a-z]* |
    189  1.13.4.1      yamt 	 grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' |
    190  1.13.4.1      yamt 	 sort -u > $LIBLIST)
    191       1.1       erh fi
    192       1.1       erh 
    193       1.2       erh #
    194       1.2       erh # The file $LIBLIST now contains a list of libraries.
    195       1.2       erh #
    196  1.13.4.1      yamt if [ -z "$2" ]; then
    197  1.13.4.1      yamt 	makefile=$CWD/Makefile
    198  1.13.4.1      yamt 	libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//')
    199  1.13.4.1      yamt 
    200  1.13.4.1      yamt 	# Assume the library name is the name of the current directory.
    201  1.13.4.1      yamt 	if [ -z "$libname" ]; then
    202  1.13.4.1      yamt 		libname=$(basename $CWD)
    203  1.13.4.1      yamt 	fi
    204       1.2       erh else
    205  1.13.4.1      yamt 	    libname="$2"
    206       1.2       erh fi
    207       1.5  christos echo $libname | grep "^lib" 1>&2 2> /dev/null
    208       1.5  christos if [ $? != 0 ]; then
    209  1.13.4.1      yamt 	libname="lib$libname"
    210       1.2       erh fi
    211       1.1       erh 
    212       1.1       erh 
    213  1.13.4.1      yamt if [ ! -f $shlib_version ]; then
    214  1.13.4.1      yamt 	echo "$PROG: unable to find $shlib_version" 1>&2
    215  1.13.4.1      yamt 	exit 2
    216       1.1       erh fi
    217       1.1       erh 
    218       1.1       erh # Grab major and minor numbers from the source.
    219       1.6    simonb . $shlib_version
    220       1.1       erh 
    221  1.13.4.1      yamt if [ -z "$minor" -o -z "$major" ]; then
    222  1.13.4.1      yamt 	echo "$PROG: $shlib_version doesn't contain the version." 1>&2
    223  1.13.4.1      yamt 	exit 2
    224       1.1       erh fi
    225       1.1       erh 
    226       1.1       erh # Find every shared object library with the same base name.
    227  1.13.4.1      yamt for instlib in $(grep $libname.so "$LIBLIST"); do
    228  1.13.4.1      yamt 	# Grab the major and minor from the installed library.
    229  1.13.4.1      yamt 	fixone "$instlib"
    230  1.13.4.1      yamt done
    231       1.1       erh 
    232       1.1       erh exit $error
    233