11949be05Schristos#!/bin/sh 2*2e795eb8Schristos# $NetBSD: checkoldver,v 1.5 2024/05/29 13:35:12 christos Exp $ 31949be05Schristos# 41949be05Schristos# Copyright (c) 2002 The NetBSD Foundation, Inc. 51949be05Schristos# All rights reserved. 61949be05Schristos# 71949be05Schristos# This code is derived from software contributed to The NetBSD Foundation 81949be05Schristos# by Christos Zoulas. 91949be05Schristos# 101949be05Schristos# Redistribution and use in source and binary forms, with or without 111949be05Schristos# modification, are permitted provided that the following conditions 121949be05Schristos# are met: 131949be05Schristos# 1. Redistributions of source code must retain the above copyright 141949be05Schristos# notice, this list of conditions and the following disclaimer. 151949be05Schristos# 2. Redistributions in binary form must reproduce the above copyright 161949be05Schristos# notice, this list of conditions and the following disclaimer in the 171949be05Schristos# documentation and/or other materials provided with the distribution. 181949be05Schristos# 191949be05Schristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201949be05Schristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211949be05Schristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221949be05Schristos# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231949be05Schristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241949be05Schristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251949be05Schristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261949be05Schristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271949be05Schristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281949be05Schristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291949be05Schristos# POSSIBILITY OF SUCH DAMAGE. 301949be05Schristos# 311949be05Schristos# checkoldver [dir ...] 321949be05Schristos# 331949be05Schristos# Looks in the given directories for old shared libraries and lists them 341949be05Schristos# Useful for: 'checkoldver /usr/lib | xargs rm -f' 351949be05Schristos 361949be05Schristosdelete() { 37075b8347Schristos obsol="$1.so" 381949be05Schristos if [ ! -z "$2" ] 391949be05Schristos then 401949be05Schristos obsol="$obsol.$2" 411949be05Schristos fi 421949be05Schristos if [ ! -z "$3" ] 431949be05Schristos then 441949be05Schristos obsol="$obsol.$3" 451949be05Schristos fi 461949be05Schristos if [ ! -z "$4" ] 471949be05Schristos then 481949be05Schristos obsol="$obsol.$4" 491949be05Schristos fi 50*2e795eb8Schristos printf "${PWD}/${obsol}\n" 511949be05Schristos} 521949be05Schristos 531949be05Schristoscomparelib() { 545c694b5eSchristos local name="${1%.so.*}" 55*2e795eb8Schristos local version="${1#"${name}"*.so.}" 56*2e795eb8Schristos local IFS=. 575c694b5eSchristos set -- $version 581949be05Schristos 591949be05Schristos if [ -z "$libmajor" ] 601949be05Schristos then 615c694b5eSchristos libname="$name" 625c694b5eSchristos libmajor="$1" 635c694b5eSchristos libminor="$2" 645c694b5eSchristos libtiny="$3" 651949be05Schristos return 661949be05Schristos fi 675c694b5eSchristos if [ "$libmajor" -lt "$1" ] 681949be05Schristos then 691949be05Schristos delete "$libname" "$libmajor" "$libminor" "$libtiny" 705c694b5eSchristos libmajor="$1" 715c694b5eSchristos libminor="$2" 725c694b5eSchristos libtiny="$3" 731949be05Schristos return 745c694b5eSchristos elif [ "$1" -lt "$libmajor" ] 751949be05Schristos then 765c694b5eSchristos delete "$libname" "$1" "$2" "$3" 771949be05Schristos return 781949be05Schristos fi 791949be05Schristos 801949be05Schristos if [ -z "$libminor" ] 811949be05Schristos then 821949be05Schristos return 831949be05Schristos fi 845c694b5eSchristos if [ "$libminor" -lt "$2" ] 851949be05Schristos then 861949be05Schristos delete "$libname" "$libmajor" "$libminor" "$libtiny" 875c694b5eSchristos libmajor="$1" 885c694b5eSchristos libminor="$2" 895c694b5eSchristos libtiny="$3" 901949be05Schristos return 915c694b5eSchristos elif [ "$2" -lt "$libminor" ] 921949be05Schristos then 935c694b5eSchristos delete "$libname" "$1" "$2" "$3" 941949be05Schristos return 951949be05Schristos fi 961949be05Schristos 971949be05Schristos if [ -z "$libtiny" ] 981949be05Schristos then 991949be05Schristos return 1001949be05Schristos fi 1015c694b5eSchristos if [ "$libtiny" -lt "$3" ] 1021949be05Schristos then 1031949be05Schristos delete "$libname" "$libmajor" "$libminor" "$libtiny" 1045c694b5eSchristos libmajor="$1" 1055c694b5eSchristos libminor="$2" 1065c694b5eSchristos libtiny="$3" 1071949be05Schristos return 1081949be05Schristos elif [ "$5" -lt "$libminor" ] 1091949be05Schristos then 1105c694b5eSchristos delete "$libname" "$1" "$2" "$3" 1111949be05Schristos return 1121949be05Schristos fi 1131949be05Schristos} 1141949be05Schristos 1151949be05Schristosprocessonedir() { 1161949be05Schristos cd "$1" 1171949be05Schristos for lib in lib*.so 1181949be05Schristos do 1191949be05Schristos lib="${lib#lib}" 1201949be05Schristos lib="${lib%.so}" 1211949be05Schristos 1221949be05Schristos libmajor= 1231949be05Schristos libminor= 1241949be05Schristos libtiny= 1251949be05Schristos for link in lib$lib.so.[0-9]*.[0-9]*.[0-9]* 1261949be05Schristos do 1271949be05Schristos comparelib "$link" 1281949be05Schristos done 1291949be05Schristos 1301949be05Schristos libmajor= 1311949be05Schristos libminor= 1321949be05Schristos libtiny= 1331949be05Schristos for link in lib$lib.so.[0-9]*.[0-9]* 1341949be05Schristos do 1351949be05Schristos comparelib "$link" 1361949be05Schristos done 1371949be05Schristos 1381949be05Schristos libmajor= 1391949be05Schristos libminor= 1401949be05Schristos libtiny= 1411949be05Schristos for link in lib$lib.so.[0-9]* 1421949be05Schristos do 1431949be05Schristos comparelib "$link" 1441949be05Schristos done 1451949be05Schristos done 1461949be05Schristos} 1471949be05Schristos 1481949be05Schristosfor i 1491949be05Schristosdo 1501949be05Schristos processonedir "$i" 1511949be05Schristosdone 152