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