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