checkoldver revision 1.4 1 1.1 christos #!/bin/sh
2 1.4 christos # $NetBSD: checkoldver,v 1.4 2024/05/28 16:20:34 christos Exp $
3 1.1 christos #
4 1.1 christos # Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 christos # All rights reserved.
6 1.1 christos #
7 1.1 christos # This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos # by Christos Zoulas.
9 1.1 christos #
10 1.1 christos # Redistribution and use in source and binary forms, with or without
11 1.1 christos # modification, are permitted provided that the following conditions
12 1.1 christos # are met:
13 1.1 christos # 1. Redistributions of source code must retain the above copyright
14 1.1 christos # notice, this list of conditions and the following disclaimer.
15 1.1 christos # 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos # notice, this list of conditions and the following disclaimer in the
17 1.1 christos # documentation and/or other materials provided with the distribution.
18 1.1 christos #
19 1.1 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 christos # POSSIBILITY OF SUCH DAMAGE.
30 1.1 christos #
31 1.1 christos # checkoldver [dir ...]
32 1.1 christos #
33 1.1 christos # Looks in the given directories for old shared libraries and lists them
34 1.1 christos # Useful for: 'checkoldver /usr/lib | xargs rm -f'
35 1.1 christos
36 1.1 christos delete() {
37 1.2 christos obsol="$1.so"
38 1.1 christos if [ ! -z "$2" ]
39 1.1 christos then
40 1.1 christos obsol="$obsol.$2"
41 1.1 christos fi
42 1.1 christos if [ ! -z "$3" ]
43 1.1 christos then
44 1.1 christos obsol="$obsol.$3"
45 1.1 christos fi
46 1.1 christos if [ ! -z "$4" ]
47 1.1 christos then
48 1.1 christos obsol="$obsol.$4"
49 1.1 christos fi
50 1.1 christos echo $PWD/$obsol
51 1.1 christos }
52 1.1 christos
53 1.1 christos comparelib() {
54 1.4 christos local name="${1%.so.*}"
55 1.4 christos local version=${1#*.so.}
56 1.1 christos OIFS="$IFS"
57 1.1 christos IFS="$IFS."
58 1.4 christos set -- $version
59 1.1 christos IFS="$OIFS"
60 1.1 christos
61 1.1 christos if [ -z "$libmajor" ]
62 1.1 christos then
63 1.4 christos libname="$name"
64 1.4 christos libmajor="$1"
65 1.4 christos libminor="$2"
66 1.4 christos libtiny="$3"
67 1.1 christos return
68 1.1 christos fi
69 1.4 christos if [ "$libmajor" -lt "$1" ]
70 1.1 christos then
71 1.1 christos delete "$libname" "$libmajor" "$libminor" "$libtiny"
72 1.4 christos libmajor="$1"
73 1.4 christos libminor="$2"
74 1.4 christos libtiny="$3"
75 1.1 christos return
76 1.4 christos elif [ "$1" -lt "$libmajor" ]
77 1.1 christos then
78 1.4 christos delete "$libname" "$1" "$2" "$3"
79 1.1 christos return
80 1.1 christos fi
81 1.1 christos
82 1.1 christos if [ -z "$libminor" ]
83 1.1 christos then
84 1.1 christos return
85 1.1 christos fi
86 1.4 christos if [ "$libminor" -lt "$2" ]
87 1.1 christos then
88 1.1 christos delete "$libname" "$libmajor" "$libminor" "$libtiny"
89 1.4 christos libmajor="$1"
90 1.4 christos libminor="$2"
91 1.4 christos libtiny="$3"
92 1.1 christos return
93 1.4 christos elif [ "$2" -lt "$libminor" ]
94 1.1 christos then
95 1.4 christos delete "$libname" "$1" "$2" "$3"
96 1.1 christos return
97 1.1 christos fi
98 1.1 christos
99 1.1 christos if [ -z "$libtiny" ]
100 1.1 christos then
101 1.1 christos return
102 1.1 christos fi
103 1.4 christos if [ "$libtiny" -lt "$3" ]
104 1.1 christos then
105 1.1 christos delete "$libname" "$libmajor" "$libminor" "$libtiny"
106 1.4 christos libmajor="$1"
107 1.4 christos libminor="$2"
108 1.4 christos libtiny="$3"
109 1.1 christos return
110 1.1 christos elif [ "$5" -lt "$libminor" ]
111 1.1 christos then
112 1.4 christos delete "$libname" "$1" "$2" "$3"
113 1.1 christos return
114 1.1 christos fi
115 1.1 christos }
116 1.1 christos
117 1.1 christos processonedir() {
118 1.1 christos cd "$1"
119 1.1 christos for lib in lib*.so
120 1.1 christos do
121 1.1 christos lib="${lib#lib}"
122 1.1 christos lib="${lib%.so}"
123 1.1 christos
124 1.1 christos libmajor=
125 1.1 christos libminor=
126 1.1 christos libtiny=
127 1.1 christos for link in lib$lib.so.[0-9]*.[0-9]*.[0-9]*
128 1.1 christos do
129 1.1 christos comparelib "$link"
130 1.1 christos done
131 1.1 christos
132 1.1 christos libmajor=
133 1.1 christos libminor=
134 1.1 christos libtiny=
135 1.1 christos for link in lib$lib.so.[0-9]*.[0-9]*
136 1.1 christos do
137 1.1 christos comparelib "$link"
138 1.1 christos done
139 1.1 christos
140 1.1 christos libmajor=
141 1.1 christos libminor=
142 1.1 christos libtiny=
143 1.1 christos for link in lib$lib.so.[0-9]*
144 1.1 christos do
145 1.1 christos comparelib "$link"
146 1.1 christos done
147 1.1 christos done
148 1.1 christos }
149 1.1 christos
150 1.1 christos for i
151 1.1 christos do
152 1.1 christos processonedir "$i"
153 1.1 christos done
154