aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-size
blob: 2812d5696f5405574e0dfb858968268224da0fd9 (plain)
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
#!/bin/sh -ef
# Show the size on disk for a package

## SYNOPSIS:
## .Nm
## .Op Ar pkg...

## DESCRIPTION:
## .Nm
## calculates the sizes of given
## .Ar packages
## using the files from the package manifest and outputs a total size of the
## packages along with all the files associated with them.

## CAVEATS:
## .Nm
## uses the non-POSIX
## .Fl h
## and
## .Fl c
## flags for
## .Xr du 1 ,
## which will not work with
## .Em sbase ,
## but it is a major performance improvement compared to calculating
## total and human-readable sizes by hand.

case "$1" in
    --help|-h)
        printf '%s\n' "usage: ${0##*/} [pkg...]"
        exit 0
        ;;
    '') set -- "${PWD##*/}"
esac

for pkg; do cpt-list "$pkg" >/dev/null; done

files=
for pkg; do
    while read -r file; do
        # Filter directories from manifest and leave only files.
        # Directories in the manifest end in a trailing '/'.
        case $file in */) continue; esac
        files="$files '$file'"
    done < "$CPT_ROOT/var/db/cpt/installed/$pkg/manifest"
done
eval "set -- $files"

# Send the file list to 'du'.
du -shc -- "$@" 2>/dev/null