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