#!/usr/bin/perl -w # dpkg-status - show package status, one line per package, with fields # specified on command line # # Rob Funk # 1 Aug 2001 $status_file = "/var/lib/dpkg/status"; $progname = (split('/',$0))[-1]; if (! @ARGV or $ARGV[0] eq '-h') { print STDOUT "Usage: $progname field ...\n"; print STDOUT "\nPossible field names include:\n"; { while () { print STDERR "\t",lc($_); } exit 0; } } if ($ARGV[0] eq '-a') { $all = 1; shift; } $/ = ""; foreach (@ARGV) { push(@args,lc($_)); } open(STATUS,$status_file); while() { my($f, $v, $o, $prev, %p, @l, @l2); my $n=0; @l = split("\n",$_); # combine wrapped lines $prev=""; foreach (@l) { if (/^\s/) { $prev .= $_; } elsif (/^Description:/) { push(@l2,$prev) if ($prev); $prev = $_; s/^Description:/Desc:/; push(@l2,$_); } else { push(@l2, $prev) if ($prev); $prev = $_; } } push(@l2, $prev) if ($prev); @l = @l2; # now put each line in hash foreach (@l) { $f = $v = ""; ($f,$v) = /^([^:]+): ?(.*)$/; if ($v) { $f = lc($f); $p{$f} = $v; } #print STDERR "$n ($f): ($p{$f})\n"; $n++; } if (!defined($all) and $p{'status'} !~ /installed/) { next; } if (defined($p{$args[0]})) { $o = $p{$args[0]}; } else { next; } foreach (@args[1 .. $#args]) { if (defined($p{$_})) { $o .= "\t$p{$_}"; } else { $o = undef; last; } } print "$o\n" if defined($o); } close(STATUS); exit 0; __END__ Package Essential Status Priority Section Installed-Size Maintainer Source Version Config-Version Replaces Provides Depends Pre-Depends Recommends Suggests Conflicts Conffiles Desc Description