-
Notifications
You must be signed in to change notification settings - Fork 6
/
pkg-real-size.sh
executable file
·62 lines (56 loc) · 1.43 KB
/
pkg-real-size.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#Return size in bytes and megabytes of the package and all its deps
set -eu
total_size=0
tempfoo=$(basename $0)
tmpfile=$(mktemp /tmp/${tempfoo}.XXXXXX)
unit=bytes
get_deps () {
local package=$1
if grep -q $package $tmpfile; then
return
fi
echo $package >> $tmpfile
# If multiples repo configured will get duplicates, so add a sort|uniq
deps=$(pkg rquery %do $1 | sort | uniq)
if [ -n "$deps" ]; then
for i in $deps; do
get_deps $i
done
fi
}
usage() {
echo "$0 [-h] [-v] [-m] package-name" >&2;
echo -e "\t-h: emit this message, then exit" >&2
echo -e "\t-m: Use megabytes unit in place of ${unit}" >&2
echo -e "\t-v: enable execution tracing" >&2
exit $1
}
if [ $# -lt 1 ]; then
usage
fi
while getopts "hmv" arg; do
case "$arg" in
h) usage 0 ;;
m) unit=megabytes ;;
v) set -x ;;
*) usage 1 ;;
esac
done
shift $(( OPTIND - 1 ))
get_deps $1
echo "List of dependencies and their sizes:"
for i in $(sort $tmpfile | uniq); do
size=$(pkg rquery -r FreeBSD %sb $i | head -1)
if [ -z "${size}" ]; then
printf "No package $i found\n"
exit 1
fi
total_size=$(( total_size + size ))
size_unit=$(units -o %0.f -t "${size} bytes" ${unit})
printf '%-20s %10s %s\n' $i ${size_unit} ${unit}
done
echo "-----------------------------------------"
size_unit=$(units -o %0.f -t "${total_size} bytes" ${unit})
printf '%-20s %10s %s\n' TOTAL ${size_unit} ${unit}
rm $tmpfile