/[smeserver]/builds_bin/update_repos
ViewVC logotype

Contents of /builds_bin/update_repos

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.75 - (show annotations) (download)
Fri Aug 15 15:29:42 2014 UTC (10 years, 3 months ago) by slords
Branch: MAIN
Changes since 1.74: +1 -1 lines
Reduce noise

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

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed