3
# original script by Jim Pick <jim@jimpick.com>, GPL'd of course
4
# many changes and enhancement by Craig Sander <cas@taz.net.au>
6
# hacked by cas to use case instead of if/elif/fi
7
# hacked by cas to add '-ls' option. also added error checking for
9
# hacked by cas to add '-conf' and '-lsconf' options.
10
# hacked by cas to add '-md5sum' and '-md5check' options.
11
# hacked by cas to add '-man' option.
12
# hacked by cas to add '-s' option (requires grep-dctrl).
13
# hacked by cas to support multiple string/package arguments
14
# hacked by cas to add simplistic emulation of 'dpkg -l'
16
DLOCATEDB=/var/lib/dlocate/dlocatedb
17
DPKGLIST=/var/lib/dlocate/dpkg-list
18
DPKG_INFO=/var/lib/dpkg/info
20
LOCATE="/usr/bin/locate"
21
# slocate diverts locate
22
LOCATE=`/usr/sbin/dpkg-divert --truename /usr/bin/locate`
27
""|"-h"|"-H"|"--help")
28
echo "Usage: dlocate [option] [string...]"
31
echo " (no option) string list all records that match"
32
echo " -S string list records where files match"
33
echo " -L package list all files in package"
34
echo " -l package almost-emulation of 'dpkg -l'"
35
echo " -s package print package's status"
36
echo " -ls package 'ls -ldF' of all files in package"
37
echo " -du package 'du -sck' of all files in package"
38
echo " -conf package list conffiles in package"
39
echo " -lsconf package 'ls -ldF' of conffiles in package"
40
echo " -md5sum package list package's md5sums (if any)"
41
echo " -md5check package check package's md5sums (if any)"
42
echo " -man package list package's man pages (if any)"
44
echo " The -L, -s, and -S commands are roughly analagous to the"
45
echo " equivalent dpkg commands."
51
[ -z "$1" ] && PKG="$OPTION"
53
while [ -n "$PKG" ] ; do
58
COLUMNS=$(stty -a 2>&- |
59
sed -ne '/columns/s/.*columns \([0-9]*\)[^0-9].*/\1/p');
60
[ 0"$COLUMNS" -lt 80 ] && COLUMNS=80;
61
((fieldw=(COLUMNS-24)/4));
63
#((fieldd=fieldw*2+16));
64
# limiting the output to COLUMNS-2 characters and losing up to
65
# additional 3 characters due to the rounding error.
66
((fieldd=COLUMNS-fieldw*2-6));
67
fmt_eq=$(echo ==================================================== |
70
"Desired=Unknown/Install/Remove/Purge/Hold
71
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
72
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
73
||/ %-${fieldw}s %-${fieldw}s %s
74
+++-${fmt_eq}-${fmt_eq}-${fmt_eq}${fmt_eq}==================\\n" \
75
Name Version Description
77
egrep "$1" $DPKGLIST | while read stat name ver descr; do
78
printf "%-2s %-${fieldw}.${fieldw}s %-${fieldw}.${fieldw}s %-${fieldd}.${fieldd}s\\n" \
79
"$stat" "$name" "$ver" "$descr";
83
if [ -e $DPKG_INFO/$PKG.list ] ; then
84
cat $DPKG_INFO/$PKG.list
86
echo Package \"$PKG\" not installed.
90
$LOCATE -d $DLOCATEDB $PKG | grep ":.*$PKG.*"
93
if [ -e $DPKG_INFO/$PKG.list ] ; then
94
grep-dctrl -X -P $PKG /var/lib/dpkg/status
96
echo Package \"$PKG\" not installed.
100
if [ -e $DPKG_INFO/$PKG.list ] ; then
101
xargs ls -ldF < $DPKG_INFO/$PKG.list
103
echo Package \"$PKG\" not installed.
107
if [ -e $DPKG_INFO/$PKG.list ] ; then
108
du -sck $(cat $DPKG_INFO/$PKG.list | xargs ls -1dF | grep -v "@$\|/$" )
110
echo Package \"$PKG\" not installed.
114
if [ -e $DPKG_INFO/$PKG.conffiles ] ; then
115
cat $DPKG_INFO/$PKG.conffiles
117
echo Package \"$PKG\" not installed or has no conffiles.
121
if [ -e $DPKG_INFO/$PKG.conffiles ] ; then
122
ls -ldF $(cat $DPKG_INFO/$PKG.conffiles)
124
echo Package \"$PKG\" not installed or has no conffiles.
128
if [ -e $DPKG_INFO/$PKG.md5sums ] ; then
129
cat $DPKG_INFO/$PKG.md5sums
131
echo Package \"$PKG\" not installed or has no md5sums.
135
if [ -e $DPKG_INFO/$PKG.list ] ; then
137
sed -n -e 's/\.gz$//' \
138
-e '/man.*\/.*[0-9]/s/^.*\/\([^\/]*\)\.\(.*\)/\2 \1/p'
140
echo Package \"$PKG\" not installed.
144
if [ -e $DPKG_INFO/$PKG.md5sums ] ; then
145
cat $DPKG_INFO/$PKG.md5sums | \
146
awk '{print $1 " /" $2}' | \
147
md5sum -v -c /dev/stdin
149
echo Package \"$PKG\" not installed or has no md5sums.
153
$LOCATE -d $DLOCATEDB "$PKG"