summaryrefslogtreecommitdiff
path: root/apt-listrepository
blob: b22f490ba1957c1b183cd2fdaf9128fbf4218fb6 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl

# Copyright (C) 2004 Marcel Meckel <debian [at] thermoman [dot] de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# apt-listrepository 0.0.1
# list packages with corresponding repository


 sub usage {
    print 'Usage: apt-listrepository

Lists all installed packages and the corresponding
repository it was installed from.

  --help          - this usage message

';
 }

 unless ($#ARGV ne 0) {
    &usage();
    exit 1;
 }

 # all installed packages
 open(DATA, 'dpkg --get-selections|') or die "Can not execute dpkg\n";
 @tmp = <DATA>;
 close DATA;

 chomp(@tmp);
 $tmp2 = join("\n", @tmp)."\n";

 $packages_nl = $tmp2;
 $packages_nl =~ s/([^\s]+)\s+([^\n]+)/\1/g;
 $packages    = $packages_nl;
 $packages    =~ s/\n/ /g;
 
 # get policy of all installed packages
 open(DATA, "apt-cache policy $packages|") or die "Can not execute apt-cache\n";
 @tmp = <DATA>;
 close DATA;
   
 chomp(@tmp);
 $tmp2 = join("\n", @tmp)."\n";

 $tmp2 =~ s/^  (Candidate|Installed|Version Table):.*\n//mg;
 $tmp2 =~ s/([^:\s\n]+):\n[^\*]+\*\*\* ([^\s\n]+)[^\n]+\n\s+-?[0-9]+ ([^\n]+)\n(\s+[^\n]+\n)*/\1|\2|\3\n/g;

 # all packages with version nr. and repository per line
 @packages = split(/\n/, $tmp2);

 foreach my $line (@packages) {
    my ($name, $version, $repository) = split (/\|/, $line);
    $repository =~ s/ Packages$//;
    printf("%-35s %s\n", $name, $repository)
 }

exit 0;