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/redhat/el~C/en/~A/dag/RPMS/' => 'rpmforge', |
80 |
'/mirrors/rpmforge/redhat/el~C/en/~A/extras/RPMS/' => 'rpmforge', |
81 |
'/mirrors/rpmforge/source/' => 'rpmforge', |
82 |
'/mirrors/atrpms/el~C-~A/atrpms/stable/' => 'atrpms', |
83 |
'/mirrors/atrpms/el~C-~A/atrpms/testing/' => 'atrpms', |
84 |
'/mirrors/atrpms/src/el~C-~A/atrpms/stable/' => 'atrpms', |
85 |
'/mirrors/atrpms/src/el~C-~A/atrpms/testing/' => 'atrpms', |
86 |
}; |
87 |
|
88 |
if ( $opts{q} ) { |
89 |
$baserepo->{'/mirrors/centos-qa/CentOS/~C/fasttrack/~A/RPMS/'} = 'centos'; |
90 |
$baserepo->{'/mirrors/centos-qa/CentOS/~C/updates/~A/RPMS/'} = 'centos'; |
91 |
$baserepo->{'/mirrors/centos-qa/CentOS/~C/os/~A/CentOS/~O'} = 'centos'; |
92 |
$baserepo->{'/mirrors/centos-qa/CentOS/~C/extras/~A/RPMS/'} = 'centos'; |
93 |
} |
94 |
|
95 |
my $skippkg = { '7' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) }, |
96 |
'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' ) }, |
97 |
'rpmforge' => { map { $_ => 1 } ( 'mod_auth_tkt', 'perl-Test-Inline', 'spamassassin' ) }, |
98 |
'atrpms' => { map { $_ => 1 } ( 'check4updates', 'dovecot', 'trac', 'yum' ) }, |
99 |
}, |
100 |
'8' => { 'atrpms' => { map { $_ => 1 } ( 'gnupg' ) }, |
101 |
'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) }, |
102 |
'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', 'smolt' ) }, |
103 |
'rpmforge' => { map { $_ => 1 } ( 'libtalloc', 'mod_auth_tkt', 'perl-Test-Inline', 'spamassassin' ) }, |
104 |
}, |
105 |
}; |
106 |
|
107 |
my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos; |
108 |
my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos; |
109 |
$devel2 ||= $devel1; |
110 |
|
111 |
my ($rpms, %base, %latest, %sources); |
112 |
foreach my $ver ( sort { $a <=> $b } keys %$distrepo ) { |
113 |
next unless $distrepo->{$ver}->{active}; |
114 |
my %repochg = (); |
115 |
$rpms = (); |
116 |
%latest = (); |
117 |
%sources = (); |
118 |
%base = (); |
119 |
|
120 |
foreach my $dir ( sort { $repos->{$baserepo->{$b}}->{prio} <=> $repos->{$baserepo->{$a}}->{prio} || $a cmp $b } keys %$baserepo ) { |
121 |
my $bdir = $dir; |
122 |
$bdir =~ s/~O/$distrepo->{$ver}->{os}/; |
123 |
$bdir =~ s/~S/$distrepo->{$ver}->{repo}/; |
124 |
$bdir =~ s/~s/$ver/; |
125 |
$bdir =~ s/~C/$distrepo->{$ver}->{centos}/; |
126 |
for my $arch ( @archs, 'SRPMS/' ) { |
127 |
my $adir = $bdir; |
128 |
if ( $arch eq 'SRPMS/' ) { |
129 |
$adir =~ s/~A.*/$arch/; |
130 |
} else { |
131 |
$adir =~ s/~A/$arch/; |
132 |
} |
133 |
opendir DIR, $adir or next; |
134 |
next unless -d $adir; |
135 |
process_rpm("$adir$_", $ver, $baserepo->{$dir}) foreach readdir DIR; |
136 |
closedir DIR; |
137 |
last unless $dir =~ m{~A}; |
138 |
} |
139 |
} |
140 |
find( { wanted => sub { process_rpm($_, $ver, 'builds'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'builds'} ); |
141 |
find( { wanted => sub { process_rpm($_, $ver, 'community'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'community'} ) if $distrepo->{$ver}->{'community'}; |
142 |
|
143 |
foreach my $base ( sort keys %$rpms ) { |
144 |
next unless $rpms->{$base}->{rpms}; |
145 |
my %track = (); |
146 |
my %seen = (); |
147 |
my %counts = (); |
148 |
my $acnt = (); |
149 |
my $print = 0; |
150 |
%latest = (); |
151 |
|
152 |
foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{rpms}} ) { |
153 |
next if $pkg->{done}; |
154 |
|
155 |
my $tmp = $pkg->{svr}; |
156 |
# srpm transformations to match up binary and source rpms |
157 |
SRC: { |
158 |
# Try to find the name the binary wants (no changes) |
159 |
$rpms->{$base}->{vers}->{$tmp} && last SRC; |
160 |
|
161 |
# rpmforge (.el4.rf to .rf, with rf,rfb,rft,rfx endings) |
162 |
($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf[btx]?)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
163 |
# rpmforge (.el4.rfx to .rf, with rfb,rft,rfx switched to rf) |
164 |
($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)[btx]$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
165 |
# rpmforge (.el4.rf to .el5) TODO: remove when no longer needed |
166 |
($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.el5} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
167 |
# rpmforge (.2.el4.rf to .rf, minor modification not pushed to source?) TODO: remove when no longer needed |
168 |
($tmp = $pkg->{svr}) =~ s{\.2\.el\d(\.rf)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
169 |
|
170 |
# atrpms (remove .el4.at) |
171 |
($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
172 |
# atrpms (remove .el4) |
173 |
($tmp = $pkg->{svr}) =~ s{\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
174 |
# atrpms (remove .0.el5, minor modification not pushed to source?) TODO: remove when no longer needed |
175 |
($tmp = $pkg->{svr}) =~ s{\.0\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
176 |
|
177 |
# Transformations that we hopefully won't have to use anymore TODO: remove if no issues |
178 |
#($tmp = $pkg->{svr}) =~ s{(\.el\d)\.rf$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
179 |
#($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+(\.rf)$}{$1$2} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
180 |
#($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
181 |
#($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d\.rf$}{$1.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
182 |
#($tmp = $pkg->{svr}) =~ s{\.el\d_}{_} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
183 |
#($tmp = $pkg->{svr}) =~ s{(-\d+)\.\d+\.el\d$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
184 |
#($tmp = $pkg->{svr}) =~ s{\.centos\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
185 |
#($tmp = $pkg->{svr}) =~ s{\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
186 |
#($tmp = $pkg->{svr}) =~ s{\.el\d\.$disttag$}{ && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
187 |
} |
188 |
if ( $rpms->{$base}->{vers}->{$tmp} ) { |
189 |
foreach $tmp ( @{$rpms->{$base}->{vers}->{$tmp}} ) { |
190 |
$tmp->{svr} = $pkg->{svr}; |
191 |
push @{$rpms->{$base}->{rpms}}, $tmp unless $tmp->{added}; |
192 |
$tmp->{added}++; |
193 |
} |
194 |
} |
195 |
|
196 |
my %orig = (); |
197 |
my %pkgs = (); |
198 |
my %reposrc = (); |
199 |
my $srpm = undef; |
200 |
foreach my $cmp ( sort { $a->{src} <=> $b->{src} || $repos->{$b->{repo}}->{prio} <=> $repos->{$a->{repo}}->{prio} } @{$rpms->{$base}->{rpms}} ) { |
201 |
next unless $cmp->{svr} eq $pkg->{svr}; |
202 |
|
203 |
if ( ! $track{repo} || $repos->{$cmp->{repo}}->{prio} > $repos->{$track{repo}}->{prio} ) { |
204 |
if ( $cmp->{src} ) { |
205 |
if ( ! $track{repo} ) { |
206 |
$cmp->{delete}++; |
207 |
$cmp->{done}++; |
208 |
next; |
209 |
} |
210 |
} else { |
211 |
$track{repo} = $cmp->{repo}; |
212 |
$track{svr} = $cmp->{svr}; |
213 |
} |
214 |
} |
215 |
if ( $cmp->{svr} eq $track{svr} ) { |
216 |
if ( $seen{$cmp->{nvra}} ) { |
217 |
if ( $track{repo} ne $cmp->{repo} ) { |
218 |
if ($repos->{$cmp->{repo}}->{stage} ) { |
219 |
if ( $seen{$cmp->{nvra}}->{latest} ) { |
220 |
$seen{$cmp->{nvra}}->{latest}++; |
221 |
delete $cmp->{delete} if $cmp->{delete}; |
222 |
} else { |
223 |
$cmp->{delete}++; |
224 |
} |
225 |
} elsif ( $repos->{$cmp->{repo}}->{orig} ) { |
226 |
$orig{$cmp->{nvra}}++; |
227 |
unless ( $repos->{$cmp->{repo}}->{base} ) { |
228 |
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
229 |
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
230 |
} |
231 |
} elsif ( $cmp->{src} ) { |
232 |
if ( $cmp->{delete} && $cmp->{oldrepo} && $reposrc{$cmp->{oldrepo}}) { |
233 |
$cmp->{repo} = $cmp->{oldrepo}; |
234 |
delete $cmp->{delete}; |
235 |
} |
236 |
if ( $reposrc{$cmp->{repo}} ) { |
237 |
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
238 |
$srpm = $cmp if ! $srpm; |
239 |
} elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} && ! $cmp->{done} ) { |
240 |
$cmp->{delete}++; |
241 |
} |
242 |
} elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} ) { |
243 |
$cmp->{delete}++; |
244 |
} |
245 |
} elsif ( $cmp->{src} ) { |
246 |
if ( $reposrc{$cmp->{repo}} && $reposrc{$cmp->{repo}}->{srpm} && $reposrc{$cmp->{repo}}->{srpm}->{oldrepo} ne $cmp->{repo} ) { |
247 |
$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{src} = [ |
248 |
grep { $_ ne $reposrc{$cmp->{repo}}->{srpm} } @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{src}} |
249 |
]; |
250 |
|
251 |
if ( @{$reposrc{$cmp->{repo}}->{srpm}->{repos}} == 1 ) { |
252 |
$reposrc{$cmp->{repo}}->{srpm}->{repo} = $reposrc{$cmp->{repo}}->{srpm}->{oldrepo}; |
253 |
delete $reposrc{$cmp->{repo}}->{srpm}->{oldrepo}; |
254 |
delete $reposrc{$cmp->{repo}}->{srpm}->{delete}; |
255 |
delete $reposrc{$cmp->{repo}}->{srpm}->{repos}; |
256 |
delete $reposrc{$cmp->{repo}}->{srpm}->{done}; |
257 |
$seen{$cmp->{nvra}} = $cmp if $seen{$cmp->{nvra}} eq $reposrc{$cmp->{repo}}->{srpm}; |
258 |
} else { |
259 |
warn "How did I get here??"; |
260 |
} |
261 |
} else { |
262 |
$seen{$cmp->{nvra}} = $cmp if $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo}; |
263 |
} |
264 |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
265 |
$reposrc{$cmp->{repo}}->{srpm} = $cmp if $reposrc{$cmp->{repo}}; |
266 |
} |
267 |
} elsif ($repos->{$cmp->{repo}}->{stage} ) { |
268 |
$cmp->{delete}++; |
269 |
} else { |
270 |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
271 |
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
272 |
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
273 |
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
274 |
if ( $cmp->{repo} ne $dest ) { |
275 |
push @{$cmp->{repos}}, $dest; |
276 |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
277 |
$orig{$cmp->{nvra}}++; |
278 |
unless ( $repos->{$cmp->{repo}}->{base} ) { |
279 |
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
280 |
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
281 |
} |
282 |
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
283 |
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
284 |
} else { |
285 |
$cmp->{delete}++; |
286 |
} |
287 |
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
288 |
$cmp->{repo} = $dest; |
289 |
if ( ! $cmp->{src} && $repos->{$dest}->{prio} > $repos->{$track{repo}}->{prio} ) { |
290 |
$track{repo} = $dest; |
291 |
$track{svr} = $cmp->{svr}; |
292 |
} |
293 |
} |
294 |
if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
295 |
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
296 |
} |
297 |
} |
298 |
} else { |
299 |
if ( $track{repo} eq $cmp->{repo} ) { |
300 |
if ( verrel($cmp, $cmp->{repo}, \%counts) ) { |
301 |
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
302 |
} elsif ( $cmp->{src} ) { |
303 |
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
304 |
} else { |
305 |
$track{svr} = $cmp->{svr}; |
306 |
} |
307 |
} elsif ( ! $repos->{$cmp->{repo}}->{base} ) { |
308 |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
309 |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
310 |
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
311 |
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
312 |
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
313 |
unless ( $cmp->{src} && ! $reposrc{$dest} ) { |
314 |
if ( $repos->{$dest}->{prio} >= $repos->{$track{repo}}->{prio} && ! verrel($cmp, $dest, \%counts) ) { |
315 |
unless ( $repos->{$cmp->{repo}}->{base} ) { |
316 |
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel}; |
317 |
qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED"; |
318 |
} |
319 |
push @{$cmp->{repos}}, $dest; |
320 |
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
321 |
$cmp->{repo} = $dest; |
322 |
$reposrc{$cmp->{repo}}->{srpm} = $cmp if $cmp->{src}; |
323 |
$orig{$cmp->{nvra}}++; |
324 |
} |
325 |
} |
326 |
} else { |
327 |
$cmp->{delete}++; |
328 |
} |
329 |
} |
330 |
} |
331 |
unless ( $repos->{$cmp->{repo}}->{orig} || ( $cmp->{delete} && ! $cmp->{repos} ) ) { |
332 |
$pkgs{$cmp->{nvra}}++; |
333 |
$latest{$cmp->{base}} = $cmp->{svr} if $repos->{$cmp->{repo}}->{inc} && ! $latest{$cmp->{base}}; |
334 |
$reposrc{$cmp->{repo}} = $cmp unless $reposrc{$cmp->{repo}} || $cmp->{src} || $repos->{$cmp->{repo}}->{stage}; |
335 |
if ( $latest{$cmp->{base}} && $cmp->{svr} eq $latest{$cmp->{base}} && $repos->{$cmp->{repo}}->{inc} ) { |
336 |
$cmp->{latest}++ if ! $seen{$cmp->{nvra}} || $cmp->{src}; |
337 |
} |
338 |
$seen{$cmp->{nvra}} = $cmp unless $seen{$cmp->{nvra}}; |
339 |
push @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{$cmp->{src} ? 'src' : $cmp->{rpm}->arch}}, $cmp unless $cmp->{done}; |
340 |
} |
341 |
$cmp->{done}++; |
342 |
} |
343 |
if ( $srpm ) { |
344 |
foreach my $r ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %reposrc ) { |
345 |
unless ( $reposrc{$r}->{srpm} ) { |
346 |
unshift @{$srpm->{repos}}, $r; |
347 |
$srpm->{oldrepo} = $srpm->{repo} unless $srpm->{oldrepo}; |
348 |
$srpm->{repo} = $r; |
349 |
$reposrc{$r}->{srpm} = $srpm; |
350 |
} |
351 |
} |
352 |
} elsif ( scalar keys %pkgs && $opts{s} ) { |
353 |
print "\n * missing source ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n"; |
354 |
} |
355 |
print "\n * missing originals ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n" if $opts{o} && scalar keys %orig != scalar keys %pkgs; |
356 |
} |
357 |
|
358 |
foreach my $r ( keys %$acnt ) { |
359 |
foreach my $p ( keys %{$acnt->{$r}} ) { |
360 |
foreach my $a ( keys %{$acnt->{$r}->{$p}} ) { |
361 |
if ( $a eq 'noarch' ) { |
362 |
my $p2 = ${$acnt->{$r}->{$p}->{$a}}[0]; |
363 |
if ( ! $p2->{repos} && scalar @{$acnt->{$r}->{$p}->{$a}} != scalar @archs ) { |
364 |
$p2->{oldrepo} = $p2->{repo}; |
365 |
push @{$p2->{repos}}, $p2->{repo}; |
366 |
} |
367 |
} elsif ( scalar @{$acnt->{$r}->{$p}->{$a}} != 1 ) { |
368 |
print "\n * many packages ($r, $a, $p)\n"; |
369 |
} |
370 |
} |
371 |
} |
372 |
} |
373 |
|
374 |
foreach my $pkg ( sort { $a->{nvra} cmp $b->{nvra} } @{$rpms->{$base}->{rpms}} ) { |
375 |
if ( $pkg->{latest} && $pkg->{latest} == 1 ) { |
376 |
$pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo}; |
377 |
$pkg->{repo} = $stage; |
378 |
push @{$pkg->{repos}}, $stage; |
379 |
} |
380 |
if ( ! $print && ($pkg->{delete} || $pkg->{repos} || $pkg->{nosig} ) ) { |
381 |
print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n"; |
382 |
$print++; |
383 |
} |
384 |
|
385 |
my $src = $pkg->{rpm}->filename; |
386 |
if ( $pkg->{nosig} ) { |
387 |
print "sign package (", basename($pkg->{rpm}->filename), ")\n"; |
388 |
unless ( $opts{t} ) { |
389 |
qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null); |
390 |
if ($?) { |
391 |
print " * failed to sign package\n"; |
392 |
next; |
393 |
} |
394 |
} |
395 |
} |
396 |
|
397 |
if ( $pkg->{repos} ) { |
398 |
foreach my $repo ( @{$pkg->{repos}} ) { |
399 |
if ( $pkg->{delete} ) { |
400 |
print "move from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
401 |
$pkg->{delete} = 0; |
402 |
$repochg{$pkg->{oldrepo}}++ unless $repos->{$pkg->{oldrepo}}->{base} || $repos->{$pkg->{oldrepo}}->{stage}; |
403 |
} elsif ( $pkg->{oldrepo} eq $repo ) { |
404 |
print "distribute noarch in $repo (", basename($pkg->{rpm}->filename), ")\n"; |
405 |
} else { |
406 |
print "copy from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
407 |
} |
408 |
$repochg{$repo}++ unless $repos->{$repo}->{base} || $repos->{$repo}->{stage}; |
409 |
$pkg->{oldrepo} = $repo unless $pkg->{oldrepo} eq ${$pkg->{repos}}[0]; |
410 |
|
411 |
my @d = (); |
412 |
my $head = $distrepo->{$ver}->{repo} . $repo . '/'; |
413 |
$head = $distrepo->{$ver}->{stage} if $repos->{$repo}->{stage}; |
414 |
my $tail = $repos->{$repo}->{os} ? "$osdir/" . $distrepo->{$ver}->{os} : 'RPMS/'; |
415 |
if ( $pkg->{src} ) { |
416 |
push @d, "${head}SRPMS/" . basename($pkg->{rpm}->filename); |
417 |
} elsif ( $pkg->{rpm}->arch eq 'noarch' ) { |
418 |
push @d, map { "${head}$_/$tail" . basename($pkg->{rpm}->filename) } @archs; |
419 |
} elsif ( $pkg->{rpm}->arch =~ m{^(i[356]86)$} ) { |
420 |
push @d, "${head}i386/$tail" . basename($pkg->{rpm}->filename); |
421 |
} else { |
422 |
push @d, $head . $pkg->{rpm}->arch . "/$tail" . basename($pkg->{rpm}->filename); |
423 |
} |
424 |
foreach my $dest ( @d ) { |
425 |
qx(cp --preserve=timestamps $src $dest) unless $opts{t} || -f "$dest"; |
426 |
} |
427 |
|
428 |
} |
429 |
qx(rm -f $src) if exists $pkg->{delete} && ! $opts{t}; |
430 |
} elsif ( $pkg->{delete} ) { |
431 |
print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n"; |
432 |
qx(rm -f $src) unless $opts{t}; |
433 |
$repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage}; |
434 |
if ( $repos->{$pkg->{repo}}->{orig} && ! $repos->{$pkg->{repo}}->{base} ) { |
435 |
my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$pkg->{repo}}, $pkg->{name}, $pkg->{ver}, $pkg->{rel}; |
436 |
qx(rm -f $tag/PUSHED) if ! $opts{t} && -d $tag && -f "$tag/PUSHED"; |
437 |
} |
438 |
} |
439 |
} |
440 |
|
441 |
if ( $rpms->{$base}->{srpms} ) { |
442 |
foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{srpms}} ) { |
443 |
next if $pkg->{done} || $repos->{$pkg->{repo}}->{orig} || $repos->{$pkg->{repo}}->{base}; |
444 |
$pkg->{delete}++; |
445 |
my $src = $pkg->{rpm}->filename; |
446 |
if ( ! $print && ($pkg->{delete} || $pkg->{repos} || $pkg->{nosig} ) ) { |
447 |
print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n"; |
448 |
$print++; |
449 |
} |
450 |
print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n"; |
451 |
qx(rm -f $src) unless $opts{t}; |
452 |
$repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage}; |
453 |
} |
454 |
} |
455 |
} |
456 |
|
457 |
if ( %repochg ) { |
458 |
print "\nrebuild repo ($disttag$ver)\n", "=" x length("rebuild repo ($disttag$ver)"), "\n"; |
459 |
} |
460 |
foreach my $repo ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %repochg ) { |
461 |
next if $repos->{$repo}->{orig} || $repos->{$repo}->{stage}; |
462 |
foreach my $arch ( @archs ) { |
463 |
my $dir = $distrepo->{$ver}->{repo} . "$repo/$arch"; |
464 |
$dir = qx(readlink -f $dir); |
465 |
chomp $dir; |
466 |
print "rebuild $repo/$arch\n"; |
467 |
unless ( $opts{t} ) { |
468 |
if ( $dir =~ m{test/|-testing/} ) { |
469 |
if ( -f "$dir/repodata/comps.xml" ) { |
470 |
qx(createrepo --update --database --exclude *smeserver-release*.rpm --exclude *.src.rpm --exclude *-debuginfo-*.rpm --groupfile repodata/comps.xml $dir); |
471 |
} else { |
472 |
qx(createrepo --update --database --exclude *smeserver-release*.rpm --exclude *.src.rpm --exclude *-debuginfo-*.rpm $dir); |
473 |
} |
474 |
} else { |
475 |
if ( -f "$dir/repodata/comps.xml" ) { |
476 |
qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm --groupfile repodata/comps.xml $dir); |
477 |
} else { |
478 |
qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm $dir); |
479 |
} |
480 |
} |
481 |
qx(repoview $dir); |
482 |
qx(rm -rf $dir/.olddata) if -d "$dir/.olddata"; |
483 |
qx(rm -rf $dir/.repodata) if -d "$dir/.repodata"; |
484 |
qx(rm -rf $dir/repodata/index.html) if -f "$dir/repodata/index.html"; |
485 |
qx(rm -rf $dir/repodata/update-info) if -d "$dir/repodata/update-info"; |
486 |
qx(rm -rf $dir/repodata/repoview) if -d "$dir/repodata/repoview"; |
487 |
} |
488 |
} |
489 |
} |
490 |
unless ( $opts{t} ) { |
491 |
finddepth(sub{rmdir}, $distrepo->{$ver}->{builds}) if -d "$distrepo->{$ver}->{builds}"; |
492 |
finddepth(sub{rmdir}, $distrepo->{$ver}->{community}) if -d "$distrepo->{$ver}->{community}"; |
493 |
} |
494 |
} |
495 |
|
496 |
sub verrel { |
497 |
my $pkg = shift; |
498 |
my $repo = shift; |
499 |
my $counts = shift; |
500 |
|
501 |
return 0 if $pkg->{src}; |
502 |
$counts->{$repo}->{$pkg->{ver}}->{$pkg->{rel}}++; |
503 |
return 1 if $repos->{$repo}->{ver} && scalar keys %{$counts->{$repo}} > $repos->{$repo}->{ver}; |
504 |
return 1 if $repos->{$repo}->{rel} && scalar keys %{$counts->{$repo}->{$pkg->{ver}}} > $repos->{$repo}->{rel}; |
505 |
return 0; |
506 |
} |
507 |
|
508 |
sub pkgdest { |
509 |
my $pkg = shift; |
510 |
my $dest = shift; |
511 |
my $hirepo = shift; |
512 |
my $pkgs = shift; |
513 |
|
514 |
foreach my $cmp ( @$pkgs ) { |
515 |
next if $cmp->{src} || $repos->{$cmp->{repo}}->{prio} <= $repos->{$dest}->{prio}; |
516 |
next if $pkg->{name} ne ( $pkg->{src} ? $cmp->{base} : $cmp->{name} ); |
517 |
if ( $repos->{$cmp->{repo}}->{prio} > $repos->{$hirepo}->{prio} ) { |
518 |
$dest = $hirepo; |
519 |
last; |
520 |
} else { |
521 |
$dest = $cmp->{repo}; |
522 |
} |
523 |
} |
524 |
return $dest; |
525 |
} |
526 |
|
527 |
sub process_rpm { |
528 |
my $rpm = shift; |
529 |
my $ver = shift; |
530 |
my $repo = shift; |
531 |
return unless $rpm =~ m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$}; |
532 |
my $base = $1; |
533 |
return unless ! $opts{r} || $base =~ m[$opts{r}]; |
534 |
return unless $latest{$base} || $sources{$base} || ! $repos->{$repo}->{base}; |
535 |
|
536 |
my $pkg; |
537 |
eval { $pkg = RPM2->open_package($rpm, $rpm_flags); }; |
538 |
if ($@) { print " * corrupt package ($rpm)\n"; return; } |
539 |
eval { my $sig = $pkg->siggpg }; |
540 |
my $nosig = ! $@; |
541 |
|
542 |
my $cmp = $latest{$pkg->name}; |
543 |
if ( $repos->{$repo}->{base} && ! $pkg->is_source_package ) { |
544 |
return unless $cmp; |
545 |
return if $repos->{$cmp->{repo}}->{base} && $repos->{$cmp->{repo}}->{prio} > $repos->{$repo}->{prio} && $pkg ge $cmp->{rpm}; |
546 |
} |
547 |
my ($src, $version, $release) = ($pkg->is_source_package ? $pkg->filename : $pkg->sourcerpm) =~ m{(?:^|/)([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$}; |
548 |
return if $skippkg->{$ver}->{$repo} && ( $skippkg->{$ver}->{$repo}->{$src} || $skippkg->{$ver}->{$repo}->{$pkg->name} ); |
549 |
return if $repos->{$repo}->{base} && $nosig; |
550 |
if ( $nosig && ! -f "$HOME/.rpmpass" ) { print " * missing signature (" .$pkg->filename . ")\n"; return; } |
551 |
my $arch = 'unknown'; |
552 |
$arch = 'SRPMS' if $pkg->filename =~ m{[/-](SRPMS?|src|source)/}; |
553 |
$arch = 'x86_64' if $pkg->filename =~ m{[/-]x86_64/}; |
554 |
$arch = 'i386' if $pkg->filename =~ m{[/-](i[356]86)/}; |
555 |
$arch = 'noarch' if $pkg->filename =~ m{[/-]noarch/}; |
556 |
|
557 |
my $rpmhash = { base => $src, |
558 |
name => $pkg->name, |
559 |
repo => $repo, |
560 |
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
561 |
svr => $src.'-'.$version.'-'.$release, |
562 |
src => $pkg->is_source_package, |
563 |
arch => $arch, |
564 |
ver => $version, |
565 |
rel => $release, |
566 |
rpm => $pkg, |
567 |
nosig => $nosig, |
568 |
}; |
569 |
if ( $pkg->is_source_package ) { |
570 |
push @{$rpms->{$src}->{srpms}}, $rpmhash; |
571 |
push @{$rpms->{$src}->{vers}->{$rpmhash->{svr}}}, $rpmhash; |
572 |
} else { |
573 |
push @{$rpms->{$src}->{rpms}}, $rpmhash; |
574 |
} |
575 |
$sources{$src}++; |
576 |
|
577 |
return if $pkg->is_source_package || $repos->{$repo}->{stage}; |
578 |
if ( ! $repos->{$repo}->{base} ) { |
579 |
if ( ! $cmp || $pkg gt $cmp->{rpm} ) { |
580 |
$latest{$pkg->name} = $rpmhash; |
581 |
} |
582 |
} elsif ( ( $repos->{$repo}->{prio} >= $repos->{$cmp->{repo}}->{prio} || ! $repos->{$cmp->{repo}}->{base} ) && $pkg ge $cmp->{rpm} ) { |
583 |
$latest{$pkg->name} = $rpmhash; |
584 |
} |
585 |
} |