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 51 52
|
#! /usr/bin/perl -w
# Copyright (c) 2004 Norbert Kiesel <nk@iname.com>
# Feta plugin for querying package distribution.
# Licensed under the GNU GPL.
# option -d => restrict to distribution
# option -t => turn off teaching mode
# option -y, -V => ignored
use strict;
use Getopt::Std;
my %opt;
getopts('yVtd:', \%opt);
# optionally filter package names through grep -E
my $pattern = shift;
my $grep = $pattern ? "grep -E '$pattern' | " : "";
my $package; # current package name
my $source; # source of current package
my %distribution; # maps package sources to distribution
my $cache = "apt-cache pkgnames | $grep sort | xargs apt-cache --quiet=2 --installed --no-generate --important showpkg 2>/dev/null |";
print "$cache\n" unless $opt{t};
open CACHE, $cache;
while (<CACHE>) {
chomp;
$package = $1, next if /^Package: (.+)/;
next unless /^Versions:/;
while (<CACHE>) {
chomp;
# installed versions print the status file name in addition
# to version and source
next unless ($source) = /^.+?\((.+?)\)\(/;
if (!$distribution{$source} or $distribution{$source} eq "UNKNOWN") {
(my $release = $source) =~ s/_Packages$/_Release/;
open RELEASE, "< $release";
$distribution{$source} = "UNKNOWN";
while (<RELEASE>) {
$distribution{$source} = $1, last if /^Archive: (.+)/;
}
}
write if !defined $opt{d} || $opt{d} eq $distribution{$source};
last;
}
}
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$package, $distribution{$source} if $distribution{$source}
.
|