Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to list all packages of the form

$ dpkg -l libav\*

but in addition to this output, I would like the origin/source (I'm not sure of the preferred term) of each package. If the package doesn't correspond to any source, it should say unknown or similar. Off the top of my head, the most promising approach would be to use dctrl-tools, but I'm not sure how to go about it. For background, I was trying to debug a library mismatch with ffmpeg. See Debian bug report - ffmpeg: backport of 4:0.6.1-5 from unstable produces WARNING: library configuration mismatch. The bug report is no longer an issue, but I'm still interested in this question.

Just to be clear on the format, this should look something like

ii  libavahi-client-dev  0.6.27-2+squeeze1  Development files for the Avahi client library  squeeze
ii  libavcodec-dev       4:0.6.1-5          Development files for libavcodec                unstable

If the same package is available in multiple categories, ie. in both squeeze and testing, then the lowest / oldest category available should be used. In this case, squeeze.

share|improve this question
    
apt-cache policy <package> gives relevant info; I'm too lazy to produce an actual script to link it to dpkg's output. –  9000 Mar 28 '11 at 15:46
    
I'm not sure the origin can be reported reliably. (I don't think it's recorded when the install happens.) For stable releases you can compare the installed versions against the archive, but for packages from unstable the installed version may not be in the archive any more. –  Andy Mar 28 '11 at 16:25
    
@Andy: This information is recorded in apt's database, since apt-cache policy reports it, as pointed out by 9000 above. If the package is not in any archive, it should be reported as unknown. See my updated question above. –  Faheem Mitha Mar 28 '11 at 17:46
    
The information is not recorded. apt-cache policy is showing where the package can currently be obtained from, not where it was originally obtained from when installed. –  Arrowmaster Mar 28 '11 at 18:20
    
@Arrowmaster: Incorrect. apt-cache policy is reading the information in apt's database, which is (usually) updated via apt-get update or aptitude update (not sure if these actually update the same stuff). So it is as current as the most recent update. –  Faheem Mitha Mar 28 '11 at 18:23

1 Answer 1

up vote 2 down vote accepted

Dpkg doesn't track this information. Where you got each .deb file is not its concern.

Apt doesn't track this information either, but it knows where you can now get the package, which is good enough.

As 9000 wrote in a comment, apt-cache policy '^libav' shows you what versions of packages with names matching the regexp ^libav are installed or available. The output isn't particularly convenient to parse, but here's a minimally tested script that gives approximately the format you want:

{ LC_CTYPE=C apt-cache policy '^libav'; echo .; } | perl -l -ne '
    if (!/^ /) {
        if (defined $version) {print "$package: $version unknown"}
        s/: *$//; $package=$_; $installed=1; $version=undef;
    }
    if (/^ *Installed: *\(none\)$/) {$installed=0}
    if ($installed && /^ \*+ +([^ ]+)/) {$version=$1}
    if (/^     [^ ]/) {$version=undef}
    if ($installed && defined $version && /^ +[0-9]+ +[^ ]+ +([^ \/]+)/) {
        print "$package: $version $1";
        $version=undef;
    }
'

Another way to the information you're asking for is with aptitude versions. Again, the minimally-tested snippet below gives roughly the desired format. The pattern "^libav" ~i matches packages that are installed and whose name matches the given regexp.

aptitude versions '"^libav" ~i' |
awk -vRS= '{if ($6 !~ /[^0-9]/) {$6="unknown"}
            print $3, $2, $5, $6}'

There's also a separately-packages utility apt-show-versions that, again, gives the information you want in roughly the format you're asking.

apt-show-versions | grep '^libav'
share|improve this answer
    
apt-show-versions works well enough for my purpose, thanks. I had not heard of this utility before. I see it uses what appear to be perl bindings to apt, namely libapt-pkg-perl. I guess python-apt would work too. Thanks. +1 and accepted. –  Faheem Mitha Mar 29 '11 at 17:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.