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