1 #!/bin/sh 2 # $NetBSD: checkoldver,v 1.5 2024/05/29 13:35:12 christos 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 36 delete() { 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 printf "${PWD}/${obsol}\n" 51 } 52 53 comparelib() { 54 local name="${1%.so.*}" 55 local version="${1#"${name}"*.so.}" 56 local IFS=. 57 set -- $version 58 59 if [ -z "$libmajor" ] 60 then 61 libname="$name" 62 libmajor="$1" 63 libminor="$2" 64 libtiny="$3" 65 return 66 fi 67 if [ "$libmajor" -lt "$1" ] 68 then 69 delete "$libname" "$libmajor" "$libminor" "$libtiny" 70 libmajor="$1" 71 libminor="$2" 72 libtiny="$3" 73 return 74 elif [ "$1" -lt "$libmajor" ] 75 then 76 delete "$libname" "$1" "$2" "$3" 77 return 78 fi 79 80 if [ -z "$libminor" ] 81 then 82 return 83 fi 84 if [ "$libminor" -lt "$2" ] 85 then 86 delete "$libname" "$libmajor" "$libminor" "$libtiny" 87 libmajor="$1" 88 libminor="$2" 89 libtiny="$3" 90 return 91 elif [ "$2" -lt "$libminor" ] 92 then 93 delete "$libname" "$1" "$2" "$3" 94 return 95 fi 96 97 if [ -z "$libtiny" ] 98 then 99 return 100 fi 101 if [ "$libtiny" -lt "$3" ] 102 then 103 delete "$libname" "$libmajor" "$libminor" "$libtiny" 104 libmajor="$1" 105 libminor="$2" 106 libtiny="$3" 107 return 108 elif [ "$5" -lt "$libminor" ] 109 then 110 delete "$libname" "$1" "$2" "$3" 111 return 112 fi 113 } 114 115 processonedir() { 116 cd "$1" 117 for lib in lib*.so 118 do 119 lib="${lib#lib}" 120 lib="${lib%.so}" 121 122 libmajor= 123 libminor= 124 libtiny= 125 for link in lib$lib.so.[0-9]*.[0-9]*.[0-9]* 126 do 127 comparelib "$link" 128 done 129 130 libmajor= 131 libminor= 132 libtiny= 133 for link in lib$lib.so.[0-9]*.[0-9]* 134 do 135 comparelib "$link" 136 done 137 138 libmajor= 139 libminor= 140 libtiny= 141 for link in lib$lib.so.[0-9]* 142 do 143 comparelib "$link" 144 done 145 done 146 } 147 148 for i 149 do 150 processonedir "$i" 151 done 152