Add /usr/share/grml-live/scripts/repodiff.pl (by formorer, thx!)
[grml-live.git] / scripts / repodiff.pl
1 #!/usr/bin/perl 
2 # Filename:      repodiff.pl
3 # Purpose:       compare the available packages from two different repositories
4 # Authors:       grml-team (grml.org), (c) Alexander Wirt <formorer@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 # Latest change: Sun Oct 28 18:00:49 CET 2007 [mika]
8 ################################################################################
9 # Notice: adjust $c_file[12] according to your needs, by default the script
10 # compares the i386 pool with the amd64 pool of grml.
11 ################################################################################
12
13 use strict; 
14 use LWP::Simple;
15 use Compress::Zlib ;
16
17 use AptPkg::Config '$_config';
18 use AptPkg::System '$_system';
19 use AptPkg::Version;
20
21 (my $self = $0) =~ s#.*/##;
22
23 # initialise the global config object with the default values
24 $_config->init;
25
26 # determine the appropriate system type
27 $_system = $_config->system;
28
29 # fetch a versioning system
30 my $vs = $_system->versioning;
31
32 sub describe
33 {
34     return 'earlier than' if $_[0] < 0;
35     return 'later than'   if $_[0] > 0;
36     'the same as'; 
37 }
38
39 my $c_file1 = get('http://deb.grml.org/dists/grml-testing/main/binary-i386/Packages.gz'); 
40 my $c_file2 = get('http://deb.grml.org/dists/grml-testing/main/binary-amd64/Packages.gz');
41
42 my $file1 = Compress::Zlib::memGunzip($c_file1);
43 my $file2 = Compress::Zlib::memGunzip($c_file2);
44
45 my $file1_tree; 
46 my $file2_tree;
47
48 my ($package, $version) = "";
49
50 foreach my $line (split('\n', $file1)) {
51     if ($line =~ m/^Package: (.*)/) {
52         $package = $1; 
53     } elsif ($line =~ m/^Version: (.*)/) {
54         $file1_tree->{$package} = "$1";
55     }   
56 }
57
58 foreach my $line (split('\n', $file2)) {
59      if ($line =~ m/^Package: (.*)/) {
60         $package = $1; 
61     } elsif ($line =~ m/^Version: (.*)/) {
62         $file2_tree->{$package} = "$1";
63     }    
64 }
65
66
67 foreach my $key (keys %{$file1_tree}) {
68     if (defined $file2_tree->{$key}) {
69         print "package $key version " . $file1_tree->{$key} . " on repo1 is ",
70         (describe $vs->compare($file1_tree->{$key}, $file2_tree->{$key})), 
71         " " . $file2_tree->{$key} . " on repo2\n"; 
72     } else {
73         print "$key does not exist on repo2\n"; 
74      }
75 }
76
77 foreach my $key (keys %{$file2_tree}) {
78     if (not defined $file1_tree->{$key}) {
79          print "$key does not exist on repo1\n";
80     }
81 }
82
83 # EOF