#!/usr/bin/perl use strict; use warnings; use RPM2; use File::Copy; my $rpm_flags = RPM2->vsf_nodsa; my @repositories = qw( /mirrors/centos/4/fasttrack/SRPMS /mirrors/centos/4/updates/SRPMS /mirrors/centos/4/os/SRPMS /mirrors/centos/4/extras/SRPMS /mirrors/rpmforge/dag/source/ /mirrors/atrpms/src/el4-i386/atrpms/stable/ /mirrors/fedora-legacy/fedora/3/updates/SRPMS/ /mirrors/fedora-legacy/fedora/3/os/SRPMS/ /builds/rpms/SRPMS/ ); opendir RPMS, "/builds/RPMS" or die "Couldn't opendir /builds/RPMS"; my %rpms = map { my $x = RPM2->open_package("/builds/RPMS/$_", $rpm_flags); $x->tag('NAME') => $x; } grep { /\.rpm$/ } readdir RPMS; closedir RPMS; my %repos; foreach my $repo (reverse @repositories) { my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir RPMS if ( opendir RPMS, $repo ); closedir RPMS; %repos = (%repos, %temp_repo); } foreach my $rpm ( sort keys %rpms ) { my (@headers, $header); my $rpmfix = $rpm; $rpmfix =~ s@\+@\\+@g; my @sources; my $src = $rpms{$rpm}->tag('SOURCERPM'); push @sources, $src; push @sources, $src if ($src =~ s/\.2\.el4\.rf\./\.rf\./); push @sources, $src if ($src =~ s/\.el4\.rf\./\.rf\./); push @sources, $src if ($src =~ s/\.el4\.at\./\.at\./); push @sources, $src if ($src =~ s/\.rf\./\.dag\./); my $found = 0; foreach my $source ( @sources ) { if( -f "/builds/SRPMS/$source" ) { $found = 1; last; } else { if ($repos{$source}) { my $fromfile = $repos{$source} . "/$source"; $fromfile =~ s#//#/#g; `cp --preserve=timestamps $fromfile /builds/SRPMS/`; $found = 1; last; } } } print "can't find SRPM ($sources[0]) for $rpm\n" unless $found; }