Annotation of src/lib/checkver, Revision 1.16
1.5 christos 1: #!/bin/sh
1.16 ! christos 2: # $NetBSD: checkver,v 1.15 2013/02/17 01:26:47 christos Exp $
1.1 erh 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: #--------------------------------------------------------------------#
1.9 erh 33: # checkver -
34: # Check for libraries that appear to be newer than the
35: # one we're about to install.
36: #
1.6 simonb 37: # checkver [-q] [-v shlib_version_file] -d [installedlibdir [library name]]"
38: # checkver [-q] [-v shlib_version_file] -s [setlistdir [library name]]"
39: # checkver [-q] [-v shlib_version_file] -f liblistfile [library name]"
1.1 erh 40: #
1.2 erh 41: # One of -d, -s or -f must be specified.
1.1 erh 42: #
1.2 erh 43: # all: If library name is not specified it is assumed to
44: # be the name of the current directory.
45: #
46: # -d: Checks the version against the installed libraries.
47: # If no further arguments are given "/usr/lib" is
48: # used as the location of installed libraries.
49: #
50: # -s: Checks the version against the sets. If no argument
51: # follows the sets directory defaults to "/usr/src/distrib/sets/lists".
52: # The directory may be specified as either the top of the
53: # source tree or as the lists directory.
54: #
55: # -f: Checks the version against the provided list. A filename
56: # must be supplied.
1.1 erh 57: #
1.6 simonb 58: # -v: Specify the filename of the shlib_version file. Defaults
59: # to "./shlib_version".
60: #
1.8 simonb 61: # This script produces no output if all library version are not
1.1 erh 62: # large than the source version. If an installed library with a
63: # version greater than the source is found, checkver prints a
64: # header and a list of the names of the offending installed libraries.
65: #
66: # The header may be supressed by passing "-q" as the first argument.
67: #
68:
1.2 erh 69: TMP=/tmp/checkver.$$
1.15 christos 70: PROG="$(basename "$0")"
1.5 christos 71: # Can't trap 11 (SEGV) in the Real Bourne Shell, since it uses it for
72: # internal malloc!
73: trap "exit 2" 1 2 3 4 5 6 7 8 10 12 13 14 15
1.2 erh 74: trap "[ -d $TMP ] && rm -rf $TMP" 0
1.1 erh 75:
1.5 christos 76: Usage() {
1.14 christos 77: cat << EOF 1>&2
78: Usage: $PROG [-q] [-v version_file] -d [installedlibdir [library name]]
79: $PROG [-q] [-v version_file] -s [setlistdir [library name]]
80: $PROG [-q] [-v version_file] -f liblistfile [library name]
81: $PROG is a script that looks for installed libraries with
82: versions greater than that in the version file.
83: For more information, read the comments.
84: EOF
85: exit 1
1.1 erh 86: }
87:
1.2 erh 88: basedir=/usr/src
89: setsdir=$basedir/distrib/sets/lists
90: libdir=/usr/lib
1.6 simonb 91: shlib_version=./shlib_version
1.1 erh 92:
1.2 erh 93: error=0
94: quiet=0
95: usedir=0
96: usefile=0
97: usesets=0
1.14 christos 98: CWD=$(pwd)
99:
100: fixone() {
101: local instmajor=$(basename $1 | awk 'BEGIN { FS="." } { print $3 }')
102: local instminor=$(basename $1 | awk 'BEGIN { FS="." } { print $4 }')
103: local instteeny=$(basename $1 | awk 'BEGIN { FS="." } { print $5 + 0 }')
104: local ms="The following libraries have versions greater than the source"
105:
106: # If they're greater than the source, complain.
107: if [ "0$major" -eq "0$instmajor" ]; then
108: if [ "0$minor" -eq "0$instminor" ]; then
109: if [ "0$teeny" -lt "0$instteeny" ]; then
110: if [ $error -eq 0 -a $quiet -eq 0 ]; then
111: echo "$ms" 1>&2
112: fi
113: echo $1 1>&2
114: error=1
115: fi
116: elif [ "0$minor" -lt "0$instminor" ]; then
117: if [ $error -eq 0 -a $quiet -eq 0 ]; then
118: echo "$ms" 1>&2
119: fi
120: echo $1 1>&2
121: error=1
122: fi
123: elif [ "0$major" -lt "0$instmajor" ]; then
124: if [ $error -eq 0 -a $quiet -eq 0 ]; then
125: echo "$ms" 1>&2
126: fi
127: echo $1 1>&2
128: error=1
129: fi
130: }
131:
132: while getopts df:shqv: f; do
133: case $f in
134: d) usedir=1
135: if [ $usefile -eq 1 -o $usesets -eq 1 ]; then
136: Usage
137: fi;;
138: f) usefile=1; arg1=$OPTARG
139: if [ $usedir -eq 1 -o $usesets -eq 1 ]; then
140: Usage
141: fi;;
142: s) usesets=1
143: if [ $usedir -eq 1 -o $usefile -eq 1 ]; then
144: Usage
145: fi;;
1.16 ! christos 146: v) shlib_version=$OPTARG;;
! 147: q) quiet=1;;
1.14 christos 148: *) Usage;;
149: esac
1.2 erh 150: done
151:
1.14 christos 152: shift $(($OPTIND - 1))
153:
154: if [ $usedir -eq 0 -a $usefile -eq 0 -a $usesets -eq 0 ]; then
155: Usage
1.2 erh 156: fi
157:
1.14 christos 158: if [ $usefile -eq 1 ]; then
159: LIBLIST="$arg1"
1.1 erh 160: else
1.14 christos 161: if ! mkdir -m 0700 $TMP; then
162: echo "$PROG: Unable to create temp directory." 1>&2
163: exit 2
164: fi
165: LIBLIST=$TMP/libs.lst
1.2 erh 166: fi
167:
168: # Build list from the installed libraries.
1.14 christos 169: if [ $usedir -eq 1 ]; then
170: if [ -n "$1" ]; then
171: libdir="$1"
172: fi
173: for f in $libdir; do
174: ls $f/lib*.so.*.*
175: done > $LIBLIST 2> /dev/null
1.1 erh 176: fi
177:
1.2 erh 178: # Build list from set lists. Parameter may be either
179: # the "lists" directory or the top of the source tree.
1.14 christos 180: if [ $usesets -eq 1 ]; then
181: if [ -n "$1" ]; then
182: setsdir="$1"
183: if [ -d "$setsdir/distrib/sets/lists" ]; then
184: setsdir="$setsdir/distrib/sets/lists"
185: fi
1.2 erh 186: fi
1.14 christos 187: (cd $setsdir;
188: cat */[a-z]* |
189: grep '^./usr/lib/lib.*\.so\.[0-9][0-9]*\.[0-9][0-9]*' |
190: sort -u > $LIBLIST)
1.1 erh 191: fi
192:
1.2 erh 193: #
194: # The file $LIBLIST now contains a list of libraries.
195: #
1.14 christos 196: if [ -z "$2" ]; then
197: makefile=$CWD/Makefile
198: libname=$(grep '^LIB=' $makefile | sed -e 's/^LIB=[[:space:]]*//')
199:
200: # Assume the library name is the name of the current directory.
201: if [ -z "$libname" ]; then
202: libname=$(basename $CWD)
203: fi
1.2 erh 204: else
1.14 christos 205: libname="$2"
1.2 erh 206: fi
1.5 christos 207: echo $libname | grep "^lib" 1>&2 2> /dev/null
208: if [ $? != 0 ]; then
1.14 christos 209: libname="lib$libname"
1.2 erh 210: fi
1.1 erh 211:
212:
1.14 christos 213: if [ ! -f $shlib_version ]; then
214: echo "$PROG: unable to find $shlib_version" 1>&2
215: exit 2
1.1 erh 216: fi
217:
218: # Grab major and minor numbers from the source.
1.6 simonb 219: . $shlib_version
1.1 erh 220:
1.14 christos 221: if [ -z "$minor" -o -z "$major" ]; then
222: echo "$PROG: $shlib_version doesn't contain the version." 1>&2
223: exit 2
1.1 erh 224: fi
225:
226: # Find every shared object library with the same base name.
1.14 christos 227: for instlib in $(grep $libname.so "$LIBLIST"); do
228: # Grab the major and minor from the installed library.
229: fixone "$instlib"
230: done
1.1 erh 231:
232: exit $error
CVSweb <webmaster@jp.NetBSD.org>