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