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