/[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.26 - (show annotations) (download)
Thu Nov 8 17:12:31 2007 UTC (17 years ago) by slords
Branch: MAIN
Changes since 1.25: +8 -7 lines
Fixes for src pkgs and unsigned pkgs

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 if ( $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'base') || rprop($cmp, 'builds') || ( $cmp->{oldrepo} && $pkg->{repo} eq $cmp->{oldrepo} ) ) {
193 tagpkg($cmp, 'inuse')
194 }
195 }
196 next if $pkg->{srpm} && $pkg->{srpm}->{rpm} eq $pkg->{rpm};
197
198 my $src = $pkg->{rpm}->sourcerpm;
199 my $source = basename $cmp->{rpm}->filename;
200 SRC: {
201 $src eq $source && last SRC;
202 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.at(\.src)}{$1} && $src eq $source && last SRC;
203 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.rf\.src)}{$1} && $src eq $source && last SRC;
204 ($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d(\.rf\.src)}{$1$2} && $src eq $source && last SRC;
205 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.rf(\.src)}{.dag$1} && $src eq $source && last SRC;
206 ($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d\.rf(\.src)}{$1.dag$2} && $src eq $source && last SRC;
207 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.src)}{$1} && $src eq $source && last SRC;
208 ($src = $pkg->{rpm}->sourcerpm) =~ s{(-\d+)\.\d+\.el\d(\.src)}{$1$2} && $src eq $source && last SRC;
209 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.centos\d(\.src)}{$1} && $src eq $source && last SRC;
210 ($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.sme(\.src)}{$1} && $src eq $source && last SRC;
211 $src = '';
212 }
213 if ( $src eq $source && ( ! $pkg->{srpm} || $pkg->{srpm}->{rpm} eq $cmp->{rpm} ) ) {
214 if ( ! $pkg->{srpm} || $pkg->{repo} eq $cmp->{repo} ) {
215 delete $pkg->{srpm}->{latest} if $pkg->{latest} && $pkg->{srpm} && $pkg->{srpm}->{latest};
216 $pkg->{srpm} = $cmp;
217 $pkg->{srpm}->{latest}++ if $pkg->{latest};
218 }
219 if ( $pkg->{latest} && rprop($cmp, 'stage') ) {
220 tagpkg($cmp, 'inuse');
221 $pkg->{srpm}->{latest}++;
222 }
223 tagpkg($cmp, 'inuse') if $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'base') || rprop($cmp, 'builds');
224 }
225 }
226 } elsif ( $cmp->{rpm} eq $pkg->{rpm} ) {
227 if ( $names{$cmp->{name}} ) {
228 if ( $pkg->{repo} eq $cmp->{repo} ) {
229 tagpkg($cmp, 'correct', 1);
230 $seen{$cmp->{nvra}}++;
231 } elsif ( $seen{$cmp->{nvra}} && rprop($cmp, 'stage') && $pkg->{latest} ) {
232 $_->{latest}++ foreach grep { $_->{nvra} eq $cmp->{nvra} && $_->{latest} && $_->{done} } @pkgs;
233 tagpkg($cmp, 'correct', 1);
234 } elsif ( $seen{$cmp->{nvra}} ) {
235 $orig++ if rprop($cmp, 'base') || rprop($cmp, 'builds');
236 movepkg($cmp, 'delete', 1);
237 } else {
238 movepkg($cmp, $pkg->{repo}, 1, 1);
239 $seen{$cmp->{nvra}}++;
240 }
241 } else {
242 tagpkg($cmp, 'nonbase');
243 }
244 } elsif ( rprop($cmp, 'prio') < rprop($pkg, 'prio') ) {
245 tagpkg($cmp, 'obsolete');
246 }
247 }
248 printline('dark blue', 1, ' - checking source packages') if $opts{d};
249 if ( ! $pkg->{srpm} ) {
250 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (missing source ', $pkg->{rpm}->sourcerpm, ')');
251 } elsif ( $pkg->{srpm}->{repo} ne $pkg->{repo} && ( ! $pkg->{srpm}->{oldrepo} || $pkg->{srpm}->{oldrepo} ne $pkg->{repo} ) ) {
252 movepkg($pkg->{srpm}, $pkg->{repo}, 0);
253 }
254 unless ( $orig ) {
255 foreach ( grep { $_->{base} eq $pkg->{base} && $_->{repo} eq $pkg->{repo} } @pkgs ) {
256 printline('bold yellow on_red', 1, ' - ', $_->{rpm}->filename, ' (missing original)');
257 }
258 }
259 }
260 printline('bold black', 1, ' - arch count check') if $opts{d};
261 foreach my $r ( keys %$archs ) {
262 foreach my $p ( keys %{$archs->{$r}} ) {
263 foreach my $a ( keys %{$archs->{$r}->{$p}} ) {
264 my $p2 = ${$archs->{$r}->{$p}->{$a}}[0];
265 if ( $a eq 'noarch' ) {
266 movepkg($p2, $p2->{repo}, 0) if ! $p2->{repos} && scalar @{$archs->{$r}->{$p}->{$a}} != scalar @archs;
267 } elsif ( scalar @{$archs->{$r}->{$p}->{$a}} != 1 ) {
268 printline('bold yellow on_red', 1, ' - ', $p2->{rpm}->filename, ' (many arch)');
269 }
270 }
271 }
272 }
273
274 printline('bold black', 1, ' - missing stage packages') if $opts{d};
275 movepkg($_, $stage, 0) foreach grep { $_->{latest} && $_->{latest} == 1 } @pkgs;
276
277 printline('bold black', 1, ' - obsolete packages') if $opts{d};
278 movepkg($_, 'delete') foreach grep { ! rprop($_, 'base') && ! $_->{done} && ( $_->{obsolete} || ( $_->{rpm}->is_source_package && ! $_->{inuse} ) ) } @pkgs;
279 }
280 printline('white', 0, "Finished processing.\n");
281
282 unless ( $opts{t} || $opts{r} ) {
283 my %repochg = ();
284 # Move / Copy / Delete packages and tag repo for rebuild.
285 foreach my $pkg ( grep { $_->{oldrepo} } @rpms ) {
286 printline('white', 0, 'Copy/move: ', $pkg->{rpm}->filename);
287 my $src = $pkg->{rpm}->filename;
288
289 qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null) if $pkg->{nosig};
290 if ( $pkg->{repos} ) {
291 foreach my $dest ( dest($pkg, @{$pkg->{repos}}) ) {
292 qx(cp --preserve=timestamps $src $dest) unless -f "$dest";
293 }
294 $repochg{$_}++ foreach @{$pkg->{repos}};
295 }
296 if ( $pkg->{remove} ) {
297 qx(rm -f $src);
298 $repochg{$pkg->{oldrepo}}++;
299 }
300 }
301 finddepth(sub{rmdir}, $distrepo->{$rel}->{builds});
302 printline('white', 0, "Finished copying/moving.\n");
303
304 foreach my $repo ( sort keys %repochg ) {
305 next if ! $repos->{$repo} || $repos->{$repo}->{base} || $repos->{$repo}->{builds} || $repos->{$repo}->{stage};
306 foreach my $arch ( @archs ) {
307 my $dir = $distrepo->{$rel}->{repo} . "$repo/$arch";
308 $dir = qx(readlink -f $dir);
309 chomp $dir;
310 printline('white', 0, "Createrepo: $repo/$arch");
311 qx(createrepo $dir);
312 printline('white', 0, "Repoview: $repo/$arch");
313 qx(repoview $dir);
314 qx(rm -rf $dir/.olddata) if -d "$dir/.olddata";
315 qx(rm -rf $dir/.repodata) if -d "$dir/.repodata";
316 }
317 }
318 printline('white', 0, "Finished rebuilding repos.\n");
319 }
320
321 print "\n================================================================================\n\n";
322 }
323
324 sub pkgsrt {
325 return $a->{rpm}->is_source_package <=> $b->{rpm}->is_source_package || $b->{rpm} cmp $a->{rpm} || rprop($b, 'prio') <=> rprop($a, 'prio');
326 }
327
328 sub rprop {
329 my ($pkg, $prop) = @_;
330 return $repos->{$pkg->{repo}} ? $repos->{$pkg->{repo}}->{$prop} : 0;
331 }
332
333 sub names {
334 my $pkg = shift;
335 my @rpms = @_;
336 return map { $_->{name} => rprop($_, 'inc') ? 2 : 1 } grep { $_->{base} eq $pkg->{base} &&
337 rprop($_, 'prio') >= rprop($pkg, 'prio') &&
338 ! rprop($_, 'base') &&
339 ! rprop($_, 'builds') &&
340 ! $_->{rpm}->is_source_package
341 } @rpms;
342 }
343
344 sub dest {
345 my ($pkg, @repos) = @_;
346 my @d = ();
347 foreach my $repo ( @repos ) {
348 my $base = $distrepo->{$rel}->{repo} . $repo;
349 $base = $distrepo->{$rel}->{stage} if $repos->{$repo}->{stage};
350 if ( $pkg->{arch} eq 'noarch' ) {
351 push @d, "$base/i386/" .
352 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
353 basename $pkg->{rpm}->filename;
354 push @d, "$base/x86_64/" .
355 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
356 basename $pkg->{rpm}->filename;
357 } elsif ( $pkg->{arch} =~ m{^(i[356]86)$} ) {
358 push @d, "$base/i386/" .
359 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
360 basename $pkg->{rpm}->filename;
361 } elsif ( $pkg->{arch} eq 'x86_64' ) {
362 push @d, "$base/x86_64/" .
363 ( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) .
364 basename $pkg->{rpm}->filename;
365 } elsif ( $pkg->{arch} eq 'zsrc' ) {
366 push @d, "$base/SRPMS/" .
367 basename $pkg->{rpm}->filename;
368 } else {
369 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (bad arch: ', $pkg->{arch}, ')');
370 }
371 }
372 return @d;
373 }
374
375 sub movepkg {
376 my ($pkg, $repo, $done, $remove) = @_;
377 defined $done or $done = 2;
378 defined $remove or $remove = 0;
379 $remove = 0 if rprop($pkg, 'base') || rprop($pkg, 'builds');
380 $remove = 1 if $repo eq 'delete';
381
382 if ( $repo eq 'delete' && ( rprop($pkg, 'base') || ( rprop($pkg, 'builds') && $done == 1 ) ) ) {
383 tagpkg($pkg, 'inuse', 1);
384 } else {
385 printline('bold magenta', 1, " - ($repo) ", $pkg->{rpm}->filename) if $opts{d};
386 my $color = 'bold white';
387 $color = 'bold yellow' if rprop($pkg, 'builds');
388 $color = 'dark green' if $repos->{$repo} && $repos->{$repo}->{devel};
389 $color = 'dark red' if $repo eq 'delete';
390 push @{$pkg->{repos}}, $repo unless $repo eq 'delete';
391 $pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo};
392 $pkg->{repo} = $repo;
393 $pkg->{remove}++ if $remove;
394 printline($color, 1, ' - ', $pkg->{rpm}->filename, ' (', $pkg->{oldrepo}, " to $repo)") if $opts{v} || $opts{d};
395 done($pkg) if $done;
396 }
397 }
398
399 sub tagpkg {
400 my ($pkg, $tag, $done) = @_;
401 defined $done or $done = 0;
402
403 printline('bold magenta', 1, " - ($tag) ", $pkg->{rpm}->filename) if $opts{d};
404 delete $pkg->{obsolete} if $pkg->{obsolete};
405 $pkg->{$tag}++;
406 done($pkg) if $done;
407 }
408
409 sub done {
410 my $pkg = shift;
411 printline('bold yellow on_red', 1, " - ", $pkg->{rpm}->filename, " (already processed)") if $pkg->{done};
412 $pkg->{done}++;
413 delete $pkg->{obsolete} if $pkg->{obsolete};
414
415 if ( $repos->{$pkg->{repo}} && ! rprop($pkg, 'base') && ! rprop($pkg, 'builds') ) {
416 # FIXME: Nasty hack for comps package
417 if ( $pkg->{name} eq 'comps' ) {
418 if ( ! $latest{$pkg->{name}.'.'.$pkg->{arch}} || $latest{$pkg->{name}.'.'.$pkg->{arch}}->{rpm} eq $pkg->{rpm} ) {
419 if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) {
420 $latest{$pkg->{name}.'.'.$pkg->{arch}} = $pkg if ! $latest{$pkg->{name}.'.'.$pkg->{arch}};
421 $pkg->{latest}++;
422 }
423 }
424 } elsif ( ! $latest{$pkg->{name}} || $latest{$pkg->{name}}->{rpm} eq $pkg->{rpm} ) {
425 if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) {
426 $latest{$pkg->{name}} = $pkg if ! $latest{$pkg->{name}};
427 $pkg->{latest}++;
428 }
429 }
430 unless ( $pkg->{oldrepo} ) {
431 my $goodarch = 0;
432 $goodarch++ if $pkg->{rpm}->filename =~ m{/(i386|x86_64)/.*\.noarch\.rpm$};
433 $goodarch++ if $pkg->{rpm}->filename =~ m{/i386/.*\.(i[56]86)\.rpm$};
434 $goodarch++ if $pkg->{rpm}->filename =~ m{/(noarch|i[356]86|x86_64)/.*\.\1\.rpm$};
435 printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (wrong arch)') unless $goodarch;
436 }
437 push @{$archs->{$pkg->{repo}}->{$pkg->{rpm}->as_nvre}->{$pkg->{rpm}->is_source_package ? 'src' : $pkg->{rpm}->arch}}, $pkg;
438 }
439 }
440
441 sub printline {
442 my $color = shift;
443 my $nline = shift;
444 my $string = join '', @_;
445
446 if ( $nline ) {
447 print "\n" unless $newline;
448 $newline++;
449 } else {
450 $newline = 0;
451 print "\r\e[0K";
452 }
453 print color $color;
454 print $string;
455 print color 'reset';
456 print "\n" if $nline;
457 }
458
459 sub loadpkg {
460 printline('white', 0, "Loading: $_") if -d _;
461 return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ( ! $opts{r} || $1 =~ m{$opts{r}} );
462
463 my $pkg;
464 eval { $pkg = RPM2->open_package($_, $rpm_flags); };
465 if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; }
466 eval { my $sig = $pkg->siggpg };
467 my $nosig = ! $@;
468
469 my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm};
470 foreach my $repo ( keys %{$skippkg->{$rel}} ) { return if (dirname $pkg->filename) =~ m{/$repo/} && grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}}; }
471 my $reponame = 'unknown';
472 if ( substr($_, 0, length($distrepo->{$rel}->{builds})) eq $distrepo->{$rel}->{builds} ) {
473 $reponame = 'builds';
474 } elsif ( substr($_, 0, length($distrepo->{$rel}->{stage})) eq $distrepo->{$rel}->{stage} ) {
475 $reponame = 'stage';
476 } elsif ( (dirname $pkg->filename) =~ m{\d/(sme[^/]+)/} ) {
477 $reponame = $1;
478 }
479 if ( $nosig && ( ! -f "$HOME/.rpmpass" || $reponame eq 'builds' ) ) {
480 printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)');
481 return;
482 }
483 push @rpms, { base => $srcname,
484 name => $pkg->name,
485 repo => $reponame,
486 nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ),
487 arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'),
488 version => $version,
489 release => $release,
490 rpm => $pkg,
491 nosig => $nosig,
492 };
493 $sources{$srcname}++;
494 if ( ! $pkg->is_source_package && ! $repos->{$reponame}->{stage} ) {
495 $latest{$pkg->name} = $rpms[$#rpms] if ! $latest{$pkg->name} || $pkg gt $latest{$pkg->name}->{rpm};
496 }
497 }
498
499 sub loadbase {
500 printline('white', 0, "Loading: $_") if -d _;
501 return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ($latest{$1} || $sources{$1});
502
503 my $pkg;
504 eval { $pkg = RPM2->open_package($_, $rpm_flags); };
505 if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; }
506 eval { my $sig = $pkg->siggpg };
507 unless ($@) { printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)'); return; }
508
509 my $cmp = $latest{$pkg->name};
510 my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm};
511 my $pkgrepo = 'base';
512 foreach my $repo ( keys %{$skippkg->{$rel}} ) {
513 if ( (dirname $pkg->filename) =~ m{/$repo/} ) {
514 return if grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}};
515 $pkgrepo = $repo;
516 return unless $pkg->is_source_package || $cmp;
517 return if ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && rprop($cmp, 'base') && rprop($cmp, 'prio') > $repos->{$pkgrepo}->{prio};
518 last;
519 }
520 }
521
522 push @rpms, { base => $srcname,
523 name => $pkg->name,
524 repo => $pkgrepo,
525 nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ),
526 arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'),
527 version => $version,
528 release => $release,
529 rpm => $pkg,
530 nosig => 0,
531 };
532 if ( ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && ( $repos->{$pkgrepo}->{prio} >= rprop($cmp, 'prio') || ! rprop($cmp, 'base') ) ) {
533 $latest{$pkg->name} = $rpms[$#rpms];
534 }
535 }
536

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