/[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.25 - (show annotations) (download)
Wed Nov 7 21:14:58 2007 UTC (17 years ago) by slords
Branch: MAIN
Changes since 1.24: +7 -6 lines
Fix noarch checks

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 Term::ANSIColor;
10 use Data::Dumper;
11
12 delete $ENV{PATH};
13 my $HOME=$ENV{HOME};
14 umask 002;
15
16 my $rpm_flags = RPM2->vsf_nosha1header | RPM2->vsf_nomd5header | RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader;
17 $rpm_flags |= RPM2->vsf_nosha1 | RPM2->vsf_nomd5 | RPM2->vsf_nodsa | RPM2->vsf_norsa;
18
19 $Term::ANSIColor::AUTORESET = 1;
20 $| = 1;
21
22 my @archs = ( 'i386', 'x86_64' );
23
24 my $repos = { 'smeos' => { prio => 17, inc => 1, ver => 1, rel => 1, os => 1 },
25 'smeupdates' => { prio => 16, inc => 1, ver => 1, rel => 1 },
26 'smeupdates-testing' => { prio => 15, inc => 1, ver => 1, rel => 1 },
27 'smeextras' => { prio => 14, inc => 0, ver => 1, rel => 1 },
28 'smeaddons' => { prio => 13, inc => 0, ver => 1, rel => 1 },
29 'smecontribs' => { prio => 12, inc => 0, ver => 1, rel => 1 },
30 'smetest' => { prio => 11, inc => 1, ver => 2, rel => 2, devel => 2 },
31 'smedev' => { prio => 10, inc => 0, ver => 2, rel => 2, devel => 1 },
32 'centos' => { prio => 9, inc => 0, ver => 0, rel => 0, base => 1 },
33 'fedora/epel' => { prio => 8, inc => 0, ver => 0, rel => 0, base => 1 },
34 'fedora/extras' => { prio => 7, inc => 0, ver => 0, rel => 0, base => 1 },
35 'rpmforge' => { prio => 6, inc => 0, ver => 0, rel => 0, base => 1 },
36 'atrpms' => { prio => 5, inc => 0, ver => 0, rel => 0, base => 1 },
37 'fedora/core' => { prio => 4, inc => 0, ver => 0, rel => 0, base => 1 },
38 'base' => { prio => 3, inc => 0, ver => 0, rel => 0, base => 1 },
39 'builds' => { prio => 2, inc => 0, ver => 0, rel => 0, builds => 1 },
40 'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 },
41 };
42
43 my $distrepo = { '7' => { active => 1,
44 centos => 4,
45 fedora => 3,
46 repo => '/releases/7/',
47 os => 'SME/RPMS/',
48 builds => '/builds/smeserver-7-core/',
49 stage => '/stage/7/',
50 },
51 '8' => { active => 1,
52 centos => 5,
53 fedora => 6,
54 repo => '/releases/testing/8/',
55 os => 'SME/',
56 builds => '/builds/smeserver-8-core/',
57 stage => '/stage/8/',
58 },
59 };
60
61 my @baserepo = ( ( map { "/mirrors/centos/~C/$_/" } ('os','updates','fasttrack','extras') ),
62 ( map { "/mirrors/fedora/epel$_/~C/" } ('','/testing') ),
63 '/mirrors/fedora/extras/~F/',
64 '/mirrors/rpmforge/dag/redhat/el~C/en/~A/RPMS.dag/',
65 '/mirrors/rpmforge/dag/source/',
66 ( map { "/mirrors/atrpms$_/el~C-~A/atrpms/stable/" } ('','/src') ),
67 ( map { "/mirrors/atrpms$_/el~C-~A/atrpms/testing/" } ('','/src') ),
68 ( map {"/mirrors/fedora/core$_/~F/" } ('','/updates') ),
69 );
70
71 my $skippkg = { '7' => { 'centos' => ['horde','imp-h3','ingo-h3','turba-h3','vim'],
72 'fedora/epel' => ['perl-Razor-Agent'],
73 'rpmforge' => ['perl-Test-Inline'],
74 'atrpms' => ['dovecot','yum'],
75 },
76 '8' => { 'centos' => ['horde','imp-h3','ingo-h3','turba-h3'],
77 'fedora/epel' => ['perl-Razor-Agent','smolt'],
78 'fedora/extras' => ['dstat','gocr','horde','oidentd','perl-Test-Inline','perl-Razor-Agent','smolt'],
79 'rpmforge' => ['perl-Test-Inline'],
80 'atrpms' => [],
81 'fedora/core' => [],
82 },
83 };
84
85 my %opts;
86 getopts( 'dtvr:', \%opts );
87 $opts{r} ||= '';
88
89 my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos;
90 $devel2 ||= $devel1;
91 my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos;
92
93 my ($rel, @rpms, %latest, %sources, $archs, $rebuild, $newline);
94 foreach my $smever ( sort { $a <=> $b } grep { $distrepo->{$_}->{active} } keys %$distrepo ) {
95 $rel = $smever;
96 %latest = ();
97 %sources = ();
98 @rpms = ();
99 $rebuild = ();
100
101 # Load distro packages
102 find( { wanted => \&loadpkg, no_chdir => 1, follow_fast => 1 }, map { $distrepo->{$smever}->{$_} } ('repo','builds','stage') );
103 printline('white', 0, "Distro (SME Server $rel) packages loaded.\n");
104
105 # Load base packages
106 foreach my $base ( @baserepo ) {
107 my $bdir = $base;
108 $bdir =~ s/~C/$distrepo->{$smever}->{centos}/;
109 $bdir =~ s/~F/$distrepo->{$smever}->{fedora}/;
110 if ( $bdir =~ m{~A} ) {
111 for my $arch ( @archs ) {
112 my $basearch = $bdir;
113 $basearch =~ s/~A/$arch/;
114 find( { wanted => \&loadbase, no_chdir => 1, follow_fast => 1 }, $basearch ) if -r $basearch;
115 }
116 } else {
117 find( { wanted => \&loadbase, no_chdir => 1, follow_fast => 1 }, $bdir ) if -r $bdir;
118 }
119 }
120 printline('white', 0, 'Base (Centos: ', $distrepo->{$smever}->{centos}, ', Fedora: ', $distrepo->{$smever}->{fedora}, ") packages loaded.\n");
121
122 %latest = ();
123 foreach my $name ( sort keys %{{ map { $_->{base} => 1 } @rpms }} ) {
124 printline('white', 0, "Processing: $name");
125 my @pkgs = sort pkgsrt grep { $_->{base} eq $name } @rpms;
126 my %seen = ();
127 my $count = ();
128 $archs = ();
129
130 foreach my $pkg ( @pkgs ) {
131 next if $pkg->{done} || $pkg->{obsolete} || $pkg->{rpm}->is_source_package || ! $repos->{$pkg->{repo}};
132 printline('bold black', 1, ' - ', $pkg->{rpm}->filename) if $opts{d};
133 my $orig = 0;
134
135 # Find names of packages in same or higher repos
136 my %names = names($pkg, @pkgs);
137
138 # Stage packages should never be most current
139 if ( rprop($pkg, 'stage') ) {
140 printline('dark blue', 1, ' - checking stage') if $opts{d};
141 tagpkg($pkg, 'obsolete');
142 next;
143 }
144
145 # Move packages from base/builds to correct area
146 elsif ( rprop($pkg, 'base') || rprop($pkg, 'builds') ) {
147 printline('dark blue', 1, ' - checking base/builds') if $opts{d};
148 my $repo = $names{$pkg->{name}} && $names{$pkg->{name}} > 1 ? $devel2 : $devel1;
149 if ( $pkg->{nonbase} ) {
150 foreach my $up ( @pkgs ) {
151 next if rprop($up, 'builds') || rprop($up, 'base');
152 next if $up->{name} ne $pkg->{name} || ! $up->{obsolete} || $up->{rpm} ge $pkg->{rpm};
153 $repo = $up->{repo};
154 last;
155 }
156 }
157 next if rprop($pkg, 'base') && $repo eq $devel1 && $devel1 ne $devel2;
158 movepkg($pkg, $repo);
159 %names = names($pkg, @pkgs);
160 $seen{$pkg->{nvra}}++;
161 $orig++;
162 }
163
164 # Check version/release counts
165 unless ( $pkg->{nonbase} ) {
166 printline('dark blue', 1, ' - checking version/release counts') if $opts{d};
167 $count->{$pkg->{repo}}->{$pkg->{version}}->{$pkg->{release}}++;
168 if ( rprop($pkg, 'ver') && scalar keys %{$count->{$pkg->{repo}}} > rprop($pkg, 'ver') ) {
169 movepkg($_, 'delete') foreach grep { $_->{rpm} eq $pkg->{rpm} } @pkgs;
170 next;
171 }
172 if ( rprop($pkg, 'rel') && scalar keys %{$count->{$pkg->{repo}}->{$pkg->{version}}} > rprop($pkg, 'rel') ) {
173 movepkg($_, 'delete') foreach grep { $_->{rpm} eq $pkg->{rpm} } @pkgs;
174 next;
175 }
176 }
177
178 foreach my $cmp ( grep { $_->{rpm}->is_source_package || ( ! $_->{done} && $_->{rpm} le $pkg->{rpm} && rprop($_, 'prio') <= rprop($pkg, 'prio') ) } @pkgs ) {
179 printline('dark blue', 1, ' - ', $cmp->{rpm}->filename) if $opts{d};
180 if ( $cmp->{rpm}->is_source_package ) {
181 if ( $cmp->{name} eq $pkg->{base} ) {
182 if ( $cmp->{rpm} eq $pkg->{rpm} ) {
183 if ( $pkg->{repo} eq $cmp->{repo} || ! $pkg->{srpm} || $pkg->{srpm}->{rpm} ne $pkg->{rpm} ) {
184 delete $pkg->{srpm}->{latest} if $pkg->{latest} && $pkg->{srpm} && $pkg->{srpm}->{latest};
185 $pkg->{srpm} = $cmp;
186 $pkg->{srpm}->{latest}++ if $pkg->{latest};
187 }
188 if ( $pkg->{latest} && rprop($cmp, 'stage') ) {
189 tagpkg($cmp, 'inuse');
190 $pkg->{srpm}->{latest}++;
191 }
192 tagpkg($cmp, 'inuse') if $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'base') || rprop($cmp, 'builds');
193 }
194 next if $pkg->{srpm} && $pkg->{srpm}->{rpm} eq $pkg->{rpm};
195
196 my $src = $pkg->{rpm}->sourcerpm;
197 my $source = basename $cmp->{rpm}->filename;
198 SRC: {
199 $src eq $source && last SRC;
200 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.at(\.src)}{$1} && $src eq $source && last SRC;
201 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.rf\.src)}{$1} && $src eq $source && last SRC;
202 ($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d(\.rf\.src)}{$1$2} && $src eq $source && last SRC;
203 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.rf(\.src)}{.dag$1} && $src eq $source && last SRC;
204 ($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d\.rf(\.src)}{$1.dag$2} && $src eq $source && last SRC;
205 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.src)}{$1} && $src eq $source && last SRC;
206 ($src = $pkg->{rpm}->sourcerpm) =~ s{(-\d+)\.\d+\.el\d(\.src)}{$1$2} && $src eq $source && last SRC;
207 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.centos\d(\.src)}{$1} && $src eq $source && last SRC;
208 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.sme(\.src)}{$1} && $src eq $source && last SRC;
209 $src = '';
210 }
211 if ( $src eq $source && ( ! $pkg->{srpm} || $pkg->{srpm}->{rpm} eq $cmp->{rpm} ) ) {
212 if ( ! $pkg->{srpm} || $pkg->{repo} eq $cmp->{repo} ) {
213 delete $pkg->{srpm}->{latest} if $pkg->{latest} && $pkg->{srpm} && $pkg->{srpm}->{latest};
214 $pkg->{srpm} = $cmp;
215 $pkg->{srpm}->{latest}++ if $pkg->{latest};
216 }
217 if ( $pkg->{latest} && rprop($cmp, 'stage') ) {
218 tagpkg($cmp, 'inuse');
219 $pkg->{srpm}->{latest}++;
220 }
221 tagpkg($cmp, 'inuse') if $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'base') || rprop($cmp, 'builds');
222 }
223 }
224 } elsif ( $cmp->{rpm} eq $pkg->{rpm} ) {
225 if ( $names{$cmp->{name}} ) {
226 if ( $pkg->{repo} eq $cmp->{repo} ) {
227 tagpkg($cmp, 'correct', 1);
228 $seen{$cmp->{nvra}}++;
229 } elsif ( $seen{$cmp->{nvra}} && rprop($cmp, 'stage') && $pkg->{latest} ) {
230 $_->{latest}++ foreach grep { $_->{nvra} eq $cmp->{nvra} && $_->{latest} && $_->{done} } @pkgs;
231 tagpkg($cmp, 'correct', 1);
232 } elsif ( $seen{$cmp->{nvra}} ) {
233 $orig++ if rprop($cmp, 'base') || rprop($cmp, 'builds');
234 movepkg($cmp, 'delete', 1);
235 } else {
236 movepkg($cmp, $pkg->{repo}, 1, 1);
237 $seen{$cmp->{nvra}}++;
238 }
239 } else {
240 tagpkg($cmp, 'nonbase');
241 }
242 } elsif ( rprop($cmp, 'prio') < rprop($pkg, 'prio') ) {
243 tagpkg($cmp, 'obsolete');
244 }
245 }
246 printline('dark blue', 1, ' - checking source packages') if $opts{d};
247 if ( ! $pkg->{srpm} ) {
248 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (missing source ', $pkg->{rpm}->sourcerpm, ')');
249 } elsif ( $pkg->{srpm}->{repo} ne $pkg->{repo} ) {
250 movepkg($pkg->{srpm}, $pkg->{repo}, 0);
251 }
252 unless ( $orig ) {
253 foreach ( grep { $_->{base} eq $pkg->{base} && $_->{repo} eq $pkg->{repo} } @pkgs ) {
254 printline('bold yellow on_red', 1, ' - ', $_->{rpm}->filename, ' (missing original)');
255 }
256 }
257 }
258 printline('bold black', 1, ' - arch count check') if $opts{d};
259 foreach my $r ( keys %$archs ) {
260 foreach my $p ( keys %{$archs->{$r}} ) {
261 foreach my $a ( keys %{$archs->{$r}->{$p}} ) {
262 my $p2 = ${$archs->{$r}->{$p}->{$a}}[0];
263 if ( $a eq 'noarch' ) {
264 movepkg($p2, $p2->{repo}, 0) if ! $p2->{repos} && scalar @{$archs->{$r}->{$p}->{$a}} != scalar @archs;
265 } elsif ( scalar @{$archs->{$r}->{$p}->{$a}} != 1 ) {
266 printline('bold yellow on_red', 1, ' - ', $p2->{rpm}->filename, ' (many arch)');
267 }
268 }
269 }
270 }
271
272 printline('bold black', 1, ' - missing stage packages') if $opts{d};
273 movepkg($_, $stage, 0) foreach grep { $_->{latest} && $_->{latest} == 1 } @pkgs;
274
275 printline('bold black', 1, ' - obsolete packages') if $opts{d};
276 movepkg($_, 'delete') foreach grep { ! rprop($_, 'base') && ! $_->{done} && ( $_->{obsolete} || ( $_->{rpm}->is_source_package && ! $_->{inuse} ) ) } @pkgs;
277 }
278 printline('white', 0, "Finished processing.\n");
279
280 unless ( $opts{t} || $opts{r} ) {
281 my %repochg = ();
282 # Move / Copy / Delete packages and tag repo for rebuild.
283 foreach my $pkg ( grep { $_->{oldrepo} } @rpms ) {
284 printline('white', 0, 'Copy/move: ', $pkg->{rpm}->filename);
285 my $src = $pkg->{rpm}->filename;
286
287 qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null) if $pkg->{nosig};
288 if ( $pkg->{repos} ) {
289 foreach my $dest ( dest($pkg, @{$pkg->{repos}}) ) {
290 qx(cp --preserve=timestamps $src $dest) unless -f "$dest";
291 }
292 $repochg{$_}++ foreach @{$pkg->{repos}};
293 }
294 if ( $pkg->{remove} ) {
295 qx(rm -f $src);
296 $repochg{$pkg->{oldrepo}}++;
297 }
298 }
299 finddepth(sub{rmdir}, $distrepo->{$rel}->{builds});
300 printline('white', 0, "Finished copying/moving.\n");
301
302 foreach my $repo ( sort keys %repochg ) {
303 next if ! $repos->{$repo} || $repos->{$repo}->{base} || $repos->{$repo}->{builds} || $repos->{$repo}->{stage};
304 foreach my $arch ( @archs ) {
305 my $dir = $distrepo->{$rel}->{repo} . "$repo/$arch";
306 $dir = qx(readlink -f $dir);
307 chomp $dir;
308 printline('white', 0, "Createrepo: $repo/$arch");
309 qx(createrepo $dir);
310 printline('white', 0, "Repoview: $repo/$arch");
311 qx(repoview $dir);
312 qx(rm -rf $dir/.olddata) if -d "$dir/.olddata";
313 qx(rm -rf $dir/.repodata) if -d "$dir/.repodata";
314 }
315 }
316 printline('white', 0, "Finished rebuilding repos.\n");
317 }
318
319 print "\n================================================================================\n\n";
320 }
321
322 sub pkgsrt {
323 return $a->{rpm}->is_source_package <=> $b->{rpm}->is_source_package || $b->{rpm} cmp $a->{rpm} || rprop($b, 'prio') <=> rprop($a, 'prio');
324 }
325
326 sub rprop {
327 my ($pkg, $prop) = @_;
328 return $repos->{$pkg->{repo}} ? $repos->{$pkg->{repo}}->{$prop} : 0;
329 }
330
331 sub names {
332 my $pkg = shift;
333 my @rpms = @_;
334 return map { $_->{name} => rprop($_, 'inc') ? 2 : 1 } grep { $_->{base} eq $pkg->{base} &&
335 rprop($_, 'prio') >= rprop($pkg, 'prio') &&
336 ! rprop($_, 'base') &&
337 ! rprop($_, 'builds') &&
338 ! $_->{rpm}->is_source_package
339 } @rpms;
340 }
341
342 sub dest {
343 my ($pkg, @repos) = @_;
344 my @d = ();
345 foreach my $repo ( @repos ) {
346 my $base = $distrepo->{$rel}->{repo} . $repo;
347 $base = $distrepo->{$rel}->{stage} if $repos->{$repo}->{stage};
348 if ( $pkg->{arch} eq 'noarch' ) {
349 push @d, "$base/i386/" .
350 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
351 basename $pkg->{rpm}->filename;
352 push @d, "$base/x86_64/" .
353 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
354 basename $pkg->{rpm}->filename;
355 } elsif ( $pkg->{arch} =~ m{^(i[356]86)$} ) {
356 push @d, "$base/i386/" .
357 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
358 basename $pkg->{rpm}->filename;
359 } elsif ( $pkg->{arch} eq 'x86_64' ) {
360 push @d, "$base/x86_64/" .
361 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
362 basename $pkg->{rpm}->filename;
363 } elsif ( $pkg->{arch} eq 'zsrc' ) {
364 push @d, "$base/SRPMS/" .
365 basename $pkg->{rpm}->filename;
366 } else {
367 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (bad arch: ', $pkg->{arch}, ')');
368 }
369 }
370 return @d;
371 }
372
373 sub movepkg {
374 my ($pkg, $repo, $done, $remove) = @_;
375 defined $done or $done = 2;
376 defined $remove or $remove = 0;
377 $remove = 0 if rprop($pkg, 'base') || rprop($pkg, 'builds');
378 $remove = 1 if $repo eq 'delete';
379
380 if ( $repo eq 'delete' && ( rprop($pkg, 'base') || ( rprop($pkg, 'builds') && $done == 1 ) ) ) {
381 tagpkg($pkg, 'inuse', 1);
382 } else {
383 printline('bold magenta', 1, " - ($repo) ", $pkg->{rpm}->filename) if $opts{d};
384 my $color = 'bold white';
385 $color = 'bold yellow' if rprop($pkg, 'builds');
386 $color = 'dark green' if $repos->{$repo} && $repos->{$repo}->{devel};
387 $color = 'dark red' if $repo eq 'delete';
388 push @{$pkg->{repos}}, $repo unless $repo eq 'delete';
389 $pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo};
390 $pkg->{repo} = $repo;
391 $pkg->{remove}++ if $remove;
392 printline($color, 1, ' - ', $pkg->{rpm}->filename, ' (', $pkg->{oldrepo}, " to $repo)") if $opts{v} || $opts{d};
393 done($pkg) if $done;
394 }
395 }
396
397 sub tagpkg {
398 my ($pkg, $tag, $done) = @_;
399 defined $done or $done = 0;
400
401 printline('bold magenta', 1, " - ($tag) ", $pkg->{rpm}->filename) if $opts{d};
402 delete $pkg->{obsolete} if $pkg->{obsolete};
403 $pkg->{$tag}++;
404 done($pkg) if $done;
405 }
406
407 sub done {
408 my $pkg = shift;
409 printline('bold yellow on_red', 1, " - ", $pkg->{rpm}->filename, " (already processed)") if $pkg->{done};
410 $pkg->{done}++;
411 delete $pkg->{obsolete} if $pkg->{obsolete};
412
413 if ( $repos->{$pkg->{repo}} && ! rprop($pkg, 'base') && ! rprop($pkg, 'builds') ) {
414 # FIXME: Nasty hack for comps package
415 if ( $pkg->{name} eq 'comps' ) {
416 if ( ! $latest{$pkg->{name}.'.'.$pkg->{arch}} || $latest{$pkg->{name}.'.'.$pkg->{arch}}->{rpm} eq $pkg->{rpm} ) {
417 if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) {
418 $latest{$pkg->{name}.'.'.$pkg->{arch}} = $pkg if ! $latest{$pkg->{name}.'.'.$pkg->{arch}};
419 $pkg->{latest}++;
420 }
421 }
422 } elsif ( ! $latest{$pkg->{name}} || $latest{$pkg->{name}}->{rpm} eq $pkg->{rpm} ) {
423 if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) {
424 $latest{$pkg->{name}} = $pkg if ! $latest{$pkg->{name}};
425 $pkg->{latest}++;
426 }
427 }
428 unless ( $pkg->{oldrepo} ) {
429 my $goodarch = 0;
430 $goodarch++ if $pkg->{rpm}->filename =~ m{/(i386|x86_64)/.*\.noarch\.rpm$};
431 $goodarch++ if $pkg->{rpm}->filename =~ m{/i386/.*\.(i[56]86)\.rpm$};
432 $goodarch++ if $pkg->{rpm}->filename =~ m{/(noarch|i[356]86|x86_64)/.*\.\1\.rpm$};
433 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (wrong arch)') unless $goodarch;
434 }
435 push @{$archs->{$pkg->{repo}}->{$pkg->{rpm}->as_nvre}->{$pkg->{rpm}->is_source_package ? 'src' : $pkg->{rpm}->arch}}, $pkg;
436 }
437 }
438
439 sub printline {
440 my $color = shift;
441 my $nline = shift;
442 my $string = join '', @_;
443
444 if ( $nline ) {
445 print "\n" unless $newline;
446 $newline++;
447 } else {
448 $newline = 0;
449 print "\r\e[0K";
450 }
451 print color $color;
452 print $string;
453 print color 'reset';
454 print "\n" if $nline;
455 }
456
457 sub loadpkg {
458 printline('white', 0, "Loading: $_") if -d _;
459 return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ( ! $opts{r} || $1 =~ m{$opts{r}} );
460
461 my $pkg;
462 eval { $pkg = RPM2->open_package($_, $rpm_flags); };
463 if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; }
464 eval { my $sig = $pkg->siggpg };
465 my $nosig = ! $@;
466 if ( $nosig && ! -f "$HOME/.rpmpass" ) {
467 printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)');
468 return;
469 }
470
471 my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm};
472 foreach my $repo ( keys %{$skippkg->{$rel}} ) { return if (dirname $pkg->filename) =~ m{/$repo/} && grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}}; }
473 my $reponame = 'unknown';
474 if ( substr($_, 0, length($distrepo->{$rel}->{builds})) eq $distrepo->{$rel}->{builds} ) {
475 $reponame = 'builds';
476 } elsif ( substr($_, 0, length($distrepo->{$rel}->{stage})) eq $distrepo->{$rel}->{stage} ) {
477 $reponame = 'stage';
478 } elsif ( (dirname $pkg->filename) =~ m{\d/(sme[^/]+)/} ) {
479 $reponame = $1;
480 }
481
482 push @rpms, { base => $srcname,
483 name => $pkg->name,
484 repo => $reponame,
485 nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ),
486 arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'),
487 version => $version,
488 release => $release,
489 rpm => $pkg,
490 nosig => $nosig,
491 };
492 $sources{$srcname}++;
493 if ( ! $pkg->is_source_package && ! $repos->{$reponame}->{stage} ) {
494 $latest{$pkg->name} = $rpms[$#rpms] if ! $latest{$pkg->name} || $pkg gt $latest{$pkg->name}->{rpm};
495 }
496 }
497
498 sub loadbase {
499 printline('white', 0, "Loading: $_") if -d _;
500 return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ($latest{$1} || $sources{$1});
501
502 my $pkg;
503 eval { $pkg = RPM2->open_package($_, $rpm_flags); };
504 if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; }
505 eval { my $sig = $pkg->siggpg };
506 unless ($@) { printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)'); return; }
507
508 my $cmp = $latest{$pkg->name};
509 my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm};
510 my $pkgrepo = 'base';
511 foreach my $repo ( keys %{$skippkg->{$rel}} ) {
512 if ( (dirname $pkg->filename) =~ m{/$repo/} ) {
513 return if grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}};
514 $pkgrepo = $repo;
515 return unless $pkg->is_source_package || $cmp;
516 return if ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && rprop($cmp, 'base') && rprop($cmp, 'prio') > $repos->{$pkgrepo}->{prio};
517 last;
518 }
519 }
520
521 push @rpms, { base => $srcname,
522 name => $pkg->name,
523 repo => $pkgrepo,
524 nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ),
525 arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'),
526 version => $version,
527 release => $release,
528 rpm => $pkg,
529 nosig => 0,
530 };
531 if ( ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && ( $repos->{$pkgrepo}->{prio} >= rprop($cmp, 'prio') || ! rprop($cmp, 'base') ) ) {
532 $latest{$pkg->name} = $rpms[$#rpms];
533 }
534 }
535

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