File: available

package info (click to toggle)
feta 1.4.15
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 444 kB
  • ctags: 85
  • sloc: perl: 1,200; sh: 192; makefile: 55
file content (54 lines) | stat: -rwxr-xr-x 1,525 bytes parent folder | download | duplicates (3)
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
53
54
#!/usr/bin/perl -w
# Copyright (c) 2002-2004 Norbert Kiesel <nk@iname.com>
# Feta plugin for querying available packages. 
# A rewrite of the shell script written by Graham Williams and Kayon Toga.
# Licensed under the GNU GPL.

# option -q => suppress header
# option -e => surround pattern with ^ and $
# option -f => regexp-quote pattern (like "grep -F")
# option -t => turn off teaching mode
# option -y, -V => ignored

use Getopt::Std;
getopts('qytVef', \%opt);

if (scalar(@ARGV) == 0) {
 print STDERR "E: You must provide at least one package name or wildcard.\n";
 exit 1;
}

@ARGV = map { quotemeta } @ARGV if $opt{f};
$pat = join('|', @ARGV);
$pat = "^($pat)\$" if $opt{e};

my $cache = "apt-cache dumpavail |";
print "$cache\n" unless $opt{t};
open CACHE, $cache;
while (<CACHE>) {
  chomp; 
  $pkg = $1, $packages{$1}++ if /^Package: (.+)/;
  $available{$pkg} = $1 if /^Version: (.+)/;
}

open STATUS, "< /var/lib/dpkg/status";
while (<STATUS>) {
  chomp;
  $pkg = $1, $packages{$1}++ if /^Package: (.+)/;
  $s = $1 if /^Status: \w+ \w+ (.+)/;
  $installed{$pkg} = $1 if /^Version: (.+)/ && $s eq 'installed';
}

print 'Package                            Available                     Installed
================================================================================
' unless $opt{q};

foreach $p (sort keys %packages) {
  write if $p =~ /$pat/;
}

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<
$p, $available{$p}||'', $installed{$p}||''
.