11.1Schristos#!/bin/sh
21.5Schristos#	$NetBSD: checkoldver,v 1.5 2024/05/29 13:35:12 christos Exp $
31.1Schristos#
41.1Schristos# Copyright (c) 2002 The NetBSD Foundation, Inc.
51.1Schristos# All rights reserved.
61.1Schristos#
71.1Schristos# This code is derived from software contributed to The NetBSD Foundation
81.1Schristos# by Christos Zoulas.
91.1Schristos#
101.1Schristos# Redistribution and use in source and binary forms, with or without
111.1Schristos# modification, are permitted provided that the following conditions
121.1Schristos# are met:
131.1Schristos# 1. Redistributions of source code must retain the above copyright
141.1Schristos#    notice, this list of conditions and the following disclaimer.
151.1Schristos# 2. Redistributions in binary form must reproduce the above copyright
161.1Schristos#    notice, this list of conditions and the following disclaimer in the
171.1Schristos#    documentation and/or other materials provided with the distribution.
181.1Schristos#
191.1Schristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Schristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Schristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Schristos# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Schristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Schristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Schristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Schristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Schristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Schristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Schristos# POSSIBILITY OF SUCH DAMAGE.
301.1Schristos#
311.1Schristos# checkoldver [dir ...]
321.1Schristos#
331.1Schristos# Looks in the given directories for old shared libraries and lists them
341.1Schristos# Useful for: 'checkoldver /usr/lib | xargs rm -f'
351.1Schristos
361.1Schristosdelete() {
371.2Schristos	obsol="$1.so"
381.1Schristos	if [ ! -z "$2" ]
391.1Schristos	then
401.1Schristos		obsol="$obsol.$2"
411.1Schristos	fi
421.1Schristos	if [ ! -z "$3" ]
431.1Schristos	then
441.1Schristos		obsol="$obsol.$3"
451.1Schristos	fi
461.1Schristos	if [ ! -z "$4" ]
471.1Schristos	then
481.1Schristos		obsol="$obsol.$4"
491.1Schristos	fi
501.5Schristos	printf "${PWD}/${obsol}\n"
511.1Schristos}
521.1Schristos
531.1Schristoscomparelib() {
541.4Schristos	local name="${1%.so.*}"
551.5Schristos	local version="${1#"${name}"*.so.}"
561.5Schristos	local IFS=.
571.4Schristos	set -- $version
581.1Schristos
591.1Schristos	if [ -z "$libmajor" ]
601.1Schristos	then
611.4Schristos		libname="$name"
621.4Schristos		libmajor="$1"
631.4Schristos		libminor="$2"
641.4Schristos		libtiny="$3"
651.1Schristos		return
661.1Schristos	fi
671.4Schristos	if [ "$libmajor" -lt "$1" ]
681.1Schristos	then
691.1Schristos		delete "$libname" "$libmajor" "$libminor" "$libtiny"
701.4Schristos		libmajor="$1"
711.4Schristos		libminor="$2"
721.4Schristos		libtiny="$3"
731.1Schristos		return
741.4Schristos	elif [ "$1" -lt "$libmajor" ]
751.1Schristos	then
761.4Schristos		delete "$libname" "$1" "$2" "$3"
771.1Schristos		return
781.1Schristos	fi
791.1Schristos
801.1Schristos	if [ -z "$libminor" ]
811.1Schristos	then
821.1Schristos		return
831.1Schristos	fi
841.4Schristos	if [ "$libminor" -lt "$2" ]
851.1Schristos	then
861.1Schristos		delete "$libname" "$libmajor" "$libminor" "$libtiny"
871.4Schristos		libmajor="$1"
881.4Schristos		libminor="$2"
891.4Schristos		libtiny="$3"
901.1Schristos		return
911.4Schristos	elif [ "$2" -lt "$libminor" ]
921.1Schristos	then
931.4Schristos		delete "$libname" "$1" "$2" "$3"
941.1Schristos		return
951.1Schristos	fi
961.1Schristos
971.1Schristos	if [ -z "$libtiny" ]
981.1Schristos	then
991.1Schristos		return
1001.1Schristos	fi
1011.4Schristos	if [ "$libtiny" -lt "$3" ]
1021.1Schristos	then
1031.1Schristos		delete "$libname" "$libmajor" "$libminor" "$libtiny"
1041.4Schristos		libmajor="$1"
1051.4Schristos		libminor="$2"
1061.4Schristos		libtiny="$3"
1071.1Schristos		return
1081.1Schristos	elif [ "$5" -lt "$libminor" ]
1091.1Schristos	then
1101.4Schristos		delete "$libname" "$1" "$2" "$3"
1111.1Schristos		return
1121.1Schristos	fi
1131.1Schristos}
1141.1Schristos
1151.1Schristosprocessonedir() {
1161.1Schristos	cd "$1"
1171.1Schristos	for lib in lib*.so
1181.1Schristos	do
1191.1Schristos		lib="${lib#lib}"
1201.1Schristos		lib="${lib%.so}"
1211.1Schristos
1221.1Schristos		libmajor=
1231.1Schristos		libminor=
1241.1Schristos		libtiny=
1251.1Schristos		for link in lib$lib.so.[0-9]*.[0-9]*.[0-9]*
1261.1Schristos		do
1271.1Schristos			comparelib "$link"
1281.1Schristos		done
1291.1Schristos
1301.1Schristos		libmajor=
1311.1Schristos		libminor=
1321.1Schristos		libtiny=
1331.1Schristos		for link in lib$lib.so.[0-9]*.[0-9]*
1341.1Schristos		do
1351.1Schristos			comparelib "$link"
1361.1Schristos		done
1371.1Schristos
1381.1Schristos		libmajor=
1391.1Schristos		libminor=
1401.1Schristos		libtiny=
1411.1Schristos		for link in lib$lib.so.[0-9]*
1421.1Schristos		do
1431.1Schristos			comparelib "$link"
1441.1Schristos		done
1451.1Schristos	done
1461.1Schristos}
1471.1Schristos
1481.1Schristosfor i
1491.1Schristosdo
1501.1Schristos	processonedir "$i"
1511.1Schristosdone
152