checkver revision 1.16 1 1.5 christos #!/bin/sh
2 1.16 christos # $NetBSD: checkver,v 1.16 2013/02/17 02:36:21 christos 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.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.14 christos
100 1.14 christos fixone() {
101 1.14 christos local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }')
102 1.14 christos local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }')
103 1.14 christos local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }')
104 1.14 christos local ms="The following libraries have versions greater than the source"
105 1.14 christos
106 1.14 christos # If they're greater than the source, complain.
107 1.14 christos if [ "0$major" -eq "0$instmajor" ]; then
108 1.14 christos if [ "0$minor" -eq "0$instminor" ]; then
109 1.14 christos if [ "0$teeny" -lt "0$instteeny" ]; then
110 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then
111 1.14 christos echo "$ms" 1>&2
112 1.14 christos fi
113 1.14 christos echo $1 1>&2
114 1.14 christos error=1
115 1.14 christos fi
116 1.14 christos elif [ "0$minor" -lt "0$instminor" ]; then
117 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then
118 1.14 christos echo "$ms" 1>&2
119 1.14 christos fi
120 1.14 christos echo $1 1>&2
121 1.14 christos error=1
122 1.14 christos fi
123 1.14 christos elif [ "0$major" -lt "0$instmajor" ]; then
124 1.14 christos if [ $error -eq 0 -a $quiet -eq 0 ]; then
125 1.14 christos echo "$ms" 1>&2
126 1.14 christos fi
127 1.14 christos echo $1 1>&2
128 1.14 christos error=1
129 1.14 christos fi
130 1.14 christos }
131 1.14 christos
132 1.14 christos while getopts df:shqv: f; do
133 1.14 christos case $f in
134 1.14 christos d) usedir=1
135 1.14 christos if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
136 1.14 christos Usage
137 1.14 christos fi;;
138 1.14 christos f) usefile=1; arg1=$OPTARG
139 1.14 christos if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
140 1.14 christos Usage
141 1.14 christos fi;;
142 1.14 christos s) usesets=1
143 1.14 christos if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
144 1.14 christos Usage
145 1.14 christos fi;;
146 1.16 christos v) shlib_version=$OPTARG;;
147 1.16 christos q) quiet=1;;
148 1.14 christos *) Usage;;
149 1.14 christos esac
150 1.2 erh done
151 1.2 erh
152 1.14 christos shift $(($OPTIND - 1))
153 1.14 christos
154 1.14 christos if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then
155 1.14 christos Usage
156 1.2 erh fi
157 1.2 erh
158 1.14 christos if [ $usefile -eq 1 ]; then
159 1.14 christos LIBLIST="$arg1"
160 1.1 erh else
161 1.14 christos if ! mkdir -m 0700 $TMP; then
162 1.14 christos echo "$PROG: Unable to create temp directory." 1>&2
163 1.14 christos exit 2
164 1.14 christos fi
165 1.14 christos 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.14 christos if [ $usedir -eq 1 ]; then
170 1.14 christos if [ -n "$1" ]; then
171 1.14 christos libdir="$1"
172 1.14 christos fi
173 1.14 christos for f in $libdir; do
174 1.14 christos ls $f/lib*.so.*.*
175 1.14 christos 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.14 christos if [ $usesets -eq 1 ]; then
181 1.14 christos if [ -n "$1" ]; then
182 1.14 christos setsdir="$1"
183 1.14 christos if [ -d "$setsdir/distrib/sets/lists" ]; then
184 1.14 christos setsdir="$setsdir/distrib/sets/lists"
185 1.14 christos fi
186 1.2 erh fi
187 1.14 christos (cd $setsdir;
188 1.14 christos cat */[a-z]* |
189 1.14 christos grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' |
190 1.14 christos 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.14 christos if [ -z "$2" ]; then
197 1.14 christos makefile=$CWD/Makefile
198 1.14 christos libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//')
199 1.14 christos
200 1.14 christos # Assume the library name is the name of the current directory.
201 1.14 christos if [ -z "$libname" ]; then
202 1.14 christos libname=$(basename $CWD)
203 1.14 christos fi
204 1.2 erh else
205 1.14 christos 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.14 christos libname="lib$libname"
210 1.2 erh fi
211 1.1 erh
212 1.1 erh
213 1.14 christos if [ ! -f $shlib_version ]; then
214 1.14 christos echo "$PROG: unable to find $shlib_version" 1>&2
215 1.14 christos 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.14 christos if [ -z "$minor" -o -z "$major" ]; then
222 1.14 christos echo "$PROG: $shlib_version doesn't contain the version." 1>&2
223 1.14 christos 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.14 christos for instlib in $(grep $libname.so "$LIBLIST"); do
228 1.14 christos # Grab the major and minor from the installed library.
229 1.14 christos fixone "$instlib"
230 1.14 christos done
231 1.1 erh
232 1.1 erh exit $error
233