3 # find unused shared libraries and remove them, repeat until there are no
4 # more to remove - david.mccullough@accelecon.com
8 echo "usage: $0 <romfsdir>" >&2
13 if [ ! -d "$ROMFS" ]; then
14 echo "Target directory $ROMFS does nto exist." >&2
18 TMPF=/tmp/$$.find-unused
20 TMPW=/tmp/$$.find-work
21 trap "rm -f $TMPW $TMPS $TMPF $TMPF.1; exit 0" 0
23 echo "Cleaning rootfs ($ROMFS) of unused .so files ..."
25 # find all the shared libs used bya a file
26 find "$ROMFS" -type f | while read t; do
27 readelf -d $t 2> /dev/null | grep 'Shared lib' |
28 sed -e 's/^.*\[//' -e 's/]$//' | while read c
33 find "$ROMFS" -type f -a \( -name '*.so' -o -name '*.so.*' \) > $TMPS
38 find "$ROMFS" -type l -a \( -name '*.so' -o -name '*.so.*' \) | while read lnk
41 #echo "`basename $rf` ---- $find"
42 [ "`basename $rf`" = "$find" ] && echo "$lnk"
46 find_pattern_in_files()
51 done | awk '{ printf $2 }'
58 [ -f "$so" ] || continue
59 LNKS="`find_symlinks \"$so\"`"
64 LOOK="$LOOK `basename $i`"
67 # echo "checking $so - $LOOK ..."
69 USERS=`find_pattern_in_files "$LOOK"`
76 echo "Skipping plugin file $so"
77 echo "`basename $so`: plugin" >> $TMPF
80 echo "Skipping PAM file $so"
81 echo "`basename $so`: PAM" >> $TMPF
84 echo "Skipping netfilter file $so"
85 echo "`basename $so`: netfilter" >> $TMPF
89 echo "Removing $so ..."
91 # remove reference this file has
92 egrep -v ": $so\$" $TMPF > $TMPF.1
99 [ -f "$TMPW" ] || break