3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use RPM2; |
use RPM2; |
6 |
|
use File::Find; |
7 |
|
use File::Basename; |
8 |
|
use Getopt::Std; |
9 |
use Data::Dumper; |
use Data::Dumper; |
10 |
|
|
11 |
sub compare($$); |
delete $ENV{PATH}; |
12 |
|
my $HOME=$ENV{HOME}; |
13 |
my $releases = 2; |
umask 002; |
14 |
|
$| = 1; |
15 |
my $rpm_flags = RPM2->vsf_nodsa; |
|
16 |
my $repodir = '/releases/7'; |
my %opts; |
17 |
my $stagedir = '/builds'; |
getopts( 'osqtr:', \%opts ); |
18 |
my @repos = qw( |
$opts{r} ||= ''; |
19 |
/releases/7/smeos/i386/CentOS/RPMS |
|
20 |
/releases/7/smeupdates/i386/RPMS |
my $rpm_flags = RPM2->vsf_nosha1header | RPM2->vsf_nomd5header | RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader; |
21 |
/releases/7/smeupdates-testing/i386/RPMS |
$rpm_flags |= RPM2->vsf_nosha1 | RPM2->vsf_nomd5 | RPM2->vsf_nodsa | RPM2->vsf_norsa; |
22 |
/releases/7/smeextras/i386/RPMS |
|
23 |
/releases/7/smeaddons/i386/RPMS |
my $osdir = 'SME'; |
24 |
/releases/7/smetest/i386/RPMS |
my $disttag = 'sme'; |
25 |
/releases/7/smedev/i386/RPMS |
my $repotag = 'sme'; |
26 |
/builds/rpms/RPMS/i386 |
|
27 |
/builds/rpms/RPMS/i586 |
my @archs = ( 'i386', 'x86_64' ); |
28 |
/builds/rpms/RPMS/i686 |
|
29 |
/builds/rpms/RPMS/noarch |
my $distrepo = { '7' => { active => 1, |
30 |
/builds/RPMS |
centos => 4, |
31 |
); |
fedora => 3, |
32 |
my $devrepo = (grep { m{/sme} } reverse @repos)[0]; |
repo => '/releases/7/', |
33 |
|
os => 'RPMS/', |
34 |
my @srcrepos = qw( |
builds => '/builds/smeserver-7-core/', |
35 |
/mirrors/centos/4/fasttrack/SRPMS |
contribs => '/builds/smeserver-7-contribs/', |
36 |
/mirrors/centos/4/updates/SRPMS |
stage => '/stage/7/', |
37 |
/mirrors/centos/4/os/SRPMS |
}, |
38 |
/mirrors/centos/4/extras/SRPMS |
'8' => { active => 1, |
39 |
/mirrors/rpmforge/dag/source |
centos => 5, |
40 |
/mirrors/atrpms/src/el4-i386/atrpms/stable |
fedora => 6, |
41 |
/builds/rpms/SRPMS |
repo => '/releases/testing/8/', |
42 |
); |
os => '', |
43 |
|
builds => '/builds/smeserver-8-core/', |
44 |
my %repohash; |
contribs => '/builds/smeserver-8-contribs/', |
45 |
my %srcrepohash; |
stage => '/stage/8/', |
46 |
my %changed; |
}, |
47 |
my %copy; |
}; |
48 |
my @remove; |
|
49 |
|
my $repos = { "${repotag}os" => { prio => 18, inc => 1, ver => 1, rel => 1, os => 1 }, |
50 |
%{$srcrepohash{$stagedir}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$stagedir/SRPMS" ); |
"${repotag}updates" => { prio => 17, inc => 1, ver => 1, rel => 1 }, |
51 |
closedir SRPMS; |
"${repotag}updates-testing" => { prio => 16, inc => 1, ver => 1, rel => 3 }, |
52 |
|
"${repotag}extras" => { prio => 15, inc => 0, ver => 1, rel => 1 }, |
53 |
print "\n"; |
"${repotag}addons" => { prio => 14, inc => 0, ver => 1, rel => 1 }, |
54 |
foreach my $repo ( @repos ) { |
"${repotag}contribs" => { prio => 13, inc => 0, ver => 1, rel => 1 }, |
55 |
if ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
"${repotag}test" => { prio => 12, inc => 0, ver => 2, rel => 3, devel => 2 }, |
56 |
my $srcrepo = $1; |
"${repotag}dev" => { prio => 11, inc => 0, ver => 1, rel => 1, devel => 1 }, |
57 |
|
'centos' => { prio => 10, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
58 |
%{$srcrepohash{$srcrepo}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$srcrepo/SRPMS" ); |
'epel' => { prio => 9, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
59 |
closedir SRPMS; |
'fedora-extras' => { prio => 8, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
60 |
} |
'rpmforge' => { prio => 7, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
61 |
|
'atrpms' => { prio => 6, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
62 |
opendir RPMS, $repo; |
'fedora' => { prio => 5, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
63 |
foreach my $rpm ( grep { m{\.rpm} } readdir RPMS ) { |
'builds' => { prio => 4, inc => 0, ver => 0, rel => 0, orig => 1 }, |
64 |
my $header = RPM2->open_package("$repo/$rpm", $rpm_flags); |
'contribs' => { prio => 2, inc => 0, ver => 0, rel => 0, orig => 1 }, |
65 |
my $pkg = $header->tag("NAME").".".$header->tag("ARCH"); |
'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 }, |
66 |
if ( $repo =~ m{/builds/RPMS} ) { |
}; |
67 |
push @{$repohash{$pkg}{$stagedir}}, $header; |
|
68 |
} elsif ( $repo =~ m{/builds/} ) { |
my $baserepo = { "~S${repotag}os/~A/$osdir/~O" => "${repotag}os", |
69 |
push @{$repohash{$pkg}{builds}}, $header; |
"~S${repotag}updates/~A/RPMS/" => "${repotag}updates", |
70 |
} elsif ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
"~S${repotag}updates-testing/~A/RPMS/" => "${repotag}updates-testing", |
71 |
my $pos = $1; |
"~S${repotag}extras/~A/RPMS/" => "${repotag}extras", |
72 |
push @{$repohash{$pkg}{$pos}}, $header; |
"~S${repotag}addons/~A/RPMS/" => "${repotag}addons", |
73 |
} |
"~S${repotag}contribs/~A/RPMS/" => "${repotag}contribs", |
74 |
} |
"~S${repotag}test/~A/RPMS/" => "${repotag}test", |
75 |
closedir RPMS; |
"~S${repotag}dev/~A/RPMS/" => "${repotag}dev", |
76 |
|
"/stage/~s/~A/$osdir/~O" => 'stage', |
77 |
|
'/mirrors/centos/~C/fasttrack/~A/RPMS/' => 'centos', |
78 |
|
'/mirrors/centos/~C/updates/~A/RPMS/' => 'centos', |
79 |
|
'/mirrors/centos/~C/os/~A/CentOS/~O' => 'centos', |
80 |
|
'/mirrors/centos/~C/extras/~A/RPMS/' => 'centos', |
81 |
|
'/mirrors/fedora/epel/~C/~A/' => 'epel', |
82 |
|
'/mirrors/fedora/epel/testing/~C/~A/' => 'epel', |
83 |
|
'/mirrors/fedora/extras/~F/~A/' => 'fedora-extras', |
84 |
|
'/mirrors/rpmforge/dag/redhat/el~C/en/~A/dag/RPMS/' => 'rpmforge', |
85 |
|
'/mirrors/rpmforge/dag/source/' => 'rpmforge', |
86 |
|
'/mirrors/atrpms/el~C-~A/atrpms/stable/' => 'atrpms', |
87 |
|
'/mirrors/atrpms/el~C-~A/atrpms/testing/' => 'atrpms', |
88 |
|
'/mirrors/atrpms/src/el~C-~A/atrpms/stable/' => 'atrpms', |
89 |
|
'/mirrors/atrpms/src/el~C-~A/atrpms/testing/' => 'atrpms', |
90 |
|
'/mirrors/fedora/core/~F/~A/os/Fedora/RPMS/' => 'fedora', |
91 |
|
'/mirrors/fedora/core/updates/~F/~A/' => 'fedora', |
92 |
|
}; |
93 |
|
|
94 |
|
if ( $opts{q} ) { |
95 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/fasttrack/~A/RPMS/'} = 'centos'; |
96 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/updates/~A/RPMS/'} = 'centos'; |
97 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/os/~A/CentOS/~O'} = 'centos'; |
98 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/extras/~A/RPMS/'} = 'centos'; |
99 |
} |
} |
100 |
|
|
101 |
my %sources; |
my $skippkg = { '7' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) }, |
102 |
foreach my $repo ( reverse @srcrepos ) { |
'epel' => { map { $_ => 1 } ( 'clamav', 'fping', 'ocsinventory', 'perl-Compress-Bzip2', 'perl-Compress-Raw-Zlib', 'perl-Compress-Raw-Bzip2', 'perl-Crypt-OpenSSL-Bignum', 'perl-Crypt-OpenSSL-Random', 'perl-Crypt-OpenSSL-RSA', 'perl-DateTime', 'perl-Razor-Agent', 'perl-Text-Iconv', 'proftpd' ) }, |
103 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo ); |
'fedora-extras' => { map { $_ => 1 } ( 'ddclient', 'hddtemp', 'pam_abl', 'perl-Compress-Bzip2', 'perl-Error', 'perl-HTML-Format', 'perl-MIME-Types', 'perl-Net-IP', 'perl-Archive-Zip', 'perl-Class-Singleton', 'perl-Razor-Agent', 'perl-Test-Inline', 'perl-Text-Autoformat', 'perl-Text-Iconv', 'perl-Text-Reform', 'perl-XML-RSS' ) }, |
104 |
closedir SRPMS; |
'rpmforge' => { map { $_ => 1 } ( 'perl-Test-Inline' ) }, |
105 |
|
'atrpms' => { map { $_ => 1 } ( 'check4updates', 'dovecot', 'trac', 'yum' ) }, |
106 |
%sources = (%sources, %temp_repo); |
}, |
107 |
} |
'8' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) }, |
108 |
|
'fedora' => { map { $_ => 1 } ( 'kernel', 'kernel-xen' ) }, |
109 |
|
'epel' => { map { $_ => 1 } ( 'clamav', 'horde', 'perl-Compress-Bzip2', 'perl-Compress-Raw-Zlib', 'perl-Compress-Raw-Bzip2', 'perl-Crypt-OpenSSL-Bignum', 'perl-Crypt-OpenSSL-Random', 'perl-Crypt-OpenSSL-RSA', 'perl-Razor-Agent', 'proftpd', 'smolt' ) }, |
110 |
|
'fedora-extras' => { map { $_ => 1 } ( 'dstat', 'gocr', 'horde', 'oidentd', 'perl-Compress-Bzip2', 'perl-Crypt-OpenSSL-Bignum', 'perl-Crypt-OpenSSL-Random', 'perl-Crypt-OpenSSL-RSA', 'perl-Test-Inline', 'perl-Razor-Agent', 'smolt' ) }, |
111 |
|
'rpmforge' => { map { $_ => 1 } ( 'perl-Test-Inline' ) }, |
112 |
|
}, |
113 |
|
}; |
114 |
|
|
115 |
|
my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos; |
116 |
|
my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos; |
117 |
|
$devel2 ||= $devel1; |
118 |
|
|
119 |
|
my ($rpms, %base, %latest, %sources); |
120 |
|
foreach my $ver ( sort { $a <=> $b } keys %$distrepo ) { |
121 |
|
next unless $distrepo->{$ver}->{active}; |
122 |
|
my %repochg = (); |
123 |
|
$rpms = (); |
124 |
|
%latest = (); |
125 |
|
%sources = (); |
126 |
|
%base = (); |
127 |
|
|
128 |
|
foreach my $dir ( sort { $repos->{$baserepo->{$b}}->{prio} <=> $repos->{$baserepo->{$a}}->{prio} || $a cmp $b } keys %$baserepo ) { |
129 |
|
my $bdir = $dir; |
130 |
|
$bdir =~ s/~O/$distrepo->{$ver}->{os}/; |
131 |
|
$bdir =~ s/~S/$distrepo->{$ver}->{repo}/; |
132 |
|
$bdir =~ s/~s/$ver/; |
133 |
|
$bdir =~ s/~C/$distrepo->{$ver}->{centos}/; |
134 |
|
$bdir =~ s/~F/$distrepo->{$ver}->{fedora}/; |
135 |
|
for my $arch ( @archs, 'SRPMS/' ) { |
136 |
|
my $adir = $bdir; |
137 |
|
if ( $arch eq 'SRPMS/' ) { |
138 |
|
$adir =~ s/~A.*/$arch/ if $arch eq 'SRPMS/'; |
139 |
|
} else { |
140 |
|
$adir =~ s/~A/$arch/; |
141 |
|
} |
142 |
|
opendir DIR, $adir or next; |
143 |
|
next unless -d $adir; |
144 |
|
process_rpm("$adir$_", $ver, $baserepo->{$dir}) foreach readdir DIR; |
145 |
|
closedir DIR; |
146 |
|
last unless $dir =~ m{~A}; |
147 |
|
} |
148 |
|
} |
149 |
|
find( { wanted => sub { process_rpm($_, $ver, 'builds'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'builds'} ); |
150 |
|
find( { wanted => sub { process_rpm($_, $ver, 'contribs'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'contribs'} ); |
151 |
|
|
152 |
|
foreach my $base ( sort keys %$rpms ) { |
153 |
|
next unless $rpms->{$base}->{rpms}; |
154 |
|
my %track = (); |
155 |
|
my %seen = (); |
156 |
|
my %counts = (); |
157 |
|
my $acnt = (); |
158 |
|
my $print = 0; |
159 |
|
%latest = (); |
160 |
|
|
161 |
|
foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{rpms}} ) { |
162 |
|
next if $pkg->{done}; |
163 |
|
|
164 |
|
my $tmp = $pkg->{svr}; |
165 |
|
SRC: { |
166 |
|
$rpms->{$base}->{vers}->{$tmp} && last SRC; |
167 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
168 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
169 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
170 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.el5} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
171 |
|
($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d(\.rf)$}{$1$2} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
172 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
173 |
|
($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d\.rf$}{$1.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
174 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
175 |
|
($tmp = $pkg->{svr}) =~ s{(-\d+)\.\d+\.el\d$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
176 |
|
($tmp = $pkg->{svr}) =~ s{\.centos\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
177 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.$disttag$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
178 |
|
} |
179 |
|
if ( $rpms->{$base}->{vers}->{$tmp} ) { |
180 |
|
foreach $tmp ( @{$rpms->{$base}->{vers}->{$tmp}} ) { |
181 |
|
$tmp->{svr} = $pkg->{svr}; |
182 |
|
push @{$rpms->{$base}->{rpms}}, $tmp unless $tmp->{added}; |
183 |
|
$tmp->{added}++; |
184 |
|
} |
185 |
|
} |
186 |
|
|
187 |
foreach my $pkg ( keys %repohash ) { |
my %orig = (); |
188 |
foreach my $repo ( @repos ) { |
my %pkgs = (); |
189 |
if ( $repo =~ m{/builds/RPMS} ) { |
my %reposrc = (); |
190 |
next unless $repohash{$pkg}{latest} || $repohash{$pkg}{$stagedir}; |
my $srpm = undef; |
191 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$stagedir}}; |
foreach my $cmp ( sort { $a->{src} <=> $b->{src} || $repos->{$b->{repo}}->{prio} <=> $repos->{$a->{repo}}->{prio} } @{$rpms->{$base}->{rpms}} ) { |
192 |
delete $repohash{$pkg}{$stagedir}; |
next unless $cmp->{svr} eq $pkg->{svr}; |
193 |
push @remove, map { $_->filename } @rest if @rest; |
|
194 |
if ( $repohash{$pkg}{latest} ) { |
if ( ! $track{repo} || $repos->{$cmp->{repo}}->{prio} > $repos->{$track{repo}}->{prio} ) { |
195 |
if ($repohash{$pkg}{latest} ne $latest ) { |
if ( $cmp->{src} ) { |
196 |
push @remove, $latest->filename; |
if ( ! $track{repo} ) { |
197 |
push @{$copy{"$stagedir/RPMS"}}, $repohash{$pkg}{latest}->filename; |
$cmp->{delete}++; |
198 |
$repohash{$pkg}{$stagedir} = $repohash{$pkg}{latest}; |
$cmp->{done}++; |
199 |
|
next; |
200 |
|
} |
201 |
|
} else { |
202 |
|
$track{repo} = $cmp->{repo}; |
203 |
|
$track{svr} = $cmp->{svr}; |
204 |
|
} |
205 |
|
} |
206 |
|
if ( $cmp->{svr} eq $track{svr} ) { |
207 |
|
if ( $seen{$cmp->{nvra}} ) { |
208 |
|
if ( $track{repo} ne $cmp->{repo} ) { |
209 |
|
if ($repos->{$cmp->{repo}}->{stage} ) { |
210 |
|
if ( $seen{$cmp->{nvra}}->{latest} ) { |
211 |
|
$seen{$cmp->{nvra}}->{latest}++; |
212 |
} else { |
} else { |
213 |
$repohash{$pkg}{$stagedir} = $latest; |
$cmp->{delete}++; |
214 |
} |
} |
215 |
} else { |
} elsif ( $repos->{$cmp->{repo}}->{orig}) { |
216 |
push @remove, $latest->filename; |
$orig{$cmp->{nvra}}++; |
217 |
|
unless ( $repos->{$cmp->{repo}}->{base} ) { |
218 |
|
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
219 |
|
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
220 |
|
} |
221 |
|
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
222 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
223 |
|
} elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} ) { |
224 |
|
$cmp->{delete}++; |
225 |
|
} |
226 |
} |
} |
227 |
} elsif ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
} elsif ($repos->{$cmp->{repo}}->{stage} ) { |
228 |
my $pos = $1; |
$cmp->{delete}++; |
229 |
next unless $repohash{$pkg}{$pos}; |
} else { |
230 |
if ( $pos =~ m{/smedev$} ) { |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
231 |
next unless $repohash{$pkg}{latest}; |
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
232 |
my @rest = grep { $_ le $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
233 |
if ( @rest ) { |
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
234 |
push @remove, map { $_->filename } @rest; |
if ( $cmp->{repo} ne $dest ) { |
235 |
$changed{$pos}++; |
push @{$cmp->{repos}}, $dest; |
236 |
@{$repohash{$pkg}{$pos}} = grep { $_ gt $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
237 |
delete $repohash{$pkg}{$pos}; |
$orig{$cmp->{nvra}}++; |
238 |
|
unless ( $repos->{$cmp->{repo}}->{base} ) { |
239 |
|
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
240 |
|
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
241 |
} |
} |
242 |
|
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
243 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
244 |
|
} else { |
245 |
|
$cmp->{delete}++; |
246 |
|
} |
247 |
|
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
248 |
|
$cmp->{repo} = $dest; |
249 |
|
if ( ! $cmp->{src} && $repos->{$dest}->{prio} > $repos->{$track{repo}}->{prio} ) { |
250 |
|
$track{repo} = $dest; |
251 |
|
$track{svr} = $cmp->{svr}; |
252 |
|
} |
253 |
|
} |
254 |
|
if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
255 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
256 |
|
} |
257 |
|
} |
258 |
|
} else { |
259 |
|
if ( $track{repo} eq $cmp->{repo} ) { |
260 |
|
if ( verrel($cmp, $cmp->{repo}, \%counts) ) { |
261 |
|
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
262 |
|
} elsif ( $cmp->{src} ) { |
263 |
|
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
264 |
} else { |
} else { |
265 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$pos}}; |
$track{svr} = $cmp->{svr}; |
266 |
delete $repohash{$pkg}{$pos}; |
} |
267 |
if ( $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $latest ) { |
} elsif ( ! $repos->{$cmp->{repo}}->{base} ) { |
268 |
push @rest, $latest; |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
269 |
} else { |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
270 |
$repohash{$pkg}{latest} = $latest; |
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
271 |
$repohash{$pkg}{$pos} = $latest; |
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
272 |
} |
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
273 |
if ( @rest ) { |
if ( $cmp->{src} && ! $reposrc{$dest} ) { |
274 |
push @remove, map { $_->filename } @rest; |
$cmp->{delete}++; |
275 |
$changed{$pos}++; |
} elsif ( $repos->{$dest}->{prio} >= $repos->{$track{repo}}->{prio} && ! verrel($cmp, $dest, \%counts) ) { |
276 |
|
unless ( $repos->{$cmp->{repo}}->{base} ) { |
277 |
|
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
278 |
|
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
279 |
} |
} |
280 |
|
push @{$cmp->{repos}}, $dest; |
281 |
|
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
282 |
|
$cmp->{repo} = $dest; |
283 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp if $cmp->{src}; |
284 |
|
$orig{$cmp->{nvra}}++; |
285 |
|
} else { |
286 |
|
$cmp->{delete}++; |
287 |
|
} |
288 |
|
} else { |
289 |
|
$cmp->{delete}++; |
290 |
} |
} |
291 |
|
} |
292 |
|
} |
293 |
|
unless ( $repos->{$cmp->{repo}}->{orig} || ( $cmp->{delete} && ! $cmp->{repos} ) ) { |
294 |
|
$pkgs{$cmp->{nvra}}++; |
295 |
|
$latest{$cmp->{base}} = $cmp->{svr} if $repos->{$cmp->{repo}}->{inc} && ! $latest{$cmp->{base}}; |
296 |
|
$reposrc{$cmp->{repo}} = $cmp unless $reposrc{$cmp->{repo}} || $cmp->{src} || $repos->{$cmp->{repo}}->{stage}; |
297 |
|
unless ( $seen{$cmp->{nvra}} ) { |
298 |
|
$seen{$cmp->{nvra}} = $cmp; |
299 |
|
$cmp->{latest}++ if $latest{$cmp->{base}} && $cmp->{svr} eq $latest{$cmp->{base}} && $repos->{$cmp->{repo}}->{inc}; |
300 |
|
} |
301 |
|
push @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{$cmp->{src} ? 'src' : $cmp->{rpm}->arch}}, $cmp; |
302 |
|
} |
303 |
|
$cmp->{done}++; |
304 |
|
} |
305 |
|
if ( $srpm ) { |
306 |
|
foreach my $r ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %reposrc ) { |
307 |
|
unless ( $reposrc{$r}->{srpm} ) { |
308 |
|
unshift @{$srpm->{repos}}, $r; |
309 |
|
$srpm->{oldrepo} = $srpm->{repo} unless $srpm->{oldrepo}; |
310 |
|
$srpm->{repo} = $r; |
311 |
|
$reposrc{$r}->{srpm} = $srpm; |
312 |
|
} |
313 |
} |
} |
314 |
|
} elsif ( scalar keys %pkgs && $opts{s} ) { |
315 |
|
print "\n * missing source ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n"; |
316 |
|
} |
317 |
|
print "\n * missing originals ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n" if $opts{o} && scalar keys %orig != scalar keys %pkgs; |
318 |
} |
} |
|
} |
|
319 |
|
|
320 |
foreach my $pkg ( sort grep { $repohash{$_}{builds} } keys %repohash ) { |
foreach my $r ( keys %$acnt ) { |
321 |
my %versions = (); |
foreach my $p ( keys %{$acnt->{$r}} ) { |
322 |
foreach my $ver ( sort { $b cmp $a } @{$repohash{$pkg}{builds}} ) { |
foreach my $a ( keys %{$acnt->{$r}->{$p}} ) { |
323 |
next if $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $ver; |
if ( $a eq 'noarch' ) { |
324 |
|
my $p2 = ${$acnt->{$r}->{$p}->{$a}}[0]; |
325 |
$versions{$ver->tag("VERSION")}++; |
if ( ! $p2->{repos} && scalar @{$acnt->{$r}->{$p}->{$a}} != scalar @archs ) { |
326 |
if ( $versions{$ver->tag("VERSION")} > $releases || (scalar keys %versions) > $releases ) { |
$p2->{oldrepo} = $p2->{repo}; |
327 |
foreach my $rpm ( grep { $ver eq $_ } @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
push @{$p2->{repos}}, $p2->{repo}; |
|
push @remove, $rpm->filename; |
|
|
@{$repohash{$pkg}{"$repodir/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$repodir/smedev"}}; |
|
|
$changed{"$repodir/smedev"}++; |
|
|
} |
|
|
} else { |
|
|
print "Possible update " . $ver->filename . "\n" if $repohash{$pkg}{latest}; |
|
|
if ( ! grep { $ver eq $_ } @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
|
|
push @{$copy{$devrepo}}, $ver->filename; |
|
|
push @{$repohash{$pkg}{"$repodir/smedev"}}, $ver; |
|
|
$changed{"$repodir/smedev"}++; |
|
328 |
} |
} |
329 |
|
} elsif ( scalar @{$acnt->{$r}->{$p}->{$a}} != 1 ) { |
330 |
|
print "\n * many packages ($r, $a, $p)\n"; |
331 |
|
} |
332 |
} |
} |
333 |
|
} |
334 |
} |
} |
|
} |
|
335 |
|
|
336 |
foreach my $pkg ( grep { $repohash{$_}{"$repodir/smedev"} } keys %repohash ) { |
foreach my $pkg ( sort { $a->{nvra} cmp $b->{nvra} } @{$rpms->{$base}->{rpms}} ) { |
337 |
foreach my $rpm ( @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
if ( $pkg->{latest} && $pkg->{latest} == 1 ) { |
338 |
unless ( grep { $rpm eq $_ } @{$repohash{$pkg}{builds}} ) { |
$pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo}; |
339 |
push @remove, $rpm->filename; |
$pkg->{repo} = $stage; |
340 |
@{$repohash{$pkg}{"$repodir/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$repodir/smedev"}}; |
push @{$pkg->{repos}}, $stage; |
341 |
$changed{"$repodir/smedev"}++; |
} |
342 |
|
if ( ! $print && ($pkg->{delete} || $pkg->{repos} || $pkg->{nosig} ) ) { |
343 |
|
print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n"; |
344 |
|
$print++; |
345 |
|
} |
346 |
|
|
347 |
|
my $src = $pkg->{rpm}->filename; |
348 |
|
if ( $pkg->{nosig} ) { |
349 |
|
print "sign package (", basename($pkg->{rpm}->filename), ")\n"; |
350 |
|
unless ( $opts{t} ) { |
351 |
|
qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null); |
352 |
|
if ($?) { |
353 |
|
print " * failed to sign package\n"; |
354 |
|
next; |
355 |
|
} |
356 |
} |
} |
357 |
} |
} |
|
} |
|
358 |
|
|
359 |
print "\n"; |
if ( $pkg->{repos} ) { |
360 |
foreach my $repo ( sort keys %srcrepohash ) { |
foreach my $repo ( @{$pkg->{repos}} ) { |
361 |
foreach my $pkg ( sort grep { $repohash{$_}{$repo} } keys %repohash ) { |
if ( $pkg->{delete} ) { |
362 |
my @rpms = ref($repohash{$pkg}{$repo}) eq "ARRAY" ? @{$repohash{$pkg}{$repo}} : ($repohash{$pkg}{$repo}); |
print "move from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
363 |
foreach my $rpm ( sort @rpms ) { |
$pkg->{delete} = 0; |
364 |
my $src = $rpm->tag("SOURCERPM"); |
$repochg{$pkg->{oldrepo}}++ unless $repos->{$pkg->{oldrepo}}->{base} || $repos->{$pkg->{oldrepo}}->{stage}; |
365 |
|
} elsif ( $pkg->{oldrepo} eq $repo ) { |
366 |
my @sources = (); |
print "distribute noarch in $repo (", basename($pkg->{rpm}->filename), ")\n"; |
367 |
push @sources, $src; |
} else { |
368 |
push @sources, $src if ($src =~ s/\.2\.el4\.rf\./\.rf\./); |
print "copy from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
369 |
push @sources, $src if ($src =~ s/\.el4\.rf\./\.rf\./); |
} |
370 |
push @sources, $src if ($src =~ s/\.el4\.at\./\.at\./); |
$repochg{$repo}++ unless $repos->{$repo}->{base} || $repos->{$repo}->{stage}; |
371 |
push @sources, $src if ($src =~ s/\.rf\./\.dag\./); |
$pkg->{oldrepo} = $repo unless $pkg->{oldrepo} eq ${$pkg->{repos}}[0]; |
372 |
|
|
373 |
my $found = 0; |
my @d = (); |
374 |
foreach my $source ( @sources ) { |
my $head = $distrepo->{$ver}->{repo} . $repo . '/'; |
375 |
if ( $sources{$source} ) { |
$head = $distrepo->{$ver}->{stage} if $repos->{$repo}->{stage}; |
376 |
unless ( -f "$repo/SRPMS/$source" ) { |
my $tail = $repos->{$repo}->{os} ? "$osdir/" . $distrepo->{$ver}->{os} : 'RPMS/'; |
377 |
push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source"; |
if ( $pkg->{src} ) { |
378 |
$changed{$repo}++; |
push @d, "${head}SRPMS/" . basename($pkg->{rpm}->filename); |
379 |
} |
} elsif ( $pkg->{rpm}->arch eq 'noarch' ) { |
380 |
$srcrepohash{$repo}{$source}++; |
push @d, map { "${head}$_/$tail" . basename($pkg->{rpm}->filename) } @archs; |
381 |
$found++; |
} elsif ( $pkg->{rpm}->arch =~ m{^(i[356]86)$} ) { |
382 |
last; |
push @d, "${head}i386/$tail" . basename($pkg->{rpm}->filename); |
383 |
} elsif ( -f "$repo/SRPMS/$source" ) { |
} else { |
384 |
print "Found missing source $repo/SRPMS/$source for ".$rpm->as_nvre()."\n"; |
push @d, $head . $pkg->{rpm}->arch . "/$tail" . basename($pkg->{rpm}->filename); |
385 |
$srcrepohash{$repo}{$source}++; |
} |
386 |
$found++; |
foreach my $dest ( @d ) { |
387 |
} |
qx(cp --preserve=timestamps $src $dest) unless $opts{t} || -f "$dest"; |
388 |
} |
} |
389 |
print "Can't find source for ".$rpm->as_nvre()."\n" unless $found; |
|
390 |
|
} |
391 |
|
qx(rm -f $src) if exists $pkg->{delete} && ! $opts{t}; |
392 |
|
} elsif ( $pkg->{delete} ) { |
393 |
|
print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n"; |
394 |
|
qx(rm -f $src) unless $opts{t}; |
395 |
|
$repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage}; |
396 |
|
if ( $repos->{$pkg->{repo}}->{orig} && ! $repos->{$pkg->{repo}}->{base} ) { |
397 |
|
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$pkg->{repo}}, $pkg->{name}, $pkg->{ver}, $pkg->{rel}; |
398 |
|
qx(rm -f $tag/PUSHED) if ! $opts{t} && -d $tag && -f "$tag/PUSHED"; |
399 |
} |
} |
400 |
|
} |
401 |
} |
} |
402 |
|
} |
403 |
|
|
404 |
foreach my $rpm ( keys %{$srcrepohash{$repo}} ) { |
if ( %repochg ) { |
405 |
unless ( $srcrepohash{$repo}{$rpm} ) { |
print "\nrebuild repo ($disttag$ver)\n", "=" x length("rebuild repo ($disttag$ver)"), "\n"; |
406 |
push @remove, "$repo/SRPMS/$rpm"; |
} |
407 |
$changed{$repo}++; |
foreach my $repo ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %repochg ) { |
408 |
|
next if $repos->{$repo}->{orig} || $repos->{$repo}->{stage}; |
409 |
|
foreach my $arch ( @archs ) { |
410 |
|
my $dir = $distrepo->{$ver}->{repo} . "$repo/$arch"; |
411 |
|
$dir = qx(readlink -f $dir); |
412 |
|
chomp $dir; |
413 |
|
print "rebuild $repo/$arch\n"; |
414 |
|
unless ( $opts{t} ) { |
415 |
|
if ( -f "$dir/repodata/comps.xml" ) { |
416 |
|
qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm --groupfile repodata/comps.xml $dir); |
417 |
|
} else { |
418 |
|
qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm $dir); |
419 |
} |
} |
420 |
|
qx(repoview $dir); |
421 |
|
qx(rm -rf $dir/.olddata) if -d "$dir/.olddata"; |
422 |
|
qx(rm -rf $dir/.repodata) if -d "$dir/.repodata"; |
423 |
|
} |
424 |
} |
} |
425 |
|
} |
426 |
|
unless ( $opts{t} ) { |
427 |
|
finddepth(sub{rmdir}, $distrepo->{$ver}->{$_}) foreach ('builds','contribs'); |
428 |
|
} |
429 |
} |
} |
430 |
|
|
431 |
print "\n"; |
sub verrel { |
432 |
foreach my $repo ( sort keys %copy ) { |
my $pkg = shift; |
433 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) { |
my $repo = shift; |
434 |
print "copying $rpm to $repo/\n"; |
my $counts = shift; |
435 |
system(qw(cp --preserve=timestamps), $rpm, "$repo/"); |
|
436 |
} |
return 0 if $pkg->{src}; |
437 |
|
$counts->{$repo}->{$pkg->{ver}}->{$pkg->{rel}}++; |
438 |
|
return 1 if $repos->{$repo}->{ver} && scalar keys %{$counts->{$repo}} > $repos->{$repo}->{ver}; |
439 |
|
return 1 if $repos->{$repo}->{rel} && scalar keys %{$counts->{$repo}->{$pkg->{ver}}} > $repos->{$repo}->{rel}; |
440 |
|
return 0; |
441 |
} |
} |
442 |
|
|
443 |
print "\n"; |
sub pkgdest { |
444 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @remove }} ) { |
my $pkg = shift; |
445 |
print "removing $rpm\n"; |
my $dest = shift; |
446 |
unlink $rpm; |
my $hirepo = shift; |
447 |
|
my $pkgs = shift; |
448 |
|
|
449 |
|
foreach my $cmp ( @$pkgs ) { |
450 |
|
next if $cmp->{src} || $repos->{$cmp->{repo}}->{prio} <= $repos->{$dest}->{prio}; |
451 |
|
next if $pkg->{name} ne ( $pkg->{src} ? $cmp->{base} : $cmp->{name} ); |
452 |
|
if ( $repos->{$cmp->{repo}}->{prio} > $repos->{$hirepo}->{prio} ) { |
453 |
|
$dest = $hirepo; |
454 |
|
last; |
455 |
|
} else { |
456 |
|
$dest = $cmp->{repo}; |
457 |
|
} |
458 |
|
} |
459 |
|
return $dest; |
460 |
} |
} |
461 |
|
|
462 |
print "\n"; |
sub process_rpm { |
463 |
foreach my $repo ( sort keys %changed ) { |
my $rpm = shift; |
464 |
next if $repo =~ m{^/builds}; |
my $ver = shift; |
465 |
|
my $repo = shift; |
466 |
print "rebuilding $repo/i386...\n"; |
return unless $rpm =~ m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$}; |
467 |
system(qw(createrepo), "$repo/i386"); |
my $base = $1; |
468 |
system(qw(repoview), "$repo/i386"); |
return unless ! $opts{r} || $base =~ m[$opts{r}]; |
469 |
|
return unless $latest{$base} || $sources{$base} || ! $repos->{$repo}->{base}; |
470 |
|
|
471 |
|
my $pkg; |
472 |
|
eval { $pkg = RPM2->open_package($rpm, $rpm_flags); }; |
473 |
|
if ($@) { print " * corrupt package ($rpm)\n"; return; } |
474 |
|
eval { my $sig = $pkg->siggpg }; |
475 |
|
my $nosig = ! $@; |
476 |
|
|
477 |
|
my $cmp = $latest{$pkg->name}; |
478 |
|
if ( $repos->{$repo}->{base} && ! $pkg->is_source_package ) { |
479 |
|
return unless $cmp; |
480 |
|
return if $repos->{$cmp->{repo}}->{base} && $repos->{$cmp->{repo}}->{prio} > $repos->{$repo}->{prio} && $pkg ge $cmp->{rpm}; |
481 |
|
} |
482 |
|
my ($src, $version, $release) = ($pkg->is_source_package ? $pkg->filename : $pkg->sourcerpm) =~ m{(?:^|/)([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$}; |
483 |
|
return if $skippkg->{$ver}->{$repo} && ( $skippkg->{$ver}->{$repo}->{$src} || $skippkg->{$ver}->{$repo}->{$pkg->name} ); |
484 |
|
return if $repos->{$repo}->{base} && $nosig; |
485 |
|
if ( $nosig && ! -f "$HOME/.rpmpass" ) { print " * missing signature (" .$pkg->filename . ")\n"; return; } |
486 |
|
my $arch = 'unknown'; |
487 |
|
$arch = 'SRPMS' if $pkg->filename =~ m{[/-](SRPMS?|src|source)/}; |
488 |
|
$arch = 'x86_64' if $pkg->filename =~ m{[/-]x86_64/}; |
489 |
|
$arch = 'i386' if $pkg->filename =~ m{[/-](i[356]86)/}; |
490 |
|
$arch = 'noarch' if $pkg->filename =~ m{[/-]noarch/}; |
491 |
|
|
492 |
|
my $rpmhash = { base => $src, |
493 |
|
name => $pkg->name, |
494 |
|
repo => $repo, |
495 |
|
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
496 |
|
svr => $src.'-'.$version.'-'.$release, |
497 |
|
src => $pkg->is_source_package, |
498 |
|
arch => $arch, |
499 |
|
ver => $version, |
500 |
|
rel => $release, |
501 |
|
rpm => $pkg, |
502 |
|
nosig => $nosig, |
503 |
|
}; |
504 |
|
if ( $pkg->is_source_package ) { |
505 |
|
push @{$rpms->{$src}->{srpms}}, $rpmhash; |
506 |
|
push @{$rpms->{$src}->{vers}->{$rpmhash->{svr}}}, $rpmhash; |
507 |
|
} else { |
508 |
|
push @{$rpms->{$src}->{rpms}}, $rpmhash; |
509 |
|
} |
510 |
|
$sources{$src}++; |
511 |
|
|
512 |
|
return if $pkg->is_source_package || $repos->{$repo}->{stage}; |
513 |
|
if ( ! $repos->{$repo}->{base} ) { |
514 |
|
if ( ! $cmp || $pkg gt $cmp->{rpm} ) { |
515 |
|
$latest{$pkg->name} = $rpmhash; |
516 |
|
} |
517 |
|
} elsif ( ( $repos->{$repo}->{prio} >= $repos->{$cmp->{repo}}->{prio} || ! $repos->{$cmp->{repo}}->{base} ) && $pkg ge $cmp->{rpm} ) { |
518 |
|
$latest{$pkg->name} = $rpmhash; |
519 |
|
} |
520 |
} |
} |