Path: blob/main/Tools/scripts/top-size-offenders.sh
18157 views
#!/bin/sh1#2# This script produces a report like this:3#4# Combined size of ports: 510.5 Mb5# The Top 20 ports by size account for 15.14% of the collection6# ====================================================================7# [snipped 15 rows]8# 0.37% 1.87Mb security/cracklib9# 0.66% 3.38Mb security/vuxml10# 0.87% 4.42Mb print/texlive-texmf11# 2.82% 14.41Mb java/openjdk712# 6.79% 34.66Mb java/openjdk813# ====================================================================14# 15.14% 77.29Mb15#16# Written by John Marino <[email protected]> one rainy day just because ...17#1819TOP=2020DUK="du -kd 1 -t 200k [a-z]*"21DASH="======================================================================="22SCRATCH=/tmp/topX2324AWKCMD1='BEGIN { FS="/"; }{ if (NF == 2) { print $0; }}'25AWKCMD2='BEGIN { total=0; } { total = total + $1 } END { print total }'26AWKCMD3='{ pc=100.0*$1/total; mega=$1/1024.0; \27printf("%5.2f%% %5.2fMb %s\n", pc, mega, $2)}'2829cd /usr/ports && ${DUK} | awk "${AWKCMD1}" | sort -n | tail -n ${TOP} \30> ${SCRATCH}3132total=$(du -sk /usr/ports/[a-z]* | awk "${AWKCMD2}")33outlaws=$(awk "${AWKCMD2}" ${SCRATCH})34megabytes=$(bc -e "scale = 2; ${total} / 1024" -e quit)35bloat=$(bc -e "scale = 2; ${outlaws} / 1024" -e quit)36PC=$(bc -e "scale = 2; 100 * ${outlaws} / ${total}" -e quit)3738printf "Combined size of ports: %1.1f Mb\n" ${megabytes}39printf "The Top %d ports by size account for %1.2f%% of the collection\n" \40${TOP} ${PC}41echo ${DASH}42awk -v total=${total} "${AWKCMD3}" ${SCRATCH}43echo ${DASH}44printf "%5.2f%% %5.2fMb\n" ${PC} ${bloat}45rm ${SCRATCH}464748