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 => 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 |
'smecontribs' => { prio => 13, inc => 0, ver => 1, rel => 2, contribs => 1 }, |
30 |
'smetest' => { prio => 12, inc => 0, ver => 2, rel => 2, devel => 2 }, |
31 |
'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 |
'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 }, |
42 |
}; |
43 |
|
44 |
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 |
}, |
53 |
'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 |
}, |
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 |
my ($contribs) = sort { $repos->{$a}->{contribs} <=> $repos->{$b}->{contribs} } grep { $repos->{$_}->{contribs} } keys %$repos; |
95 |
my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos; |
96 |
|
97 |
my ($rel, @rpms, %latest, %sources, $archs, $rebuild, $newline); |
98 |
foreach my $smever ( sort { $a <=> $b } grep { $distrepo->{$_}->{active} } keys %$distrepo ) { |
99 |
$rel = $smever; |
100 |
%latest = (); |
101 |
%sources = (); |
102 |
@rpms = (); |
103 |
$rebuild = (); |
104 |
|
105 |
# Load distro packages |
106 |
find( { wanted => \&loadpkg, no_chdir => 1, follow_fast => 1 }, map { $distrepo->{$smever}->{$_} } ('repo','builds','contribs','stage') ); |
107 |
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 |
%latest = (); |
127 |
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 |
next if $pkg->{done} || $pkg->{obsolete} || $pkg->{rpm}->is_source_package || ! $repos->{$pkg->{repo}}; |
136 |
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 |
# Stage packages should never be most current |
143 |
if ( rprop($pkg, 'stage') ) { |
144 |
printline('dark blue', 1, ' - checking stage') if $opts{d}; |
145 |
tagpkg($pkg, 'obsolete'); |
146 |
next; |
147 |
} |
148 |
|
149 |
# Move packages from base/builds to correct area |
150 |
elsif ( rprop($pkg, 'orig') ) { |
151 |
printline('dark blue', 1, ' - checking base/builds/contribs') if $opts{d}; |
152 |
my $repo = $names{$pkg->{name}} > 1 ? $devel2 : $devel1; |
153 |
$repo = $contribs if $pkg->{repo} eq 'contribs'; |
154 |
if ( $pkg->{nonbase} ) { |
155 |
foreach my $up ( @pkgs ) { |
156 |
next if rprop($up, 'orig'); |
157 |
next if $up->{name} ne $pkg->{name} || ! $up->{obsolete} || $up->{rpm} ge $pkg->{rpm}; |
158 |
$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 |
|
182 |
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 |
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 |
if ( $pkg->{repo} eq $cmp->{repo} || ( $cmp->{oldrepo} && $pkg->{repo} eq $cmp->{oldrepo} ) || rprop($cmp, 'orig') ) { |
197 |
tagpkg($cmp, 'inuse') |
198 |
} |
199 |
} |
200 |
next if $pkg->{srpm} && $pkg->{srpm}->{rpm} eq $pkg->{rpm}; |
201 |
|
202 |
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 |
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 |
tagpkg($cmp, 'inuse') if $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'orig'); |
228 |
} |
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 |
} 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 |
} elsif ( $seen{$cmp->{nvra}} ) { |
239 |
$orig++ if rprop($cmp, 'orig'); |
240 |
movepkg($cmp, 'delete', 1); |
241 |
} else { |
242 |
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 |
} |
247 |
} else { |
248 |
tagpkg($cmp, 'nonbase'); |
249 |
} |
250 |
} elsif ( rprop($cmp, 'prio') < rprop($pkg, 'prio') ) { |
251 |
tagpkg($cmp, 'obsolete'); |
252 |
} |
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 |
} elsif ( $pkg->{srpm}->{repo} ne $pkg->{repo} && ( ! $pkg->{srpm}->{oldrepo} || $pkg->{srpm}->{oldrepo} ne $pkg->{repo} ) ) { |
258 |
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 |
|
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 |
} |
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 |
qx(cp --preserve=timestamps $src $dest) unless -f "$dest"; |
299 |
} |
300 |
$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 |
finddepth(sub{rmdir}, $distrepo->{$rel}->{contribs}); |
309 |
printline('white', 0, "Finished copying/moving.\n"); |
310 |
|
311 |
foreach my $repo ( sort keys %repochg ) { |
312 |
next if ! $repos->{$repo} || $repos->{$repo}->{orig} || $repos->{$repo}->{stage}; |
313 |
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 |
} |
325 |
printline('white', 0, "Finished rebuilding repos.\n"); |
326 |
} |
327 |
|
328 |
print "\n================================================================================\n\n"; |
329 |
} |
330 |
|
331 |
sub pkgsrt { |
332 |
return $a->{rpm}->is_source_package <=> $b->{rpm}->is_source_package || $b->{rpm} cmp $a->{rpm} || rprop($b, 'prio') <=> rprop($a, 'prio'); |
333 |
} |
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 |
! rprop($_, 'orig') && |
346 |
! $_->{rpm}->is_source_package |
347 |
} @rpms; |
348 |
} |
349 |
|
350 |
sub dest { |
351 |
my ($pkg, @repos) = @_; |
352 |
my @d = (); |
353 |
foreach my $repo ( @repos ) { |
354 |
my $base = $distrepo->{$rel}->{repo} . $repo; |
355 |
$base = $distrepo->{$rel}->{stage} if $repos->{$repo}->{stage}; |
356 |
if ( $pkg->{arch} eq 'noarch' ) { |
357 |
push @d, "$base/i386/" . |
358 |
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
359 |
basename $pkg->{rpm}->filename; |
360 |
push @d, "$base/x86_64/" . |
361 |
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
362 |
basename $pkg->{rpm}->filename; |
363 |
} elsif ( $pkg->{arch} =~ m{^(i[356]86)$} ) { |
364 |
push @d, "$base/i386/" . |
365 |
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
366 |
basename $pkg->{rpm}->filename; |
367 |
} elsif ( $pkg->{arch} eq 'x86_64' ) { |
368 |
push @d, "$base/x86_64/" . |
369 |
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
370 |
basename $pkg->{rpm}->filename; |
371 |
} elsif ( $pkg->{arch} eq 'zsrc' ) { |
372 |
push @d, "$base/SRPMS/" . |
373 |
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 |
$remove = 0 if rprop($pkg, 'orig'); |
386 |
$remove = 1 if $repo eq 'delete'; |
387 |
|
388 |
if ( $repo eq 'delete' && ( rprop($pkg, 'base') || ( rprop($pkg, 'orig') && $done == 1 ) ) ) { |
389 |
tagpkg($pkg, 'inuse', 1); |
390 |
} else { |
391 |
printline('bold magenta', 1, " - ($repo) ", $pkg->{rpm}->filename) if $opts{d}; |
392 |
my $color = 'bold white'; |
393 |
$color = 'bold yellow' if rprop($pkg, 'orig'); |
394 |
$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 |
defined $done or $done = 0; |
408 |
|
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 |
if ( $repos->{$pkg->{repo}} && ! rprop($pkg, 'orig') ) { |
422 |
# 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 |
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 |
} |
443 |
push @{$archs->{$pkg->{repo}}->{$pkg->{rpm}->as_nvre}->{$pkg->{rpm}->is_source_package ? 'src' : $pkg->{rpm}->arch}}, $pkg; |
444 |
} |
445 |
} |
446 |
|
447 |
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 |
return unless m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$} && ( ! $opts{r} || $1 =~ m{$opts{r}} ); |
468 |
|
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 |
my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$}; |
476 |
foreach my $repo ( keys %{$skippkg->{$rel}} ) { return if (dirname $pkg->filename) =~ m{/$repo/} && grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}}; } |
477 |
my $reponame = 'unknown'; |
478 |
if ( substr($_, 0, length($distrepo->{$rel}->{builds})) eq $distrepo->{$rel}->{builds} ) { |
479 |
$reponame = 'builds'; |
480 |
} elsif ( substr($_, 0, length($distrepo->{$rel}->{contribs})) eq $distrepo->{$rel}->{contribs} ) { |
481 |
$reponame = 'contribs'; |
482 |
} 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 |
if ( $nosig && ( ! -f "$HOME/.rpmpass" || ! $repos->{$reponame}->{orig} ) ) { |
488 |
printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)'); |
489 |
return; |
490 |
} |
491 |
push @rpms, { base => $srcname, |
492 |
name => $pkg->name, |
493 |
repo => $reponame, |
494 |
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
495 |
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 |
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 |
} |
506 |
|
507 |
sub loadbase { |
508 |
printline('white', 0, "Loading: $_") if -d _; |
509 |
return unless m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$} && ($latest{$1} || $sources{$1}); |
510 |
|
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 |
my $cmp = $latest{$pkg->name}; |
518 |
my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$}; |
519 |
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 |
return if ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && rprop($cmp, 'base') && rprop($cmp, 'prio') > $repos->{$pkgrepo}->{prio}; |
526 |
last; |
527 |
} |
528 |
} |
529 |
|
530 |
push @rpms, { base => $srcname, |
531 |
name => $pkg->name, |
532 |
repo => $pkgrepo, |
533 |
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
534 |
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 |
$latest{$pkg->name} = $rpms[$#rpms]; |
542 |
} |
543 |
} |
544 |
|