1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use RPM2; |
6 |
use Data::Dumper; |
7 |
use Getopt::Std; |
8 |
|
9 |
my %opts; |
10 |
getopts( "als:", \%opts ); |
11 |
my $src = $opts{s} || '/builds/RPMS'; |
12 |
|
13 |
my $centosrel = '4'; |
14 |
my $fedorarel = '3'; |
15 |
my $builds = '/builds/rpms'; |
16 |
my $arch = `uname -i`; |
17 |
chomp $arch; |
18 |
|
19 |
my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa; |
20 |
my @repos = ( |
21 |
"/mirrors/centos/$centosrel/fasttrack/$arch/RPMS", |
22 |
"/mirrors/centos/$centosrel/updates/$arch/RPMS", |
23 |
"/mirrors/centos/$centosrel/os/$arch/CentOS/RPMS", |
24 |
"/mirrors/centos/$centosrel/os/$arch/SME/RPMS", |
25 |
"/mirrors/centos/$centosrel/os/$arch/RPMS", |
26 |
"/mirrors/centos/$centosrel/os/$arch/CentOS", |
27 |
"/mirrors/centos/$centosrel/os/$arch/SME", |
28 |
"/mirrors/centos/$centosrel/extras/$arch/RPMS", |
29 |
"/mirrors/fedora/epel/$centosrel/$arch", |
30 |
"/mirrors/rpmforge/dag/redhat/el$centosrel/en/$arch/dag/RPMS", |
31 |
"/mirrors/atrpms/el$centosrel-$arch/atrpms/stable", |
32 |
"/mirrors/fedora/core/updates/$fedorarel/$arch", |
33 |
"/mirrors/fedora/core/$fedorarel/$arch/os/Fedora/RPMS", |
34 |
"/mirrors/fedora/extras/$fedorarel/$arch", |
35 |
"$builds/RPMS/i686", |
36 |
"$builds/RPMS/i586", |
37 |
"$builds/RPMS/$arch", |
38 |
"$builds/RPMS/noarch", |
39 |
); |
40 |
|
41 |
opendir RPMS, $src or die "Couldn't opendir $src"; |
42 |
my %rpms = map { my $x = RPM2->open_package("$src/$_", $rpm_flags); $x->tag('NAME') => $x; } grep { /\.rpm$/ } readdir RPMS; |
43 |
closedir RPMS; |
44 |
|
45 |
my %repos; |
46 |
foreach my $repo (reverse @repos) |
47 |
{ |
48 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir RPMS if ( opendir RPMS, $repo ); |
49 |
closedir RPMS; |
50 |
%repos = (%repos, %temp_repo); |
51 |
} |
52 |
|
53 |
foreach my $rpm ( sort keys %rpms ) |
54 |
{ |
55 |
my (@headers, $header); |
56 |
|
57 |
my $rpmfix = $rpm; |
58 |
$rpmfix =~ s@\+@\\+@g; |
59 |
@headers = (); |
60 |
foreach my $file ( grep { /^$rpmfix-[0-9].*\.rpm$/ } keys %repos ) |
61 |
{ |
62 |
$header = RPM2->open_package("$repos{$file}/$file", $rpm_flags); |
63 |
if ($header ge $rpms{$rpm} || $header->filename =~ m#/centos/[\d.]+/(os|updates|fasttrack|extras)/#i || $opts{a}) |
64 |
{ |
65 |
push @headers, $header; |
66 |
} |
67 |
} |
68 |
@headers = reverse sort { $a cmp $b } @headers; |
69 |
if (grep { $_->filename =~ m#/centos/[\d.]+/(os|updates|fasttrack|extras)/#i } @headers) |
70 |
{ |
71 |
@headers = grep { $_->filename !~ m#/fedora/#i || $_->filename =~ m#/epel/#i || $_ eq $rpms{$rpm} } @headers; |
72 |
} |
73 |
unless ($opts{a}) { |
74 |
if (grep { $_->filename =~ m#/centos/[\d.]+/(updates|fasttrack)/#i } @headers) |
75 |
{ |
76 |
@headers = grep { $_->filename !~ m#/centos/[\d.]+/os/#i || $_ eq $rpms{$rpm} } @headers; |
77 |
} |
78 |
if (grep { $_->filename =~ m#/centos/[\d.]+/(os|updates|fasttrack|extras)/#i || $_->filename =~ m#/(dag|epel)/[^d]#i } @headers) |
79 |
{ |
80 |
@headers = grep { $_->filename !~ m#/atrpms/#i || $_ eq $rpms{$rpm} } @headers; |
81 |
} |
82 |
} |
83 |
if ($#headers < 0) |
84 |
{ |
85 |
print "$rpm\n"; |
86 |
print " ***** can't find $rpm in any repository *****\n"; |
87 |
} |
88 |
elsif ( $headers[0]->filename !~ m#/centos/[\d.]+/(os|updates|fastrrack|extras)/#i || $headers[0] ne $rpms{$rpm} ) |
89 |
{ |
90 |
next if $headers[0] eq $rpms{$rpm} && $opts{l}; |
91 |
if (grep { $_ ne $rpms{$rpm} } @headers) |
92 |
{ |
93 |
print "$rpm\n"; |
94 |
foreach $header ( @headers) |
95 |
{ |
96 |
my $path = $header->filename; |
97 |
$path =~ s@^(.*)/.*@$1@; |
98 |
my $filename = $rpms{$rpm}->filename; |
99 |
$filename =~ s@^.*/(.*)@$1@; |
100 |
print " " . ( $header eq $rpms{$rpm} ? "** " : ( $path =~ m#/centos/# ? "-- " : ".. " ) ) . $header->as_nvre . " ($path)\n"; |
101 |
#print " - rm -f $src/$filename; cp ". $header->filename . " $src\n"; |
102 |
last if $header eq $rpms{$rpm} && $opts{l}; |
103 |
} |
104 |
} |
105 |
} |
106 |
} |