1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use RPM2; |
6 |
use File::Copy; |
7 |
|
8 |
my $rpm_flags = RPM2->vsf_nodsa; |
9 |
my @repositories = qw( |
10 |
/mirrors/centos/4/fasttrack/SRPMS |
11 |
/mirrors/centos/4/updates/SRPMS |
12 |
/mirrors/centos/4/os/SRPMS |
13 |
/mirrors/centos/4/extras/SRPMS |
14 |
/mirrors/rpmforge/dag/source/ |
15 |
/mirrors/atrpms/src/el4-i386/atrpms/stable/ |
16 |
/mirrors/fedora-legacy/fedora/3/updates/SRPMS/ |
17 |
/mirrors/fedora-legacy/fedora/3/os/SRPMS/ |
18 |
/builds/rpms/SRPMS/ |
19 |
); |
20 |
|
21 |
opendir RPMS, "/builds/RPMS" or die "Couldn't opendir /builds/RPMS"; |
22 |
my %rpms = map { my $x = RPM2->open_package("/builds/RPMS/$_", $rpm_flags); $x->tag('NAME') => $x; } grep { /\.rpm$/ } readdir RPMS; |
23 |
closedir RPMS; |
24 |
|
25 |
my %repos; |
26 |
foreach my $repo (reverse @repositories) |
27 |
{ |
28 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir RPMS if ( opendir RPMS, $repo ); |
29 |
closedir RPMS; |
30 |
|
31 |
%repos = (%repos, %temp_repo); |
32 |
} |
33 |
|
34 |
foreach my $rpm ( sort keys %rpms ) |
35 |
{ |
36 |
my (@headers, $header); |
37 |
|
38 |
my $rpmfix = $rpm; |
39 |
$rpmfix =~ s@\+@\\+@g; |
40 |
|
41 |
my @sources; |
42 |
my $src = $rpms{$rpm}->tag('SOURCERPM'); |
43 |
push @sources, $src; |
44 |
push @sources, $src if ($src =~ s/\.2\.el4\.rf\./\.rf\./); |
45 |
push @sources, $src if ($src =~ s/\.el4\.rf\./\.rf\./); |
46 |
push @sources, $src if ($src =~ s/\.el4\.at\./\.at\./); |
47 |
push @sources, $src if ($src =~ s/\.rf\./\.dag\./); |
48 |
|
49 |
my $found = 0; |
50 |
foreach my $source ( @sources ) |
51 |
{ |
52 |
if( -f "/builds/SRPMS/$source" ) |
53 |
{ |
54 |
$found = 1; |
55 |
last; |
56 |
} else { |
57 |
if ($repos{$source}) |
58 |
{ |
59 |
my $fromfile = $repos{$source} . "/$source"; |
60 |
$fromfile =~ s#//#/#g; |
61 |
`cp --preserve=timestamps $fromfile /builds/SRPMS/`; |
62 |
$found = 1; |
63 |
last; |
64 |
} |
65 |
|
66 |
} |
67 |
} |
68 |
print "can't find SRPM ($sources[0]) for $rpm\n" unless $found; |
69 |
} |