Add SHA-256 and SHA-512 hashes
[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 ################################################################################
8 # Notice: adjust $c_file[12] according to your needs, by default the script
9 # compares the i386 pool with the amd64 pool of grml.
10 ################################################################################
11
12 use strict; 
13 use LWP::Simple;
14 use Compress::Zlib ;
15
16 use AptPkg::Config '$_config';
17 use AptPkg::System '$_system';
18 use AptPkg::Version;
19
20 (my $self = $0) =~ s#.*/##;
21
22 # initialise the global config object with the default values
23 $_config->init;
24
25 # determine the appropriate system type
26 $_system = $_config->system;
27
28 # fetch a versioning system
29 my $vs = $_system->versioning;
30
31 sub describe
32 {
33     return 'earlier than' if $_[0] < 0;
34     return 'later than'   if $_[0] > 0;
35     'the same as'; 
36 }
37
38 my $c_file1 = get('http://deb.grml.org/dists/grml-testing/main/binary-i386/Packages.gz'); 
39 my $c_file2 = get('http://deb.grml.org/dists/grml-testing/main/binary-amd64/Packages.gz');
40
41 my $file1 = Compress::Zlib::memGunzip($c_file1);
42 my $file2 = Compress::Zlib::memGunzip($c_file2);
43
44 my $file1_tree; 
45 my $file2_tree;
46
47 my ($package, $version) = "";
48
49 foreach my $line (split('\n', $file1)) {
50     if ($line =~ m/^Package: (.*)/) {
51         $package = $1; 
52     } elsif ($line =~ m/^Version: (.*)/) {
53         $file1_tree->{$package} = "$1";
54     }   
55 }
56
57 foreach my $line (split('\n', $file2)) {
58      if ($line =~ m/^Package: (.*)/) {
59         $package = $1; 
60     } elsif ($line =~ m/^Version: (.*)/) {
61         $file2_tree->{$package} = "$1";
62     }    
63 }
64
65
66 foreach my $key (keys %{$file1_tree}) {
67     if (defined $file2_tree->{$key}) {
68         print "package $key version " . $file1_tree->{$key} . " on repo1 is ",
69         (describe $vs->compare($file1_tree->{$key}, $file2_tree->{$key})), 
70         " " . $file2_tree->{$key} . " on repo2\n"; 
71     } else {
72         print "$key does not exist on repo2\n"; 
73      }
74 }
75
76 foreach my $key (keys %{$file2_tree}) {
77     if (not defined $file1_tree->{$key}) {
78          print "$key does not exist on repo1\n";
79     }
80 }
81
82 # EOF