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