Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/Tools/scripts/top-size-offenders.sh
18157 views
1
#!/bin/sh
2
#
3
# This script produces a report like this:
4
#
5
# Combined size of ports: 510.5 Mb
6
# The Top 20 ports 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 <[email protected]> one rainy day just because ...
18
#
19
20
TOP=20
21
DUK="du -kd 1 -t 200k [a-z]*"
22
DASH="======================================================================="
23
SCRATCH=/tmp/topX
24
25
AWKCMD1='BEGIN { FS="/"; }{ if (NF == 2) { print $0; }}'
26
AWKCMD2='BEGIN { total=0; } { total = total + $1 } END { print total }'
27
AWKCMD3='{ pc=100.0*$1/total; mega=$1/1024.0; \
28
printf("%5.2f%% %5.2fMb %s\n", pc, mega, $2)}'
29
30
cd /usr/ports && ${DUK} | awk "${AWKCMD1}" | sort -n | tail -n ${TOP} \
31
> ${SCRATCH}
32
33
total=$(du -sk /usr/ports/[a-z]* | awk "${AWKCMD2}")
34
outlaws=$(awk "${AWKCMD2}" ${SCRATCH})
35
megabytes=$(bc -e "scale = 2; ${total} / 1024" -e quit)
36
bloat=$(bc -e "scale = 2; ${outlaws} / 1024" -e quit)
37
PC=$(bc -e "scale = 2; 100 * ${outlaws} / ${total}" -e quit)
38
39
printf "Combined size of ports: %1.1f Mb\n" ${megabytes}
40
printf "The Top %d ports by size account for %1.2f%% of the collection\n" \
41
${TOP} ${PC}
42
echo ${DASH}
43
awk -v total=${total} "${AWKCMD3}" ${SCRATCH}
44
echo ${DASH}
45
printf "%5.2f%% %5.2fMb\n" ${PC} ${bloat}
46
rm ${SCRATCH}
47
48