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