1#!/bin/sh 2# $NetBSD: checkoldver,v 1.3 2008/04/30 13:10:50 martin Exp $ 3# 4# Copyright (c) 2002 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Christos Zoulas. 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# checkoldver [dir ...] 32# 33# Looks in the given directories for old shared libraries and lists them 34# Useful for: 'checkoldver /usr/lib | xargs rm -f' 35 36delete() { 37 obsol="$1.so" 38 if [ ! -z "$2" ] 39 then 40 obsol="$obsol.$2" 41 fi 42 if [ ! -z "$3" ] 43 then 44 obsol="$obsol.$3" 45 fi 46 if [ ! -z "$4" ] 47 then 48 obsol="$obsol.$4" 49 fi 50 echo $PWD/$obsol 51} 52 53comparelib() { 54 OIFS="$IFS" 55 IFS="$IFS." 56 set -- $1 57 IFS="$OIFS" 58 if [ "$3" = "[0-9]*" ] 59 then 60 return 61 fi 62 63 if [ -z "$libmajor" ] 64 then 65 libname="$1" 66 libmajor="$3" 67 libminor="$4" 68 libtiny="$5" 69 return 70 fi 71 if [ "$libmajor" -lt "$3" ] 72 then 73 delete "$libname" "$libmajor" "$libminor" "$libtiny" 74 libmajor="$3" 75 libminor="$4" 76 libtiny="$5" 77 return 78 elif [ "$3" -lt "$libmajor" ] 79 then 80 delete "$libname" "$3" "$4" "$5" 81 return 82 fi 83 84 if [ -z "$libminor" ] 85 then 86 return 87 fi 88 if [ "$libminor" -lt "$4" ] 89 then 90 delete "$libname" "$libmajor" "$libminor" "$libtiny" 91 libmajor="$3" 92 libminor="$4" 93 libtiny="$5" 94 return 95 elif [ "$4" -lt "$libminor" ] 96 then 97 delete "$libname" "$3" "$4" "$5" 98 return 99 fi 100 101 if [ -z "$libtiny" ] 102 then 103 return 104 fi 105 if [ "$libtiny" -lt "$5" ] 106 then 107 delete "$libname" "$libmajor" "$libminor" "$libtiny" 108 libmajor="$3" 109 libminor="$4" 110 libtiny="$5" 111 return 112 elif [ "$5" -lt "$libminor" ] 113 then 114 delete "$libname" "$3" "$4" "$5" 115 return 116 fi 117} 118 119processonedir() { 120 cd "$1" 121 for lib in lib*.so 122 do 123 lib="${lib#lib}" 124 lib="${lib%.so}" 125 126 libmajor= 127 libminor= 128 libtiny= 129 for link in lib$lib.so.[0-9]*.[0-9]*.[0-9]* 130 do 131 comparelib "$link" 132 done 133 134 libmajor= 135 libminor= 136 libtiny= 137 for link in lib$lib.so.[0-9]*.[0-9]* 138 do 139 comparelib "$link" 140 done 141 142 libmajor= 143 libminor= 144 libtiny= 145 for link in lib$lib.so.[0-9]* 146 do 147 comparelib "$link" 148 done 149 done 150} 151 152for i 153do 154 processonedir "$i" 155done 156