scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

cleanlibs (1392B)


      1 #!/bin/sh
      2 # Clean up seemingly unused system libraries
      3 #
      4 # $Beard: cleanlibs,v 1.1 2014/01/08 23:04:40 alexander Exp $
      5 #
      6 # Copyright (c) 2014 Alexander Hall <alexander@beard.se>
      7 #
      8 # Permission to use, copy, modify, and distribute this software for any
      9 # purpose with or without fee is hereby granted, provided that the above
     10 # copyright notice and this permission notice appear in all copies.
     11 #
     12 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     16 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     17 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     18 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     19 
     20 usage() {
     21 	echo "usage: ${0##*/} [-n]" >&2
     22 	exit 1
     23 }
     24 
     25 NOP=
     26 OPTS=
     27 PREFIX=/usr/lib/lib
     28 PKGDB=/var/db/pkg
     29 LIBCAT='@wantlib'
     30 
     31 while getopts 'n' opt "$@" 2>/dev/null; do
     32 	case $opt in
     33 	n)	NOP=echo;;
     34 	*)	usage;;
     35 	esac
     36 done
     37 
     38 ls -1 $PREFIX*.so.* |
     39 sed "s|$PREFIX||;s|\.so\.|.|" |
     40 sort -r -t. -k1,1 -n -k2,3 |
     41 awk -F. 'a[$1]++' |
     42 grep -v -hf/dev/fd/3 3<<_ |
     43 $(find $PKGDB -name +CONTENTS -type f -exec sed -n "s/^$LIBCAT //p" {} + | sort -u)
     44 _
     45 sort -u |
     46 sed "s|\.|\.so\.|;s|^|$PREFIX|" |
     47 xargs -r $NOP rm