Debian Codegraph @

dpigs

raw
1 #!/bin/sh
2
3 # dpigs - Show which installed packages occupy the most space
4
5 # Copyright (C) 2001,2002 Matt Zimmerman <[email protected]>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # 02111-1307, USA.
21 #
22
23 set -e
24
25 # set locale for sorting
26 LC_NUMERIC=C
27 export LC_NUMERIC
28
29 Usage() {
30 echo "Usage: dpigs [options]"
31 echo
32 echo "Options:"
33 echo " -n, --lines=N"
34 echo " Display the N largest packages on the system (default 10)."
35 echo " -s, --status=status-file"
36 echo " Use status-file instead of the default dpkg status file."
37 echo " -S, --source"
38 echo " Display the largest source packages of binary packages installed"
39 echo " on the system."
40 echo " -H, --human-readable"
41 echo " Display package sizes in human-readable format (like ls -lh or du -h)"
42 echo " -h, --help"
43 echo " Display this message."
44 }
45
46 LINES=10
47 # grep-status provides a default
48 STATUS=
49 # Default: provide binary package information
50 SOURCE=0
51 # Default: display kilobytes
52 HUMAN=0
53
54 OPTS=$(getopt -o n:s:ShH --long lines:,status:,source,help,human-readable -- "$@")
55 eval set -- "$OPTS"
56
57 while true; do
58 case "$1" in
59 -n|--lines)
60 LINES="$2"
61 shift 2
62 ;;
63 -s|--status)
64 STATUS="$2"
65 shift 2
66 ;;
67 -S|--source)
68 SOURCE=1
69 shift 1
70 ;;
71 -H|--human-readable)
72 HUMAN=1
73 shift 1
74 ;;
75 -h|--help)
76 Usage
77 exit 0
78 ;;
79 --)
80 shift
81 break
82 ;;
83 *)
84 Usage
85 exit 1
86 ;;
87 esac
88 done
89
90 if [ $SOURCE -eq 0 ] ; then
91 grep-status -nsInstalled-size,Package -F Status ' installed' $STATUS \
92 | perl -p00l12 -e 's/\n/ /' \
93 | sort -rn \
94 | head --lines=$LINES
95 else
96 # Order by source package
97 grep-status -nsInstalled-size,Source:Package -F Status ' installed' $STATUS \
98 | perl -n00a -e '$s{$F[1]}+=$F[0]; END { for(keys %s) {print"$s{$_} $_\n"} }' \
99 | sort -rn \
100 | head --lines=$LINES
101 # Alternatively use this:
102 # It adds details of which binary packages are
103 # involved (but not how big they are), with % standing in for the source
104 #grep-status -nsInstalled-size,Package,Source:Package -F Status ' installed' \
105 # $STATUS \
106 # | perl -n00al12 -e '$s{$F[2]} += $F[0];
107 # $F[1] =~ s/\Q$F[2]\E/%/; $b{$F[2]}{$F[1]} = 1;
108 # END {$, = " "; for(keys %s) {print "$s{$_} $_:", sort keys %{$b{$_}}} }' \
109 # | sort -rn \
110 # | head --lines=$LINES
111 fi | if [ $HUMAN -eq 1 ]; then
112 numfmt --from-unit=Ki --to=iec-i --suffix=B --padding=7
113 else
114 cat
115 fi