/[smeserver]/builds_bin/update_repos
ViewVC logotype

Annotation of /builds_bin/update_repos

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


Revision 1.29 - (hide annotations) (download)
Fri Nov 23 16:45:36 2007 UTC (17 years ago) by slords
Branch: MAIN
Changes since 1.28: +10 -9 lines
updates

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

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