1#!/bin/sh 2# 3# This script produces a report like this: 4# 5# Combined size of mports: 510.5 Mb 6# The Top 20 mports by size account for 15.14% of the collection 7# ==================================================================== 8# [snipped 15 rows] 9# 0.37% 1.87Mb security/cracklib 10# 0.66% 3.38Mb security/vuxml 11# 0.87% 4.42Mb print/texlive-texmf 12# 2.82% 14.41Mb java/openjdk7 13# 6.79% 34.66Mb java/openjdk8 14# ==================================================================== 15# 15.14% 77.29Mb 16# 17# Written by John Marino <marino@FreeBSD.org> one rainy day just because ... 18# 19 20TOP=20 21DUK="du -kd 1 -t 200k [a-z]*" 22DASH="=======================================================================" 23SCRATCH=/tmp/topX 24 25AWKCMD1='BEGIN { FS="/"; }{ if (NF == 2) { print $0; }}' 26AWKCMD2='BEGIN { total=0; } { total = total + $1 } END { print total }' 27AWKCMD3='{ pc=100.0*$1/total; mega=$1/1024.0; \ 28 printf("%5.2f%% %5.2fMb %s\n", pc, mega, $2)}' 29 30cd /usr/mports && ${DUK} | awk "${AWKCMD1}" | sort -n | tail -n ${TOP} \ 31 > ${SCRATCH} 32 33total=$(du -sk /usr/mports/[a-z]* | awk "${AWKCMD2}") 34outlaws=$(awk "${AWKCMD2}" ${SCRATCH}) 35megabytes=$(bc -e "scale = 2; ${total} / 1024" -e quit) 36bloat=$(bc -e "scale = 2; ${outlaws} / 1024" -e quit) 37PC=$(bc -e "scale = 2; 100 * ${outlaws} / ${total}" -e quit) 38 39printf "Combined size of mports: %1.1f Mb\n" ${megabytes} 40printf "The Top %d mports by size account for %1.2f%% of the collection\n" \ 41 ${TOP} ${PC} 42echo ${DASH} 43awk -v total=${total} "${AWKCMD3}" ${SCRATCH} 44echo ${DASH} 45printf "%5.2f%% %5.2fMb\n" ${PC} ${bloat} 46rm ${SCRATCH} 47