/[smeserver]/builds_bin/update_repos
ViewVC logotype

Contents of /builds_bin/update_repos

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


Revision 1.72 - (show annotations) (download)
Sat Mar 16 14:19:11 2013 UTC (11 years, 8 months ago) by slords
Branch: MAIN
Changes since 1.71: +11 -7 lines
Tools update

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 Data::Dumper;
10
11 delete $ENV{PATH};
12 my $HOME=$ENV{HOME};
13 umask 002;
14 $| = 1;
15
16 my %opts;
17 getopts( 'osqtr:', \%opts );
18 $opts{r} ||= '';
19
20 my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader | RPM2->vsf_nodsa | RPM2->vsf_norsa;
21
22 my $osdir = 'SME';
23 my $disttag = 'sme';
24 my $repotag = 'sme';
25
26 my @archs = ( 'i386', 'x86_64' );
27
28 my $distrepo = { '7' => { active => 0,
29 centos => 4,
30 repo => '/build/smeserver/repo/7/',
31 builds => ['/build/builds/smeserver-7-core/'],
32 community => '/build/builds/smeserver-7-contribs/',
33 stage => '/build/smeserver/stage/7/',
34 sign => 1,
35 checksum => 'sha',
36 },
37 '8' => { active => 1,
38 centos => 5,
39 repo => '/build/smeserver/repo/8/',
40 builds => ['/build/builds/smeserver-8-core/'],
41 community => '/build/builds/smeserver-8-contribs/',
42 stage => '/build/smeserver/stage/8/',
43 sign => 1,
44 checksum => 'sha',
45 },
46 '9' => { active => 1,
47 centos => 6,
48 repo => '/build/smeserver/repo/testing/9/',
49 builds => ['/build/builds/smeserver-9-core/'],
50 community => '/build/builds/smeserver-9-contribs/',
51 stage => '/build/smeserver/stage/9/',
52 sign => 1,
53 checksum => 'sha256',
54 },
55 };
56
57 my $repos = { "${repotag}os" => { prio => 19, inc => 1, ver => 1, rel => 1, os => 1 },
58 "${repotag}updates" => { prio => 18, inc => 1, ver => 1, rel => 1 },
59 "${repotag}updates-testing" => { prio => 17, inc => 1, ver => 1, rel => 3 },
60 "${repotag}extras" => { prio => 16, inc => 0, ver => 1, rel => 1 },
61 "${repotag}addons" => { prio => 15, inc => 0, ver => 1, rel => 1 },
62 "${repotag}contribs" => { prio => 14, inc => 0, ver => 1, rel => 1 },
63 "${repotag}test" => { prio => 13, inc => 0, ver => 2, rel => 3, devel => 2 },
64 "${repotag}dev" => { prio => 12, inc => 0, ver => 1, rel => 1, devel => 1 },
65 'centos' => { prio => 10, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 },
66 'epel' => { prio => 9, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 },
67 'rpmforge' => { prio => 7, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 },
68 'atrpms' => { prio => 6, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 },
69 'builds' => { prio => 4, inc => 0, ver => 0, rel => 0, orig => 1 },
70 'community' => { prio => 2, inc => 0, ver => 0, rel => 0, orig => 1 },
71 'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 },
72 };
73
74 my $baserepo = { "~S${repotag}os/~A/" => "${repotag}os",
75 "~S${repotag}updates/~A/" => "${repotag}updates",
76 "~S${repotag}updates-testing/~A/" => "${repotag}updates-testing",
77 "~S${repotag}extras/~A/" => "${repotag}extras",
78 "~S${repotag}addons/~A/" => "${repotag}addons",
79 "~S${repotag}contribs/~A/" => "${repotag}contribs",
80 "~S${repotag}test/~A/" => "${repotag}test",
81 "~S${repotag}dev/~A/" => "${repotag}dev",
82 "/build/smeserver/stage/~s/~A/" => 'stage',
83 '/mirrors/centos/~C/fasttrack/~A/' => 'centos',
84 '/mirrors/centos/~C/updates/~A/' => 'centos',
85 '/mirrors/centos/~C/os/~A/' => 'centos',
86 '/mirrors/centos/~C/extras/~A/' => 'centos',
87 '/mirrors/centos-vault/~C/fasttrack/~A/' => 'centos',
88 '/mirrors/centos-vault/~C/updates/~A/' => 'centos',
89 '/mirrors/centos-vault/~C/os/~A/' => 'centos',
90 '/mirrors/centos-vault/~C/extras/~A/' => 'centos',
91 '/mirrors/fedora/epel/~C/~A/' => 'epel',
92 '/mirrors/fedora/epel/testing/~C/~A/' => 'epel',
93 '/mirrors/rpmforge/redhat/el~C/en/~A/dag/' => 'rpmforge',
94 '/mirrors/rpmforge/redhat/el~C/en/~A/extras/' => 'rpmforge',
95 '/mirrors/rpmforge/source/' => 'rpmforge',
96 '/mirrors/atrpms/el~C-~A/atrpms/stable/' => 'atrpms',
97 '/mirrors/atrpms/el~C-~A/atrpms/testing/' => 'atrpms',
98 '/mirrors/atrpms/src/el~C-~A/atrpms/stable/' => 'atrpms',
99 '/mirrors/atrpms/src/el~C-~A/atrpms/testing/' => 'atrpms',
100 };
101
102 if ( $opts{q} ) {
103 $baserepo->{'/mirrors/centos-qa/CentOS/~C/fasttrack/~A/'} = 'centos';
104 $baserepo->{'/mirrors/centos-qa/CentOS/~C/updates/~A/'} = 'centos';
105 $baserepo->{'/mirrors/centos-qa/CentOS/~C/os/~A/'} = 'centos';
106 $baserepo->{'/mirrors/centos-qa/CentOS/~C/extras/~A/'} = 'centos';
107 }
108
109 my $skippkg = { '7' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) },
110 'epel' => { map { $_ => 1 } ( 'clamav', 'fping', 'ocsinventory', 'perl-Compress-Bzip2', 'perl-Compress-Raw-Zlib', 'perl-Compress-Raw-Bzip2', 'perl-Crypt-OpenSSL-Bignum', 'perl-Crypt-OpenSSL-Random', 'perl-Crypt-OpenSSL-RSA', 'perl-DateTime', 'perl-Razor-Agent', 'perl-Text-Iconv' ) },
111 'rpmforge' => { map { $_ => 1 } ( 'dovecot', 'mod_auth_tkt', 'perl-Test-Inline', 'perl-libwww-perl', 'spamassassin' ) },
112 'atrpms' => { map { $_ => 1 } ( 'check4updates', 'dovecot', 'trac', 'yum' ) },
113 },
114 '8' => { 'atrpms' => { map { $_ => 1 } ( 'gnupg' ) },
115 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) },
116 'epel' => { map { $_ => 1 } ( 'clamav', 'fping', 'html2ps', 'horde', 'libtalloc', 'libtdb', 'oidentd', 'perl-Compress-Bzip2', 'perl-Compress-Raw-Zlib', 'perl-Compress-Raw-Bzip2', 'perl-Crypt-OpenSSL-Bignum', 'perl-Crypt-OpenSSL-Random', 'perl-Crypt-OpenSSL-RSA', 'perl-Razor-Agent', 'smolt' ) },
117 'rpmforge' => { map { $_ => 1 } ( 'dovecot', 'libtalloc', 'mod_auth_tkt', 'perl-Test-Inline', 'spamassassin' ) },
118 },
119 '9' => { 'atrpms' => { map { $_ => 1 } ( 'perl-Pod-Escapes', 'perl-Pod-Simple' ) },
120 'epel' => { map { $_ => 1 } ( 'oidentd', 'perl-Razor-Agent' ) },
121 'rpmforge' => { map { $_ => 1 } ( 'perl-CGI', 'perl-Compress-Raw-Zlib', 'perl-ExtUtils-ParseXS', 'perl-Pod-Escapes', 'perl-Pod-Simple', 'perl-Time-HiRes', 'perl-version', 'spamassassin' ) },
122 },
123 };
124
125 my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos;
126 my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos;
127 $devel2 ||= $devel1;
128
129 my ($rpms, %base, %latest, %sources);
130 foreach my $ver ( sort { $a <=> $b } keys %$distrepo ) {
131 next unless $distrepo->{$ver}->{active};
132 my %repochg = ();
133 $rpms = ();
134 %latest = ();
135 %sources = ();
136 %base = ();
137
138 foreach my $dir ( sort { $repos->{$baserepo->{$b}}->{prio} <=> $repos->{$baserepo->{$a}}->{prio} || $a cmp $b } keys %$baserepo ) {
139 my $bdir = $dir;
140 $bdir =~ s/~S/$distrepo->{$ver}->{repo}/;
141 $bdir =~ s/~s/$ver/;
142 $bdir =~ s/~C/$distrepo->{$ver}->{centos}/;
143 for my $arch ( @archs, 'SRPMS/' ) {
144 my $adir = $bdir;
145 if ( $arch eq 'SRPMS/' ) {
146 $adir =~ s/~A.*//;
147 if ( -d "${adir}SRPMS" ) {
148 $adir .= "SRPMS/";
149 } elsif ( -d "${adir}Source/SPackages" ) {
150 $adir .= "Source/SPackages/";
151 }
152 } else {
153 $adir =~ s/~A/$arch/;
154 if ( -d "${adir}CentOS/RPMS" ) {
155 $adir .= "CentOS/RPMS/";
156 } elsif ( -d "${adir}$osdir/RPMS" ) {
157 $adir .= "$osdir/RPMS/";
158 } elsif ( -d "${adir}RPMS" ) {
159 $adir .= "RPMS/";
160 } elsif ( -d "${adir}Packages" ) {
161 $adir .= "Packages/";
162 } elsif ( -d "${adir}CentOS" ) {
163 $adir .= "CentOS/";
164 } elsif ( -d "${adir}$osdir" ) {
165 $adir .= "$osdir/";
166 }
167 }
168 next unless -d $adir;
169 opendir DIR, $adir or next;
170 process_rpm("$adir$_", $ver, $baserepo->{$dir}) foreach readdir DIR;
171 closedir DIR;
172 last unless $dir =~ m{~A};
173 }
174 }
175 find( { wanted => sub { process_rpm($_, $ver, 'builds'); }, no_chdir => 1, follow_fast => 1 }, "$_" ) foreach @{$distrepo->{$ver}->{'builds'}};
176 find( { wanted => sub { process_rpm($_, $ver, 'community'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'community'} ) if $distrepo->{$ver}->{'community'};
177
178 foreach my $base ( sort keys %$rpms ) {
179 next unless $rpms->{$base}->{rpms};
180 my %track = ();
181 my %seen = ();
182 my %counts = ();
183 my $acnt = ();
184 my $print = 0;
185 %latest = ();
186
187 foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{rpms}} ) {
188 next if $pkg->{done};
189
190 my $tmp = $pkg->{svr};
191 # srpm transformations to match up binary and source rpms
192 SRC: {
193 # Try to find the name the binary wants (no changes)
194 $rpms->{$base}->{vers}->{$tmp} && last SRC;
195
196 # rpmforge (.el4.rf to .rf, with rf,rfb,rft,rfx endings)
197 ($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf[btx]?)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
198 # rpmforge (.el4.rfx to .rf, rfb,rft,rfx switched to rf)
199 ($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)[btx]$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
200 # rpmforge (.el4.rf to .rfx, rf,rfb,rft,rfx switched to rfx)
201 ($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)[btx]?$}{$1x} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
202 # rpmforge (.el4.rf to .el5) TODO: remove when no longer needed
203 ($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.el5} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
204 # rpmforge (.2.el4.rf to .rf, minor modification not pushed to source?) TODO: remove when no longer needed
205 ($tmp = $pkg->{svr}) =~ s{\.2\.el\d(\.rf)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
206
207 # atrpms (remove .at)
208 ($tmp = $pkg->{svr}) =~ s{\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
209 # atrpms (remove .el4.at)
210 ($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
211 # atrpms (remove .el4)
212 ($tmp = $pkg->{svr}) =~ s{\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
213 # atrpms (remove .0.el5, minor modification not pushed to source?) TODO: remove when no longer needed
214 ($tmp = $pkg->{svr}) =~ s{\.0\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
215
216 # Transformations that we hopefully won't have to use anymore TODO: remove if no issues
217 #($tmp = $pkg->{svr}) =~ s{(\.el\d)\.rf$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
218 #($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+(\.rf)$}{$1$2} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
219 #($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
220 #($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d\.rf$}{$1.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
221 #($tmp = $pkg->{svr}) =~ s{\.el\d_}{_} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
222 #($tmp = $pkg->{svr}) =~ s{(-\d+)\.\d+\.el\d$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
223 #($tmp = $pkg->{svr}) =~ s{\.centos\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
224 #($tmp = $pkg->{svr}) =~ s{\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
225 #($tmp = $pkg->{svr}) =~ s{\.el\d\.$disttag$}{ && $rpms->{$base}->{vers}->{$tmp} && last SRC;
226 }
227 if ( $rpms->{$base}->{vers}->{$tmp} ) {
228 foreach $tmp ( @{$rpms->{$base}->{vers}->{$tmp}} ) {
229 $tmp->{svr} = $pkg->{svr};
230 push @{$rpms->{$base}->{rpms}}, $tmp unless $tmp->{added};
231 $tmp->{added}++;
232 }
233 }
234
235 my %orig = ();
236 my %pkgs = ();
237 my %reposrc = ();
238 my $srpm = undef;
239 foreach my $cmp ( sort { $a->{src} <=> $b->{src} || $repos->{$b->{repo}}->{prio} <=> $repos->{$a->{repo}}->{prio} } @{$rpms->{$base}->{rpms}} ) {
240 next unless $cmp->{svr} eq $pkg->{svr};
241
242 if ( ! $track{repo} || $repos->{$cmp->{repo}}->{prio} > $repos->{$track{repo}}->{prio} ) {
243 if ( $cmp->{src} ) {
244 if ( ! $track{repo} ) {
245 $cmp->{delete}++;
246 $cmp->{done}++;
247 next;
248 }
249 } else {
250 $track{repo} = $cmp->{repo};
251 $track{svr} = $cmp->{svr};
252 }
253 }
254 if ( $cmp->{svr} eq $track{svr} ) {
255 if ( $seen{$cmp->{nvra}} ) {
256 if ( $track{repo} ne $cmp->{repo} ) {
257 if ($repos->{$cmp->{repo}}->{stage} ) {
258 if ( $seen{$cmp->{nvra}}->{latest} ) {
259 $seen{$cmp->{nvra}}->{latest}++;
260 delete $cmp->{delete} if $cmp->{delete};
261 } else {
262 $cmp->{delete}++;
263 }
264 } elsif ( $repos->{$cmp->{repo}}->{orig} ) {
265 $orig{$cmp->{nvra}}++;
266 unless ( $repos->{$cmp->{repo}}->{base} ) {
267 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel};
268 qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED";
269 }
270 } elsif ( $cmp->{src} ) {
271 if ( $cmp->{delete} && $cmp->{oldrepo} && $reposrc{$cmp->{oldrepo}}) {
272 $cmp->{repo} = $cmp->{oldrepo};
273 delete $cmp->{delete};
274 }
275 if ( $reposrc{$cmp->{repo}} ) {
276 $reposrc{$cmp->{repo}}->{srpm} = $cmp;
277 $srpm = $cmp if ! $srpm;
278 } elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} && ! $cmp->{done} ) {
279 $cmp->{delete}++;
280 }
281 } elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} ) {
282 $cmp->{delete}++;
283 }
284 } elsif ( $cmp->{src} ) {
285 if ( $reposrc{$cmp->{repo}} && $reposrc{$cmp->{repo}}->{srpm} && $reposrc{$cmp->{repo}}->{srpm}->{oldrepo} ne $cmp->{repo} ) {
286 $acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{src} = [
287 grep { $_ ne $reposrc{$cmp->{repo}}->{srpm} } @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{src}}
288 ];
289
290 if ( @{$reposrc{$cmp->{repo}}->{srpm}->{repos}} == 1 ) {
291 $reposrc{$cmp->{repo}}->{srpm}->{repo} = $reposrc{$cmp->{repo}}->{srpm}->{oldrepo};
292 delete $reposrc{$cmp->{repo}}->{srpm}->{oldrepo};
293 delete $reposrc{$cmp->{repo}}->{srpm}->{delete};
294 delete $reposrc{$cmp->{repo}}->{srpm}->{repos};
295 delete $reposrc{$cmp->{repo}}->{srpm}->{done};
296 $seen{$cmp->{nvra}} = $cmp if $seen{$cmp->{nvra}} eq $reposrc{$cmp->{repo}}->{srpm};
297 } else {
298 warn "How did I get here??";
299 }
300 } else {
301 $seen{$cmp->{nvra}} = $cmp if $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo};
302 }
303 $srpm = $cmp if ! $srpm && $cmp->{src};
304 $reposrc{$cmp->{repo}}->{srpm} = $cmp if $reposrc{$cmp->{repo}};
305 }
306 } elsif ( $repos->{$cmp->{repo}}->{stage} ) {
307 $cmp->{delete}++;
308 } else {
309 $srpm = $cmp if ! $srpm && $cmp->{src};
310 my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2;
311 $dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms});
312 $dest = $devel1 if verrel($cmp, $dest, \%counts);
313 if ( $cmp->{repo} ne $dest ) {
314 push @{$cmp->{repos}}, $dest;
315 if ( $repos->{$cmp->{repo}}->{orig} ) {
316 $orig{$cmp->{nvra}}++;
317 unless ( $repos->{$cmp->{repo}}->{base} ) {
318 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel};
319 qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED";
320 }
321 } elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) {
322 $reposrc{$cmp->{repo}}->{srpm} = $cmp;
323 } else {
324 $cmp->{delete}++;
325 }
326 $cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo};
327 $cmp->{repo} = $dest;
328 if ( ! $cmp->{src} && $repos->{$dest}->{prio} > $repos->{$track{repo}}->{prio} ) {
329 $track{repo} = $dest;
330 $track{svr} = $cmp->{svr};
331 }
332 }
333 if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) {
334 $reposrc{$cmp->{repo}}->{srpm} = $cmp;
335 }
336 }
337 } else {
338 if ( $track{repo} eq $cmp->{repo} ) {
339 if ( verrel($cmp, $cmp->{repo}, \%counts) ) {
340 $cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base};
341 } elsif ( $cmp->{src} ) {
342 $cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base};
343 } else {
344 $track{svr} = $cmp->{svr};
345 }
346 } elsif ( ! $repos->{$cmp->{repo}}->{base} ) {
347 if ( $repos->{$cmp->{repo}}->{orig} ) {
348 $srpm = $cmp if ! $srpm && $cmp->{src};
349 my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2;
350 $dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms});
351 $dest = $devel1 if verrel($cmp, $dest, \%counts);
352 unless ( $cmp->{src} && ! $reposrc{$dest} ) {
353 if ( $repos->{$dest}->{prio} >= $repos->{$track{repo}}->{prio} && ! verrel($cmp, $dest, \%counts) ) {
354 unless ( $repos->{$cmp->{repo}}->{base} ) {
355 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel};
356 qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED";
357 }
358 push @{$cmp->{repos}}, $dest;
359 $cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo};
360 $cmp->{repo} = $dest;
361 $reposrc{$cmp->{repo}}->{srpm} = $cmp if $cmp->{src};
362 $orig{$cmp->{nvra}}++;
363 }
364 }
365 } else {
366 $cmp->{delete}++;
367 }
368 }
369 }
370 unless ( $repos->{$cmp->{repo}}->{orig} || ( $cmp->{delete} && ! $cmp->{repos} ) ) {
371 $pkgs{$cmp->{nvra}}++;
372 $latest{$cmp->{base}} = $cmp->{svr} if $repos->{$cmp->{repo}}->{inc} && ! $latest{$cmp->{base}};
373 $reposrc{$cmp->{repo}} = $cmp unless $reposrc{$cmp->{repo}} || $cmp->{src} || $repos->{$cmp->{repo}}->{stage};
374 if ( $latest{$cmp->{base}} && $cmp->{svr} eq $latest{$cmp->{base}} && $repos->{$cmp->{repo}}->{inc} ) {
375 $cmp->{latest}++ if ! $seen{$cmp->{nvra}} || $cmp->{src};
376 }
377 $seen{$cmp->{nvra}} = $cmp unless $seen{$cmp->{nvra}};
378 push @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{$cmp->{src} ? 'src' : $cmp->{rpm}->arch}}, $cmp unless $cmp->{done};
379 }
380 $cmp->{done}++;
381 }
382 if ( $srpm ) {
383 foreach my $r ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %reposrc ) {
384 unless ( $reposrc{$r}->{srpm} ) {
385 unshift @{$srpm->{repos}}, $r;
386 $srpm->{oldrepo} = $srpm->{repo} unless $srpm->{oldrepo};
387 $srpm->{repo} = $r;
388 $reposrc{$r}->{srpm} = $srpm;
389 }
390 }
391 } elsif ( scalar keys %pkgs && $opts{s} ) {
392 print "\n * missing source ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n";
393 }
394 print "\n * missing originals ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n" if $opts{o} && scalar keys %orig != scalar keys %pkgs;
395 }
396
397 foreach my $r ( keys %$acnt ) {
398 foreach my $p ( keys %{$acnt->{$r}} ) {
399 foreach my $a ( keys %{$acnt->{$r}->{$p}} ) {
400 if ( $a eq 'noarch' ) {
401 my $p2 = ${$acnt->{$r}->{$p}->{$a}}[0];
402 if ( ! $p2->{repos} && scalar @{$acnt->{$r}->{$p}->{$a}} != scalar @archs ) {
403 $p2->{oldrepo} = $p2->{repo};
404 push @{$p2->{repos}}, $p2->{repo};
405 }
406 } elsif ( scalar @{$acnt->{$r}->{$p}->{$a}} != 1 ) {
407 print "\n * many packages ($r, $a, $p)\n";
408 }
409 }
410 }
411 }
412
413 foreach my $pkg ( sort { $a->{nvra} cmp $b->{nvra} } @{$rpms->{$base}->{rpms}} ) {
414 if ( $pkg->{latest} && $pkg->{latest} == 1 ) {
415 unless ( grep { $_->{nvra} eq $pkg->{nvra} && $_->{repo} eq $stage } @{$rpms->{$base}->{rpms}} ) {
416 $pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo};
417 $pkg->{repo} = $stage;
418 push @{$pkg->{repos}}, $stage;
419 }
420 }
421 if ( ! $print && ($pkg->{delete} || $pkg->{repos} || ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) ) ) {
422 print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n";
423 $print++;
424 }
425
426 my $src = $pkg->{rpm}->filename;
427 if ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) {
428 print "sign package (", basename($pkg->{rpm}->filename), ")\n";
429 unless ( $opts{t} ) {
430 qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null);
431 if ($?) {
432 print " * failed to sign package\n";
433 next;
434 }
435 }
436 }
437
438 if ( $pkg->{repos} ) {
439 foreach my $repo ( @{$pkg->{repos}} ) {
440 if ( $pkg->{delete} ) {
441 print "move from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n";
442 $pkg->{delete} = 0;
443 $repochg{$pkg->{oldrepo}}++ unless $repos->{$pkg->{oldrepo}}->{base} || $repos->{$pkg->{oldrepo}}->{stage};
444 } elsif ( $pkg->{oldrepo} eq $repo ) {
445 print "distribute noarch in $repo (", basename($pkg->{rpm}->filename), ")\n";
446 } else {
447 print "copy from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n";
448 }
449 $repochg{$repo}++ unless $repos->{$repo}->{base} || $repos->{$repo}->{stage};
450 $pkg->{oldrepo} = $repo unless $pkg->{oldrepo} eq ${$pkg->{repos}}[0];
451
452 my @d = ();
453 my $head = $distrepo->{$ver}->{repo} . $repo . '/';
454 $head = $distrepo->{$ver}->{stage} if $repos->{$repo}->{stage};
455 my $tail = $repos->{$repo}->{os} ? "$osdir/" : 'RPMS/';
456 if ( $pkg->{src} ) {
457 push @d, "${head}SRPMS/" . basename($pkg->{rpm}->filename);
458 } elsif ( $pkg->{rpm}->arch eq 'noarch' ) {
459 push @d, map { "${head}$_/$tail" . basename($pkg->{rpm}->filename) } @archs;
460 } elsif ( $pkg->{rpm}->arch =~ m{^(i[356]86)$} ) {
461 push @d, "${head}i386/$tail" . basename($pkg->{rpm}->filename);
462 } else {
463 push @d, $head . $pkg->{rpm}->arch . "/$tail" . basename($pkg->{rpm}->filename);
464 }
465 foreach my $dest ( @d ) {
466 qx(cp --preserve=timestamps $src $dest) unless $opts{t} || -f "$dest";
467 }
468
469 }
470 qx(rm -f $src) if exists $pkg->{delete} && ! $opts{t};
471 } elsif ( $pkg->{delete} ) {
472 print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n";
473 qx(rm -f $src) unless $opts{t};
474 $repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage};
475 if ( $repos->{$pkg->{repo}}->{orig} && ! $repos->{$pkg->{repo}}->{base} ) {
476 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$pkg->{repo}}, $pkg->{name}, $pkg->{ver}, $pkg->{rel};
477 qx(rm -f $tag/PUSHED) if ! $opts{t} && -d $tag && -f "$tag/PUSHED";
478 }
479 }
480 }
481
482 if ( $rpms->{$base}->{srpms} ) {
483 foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{srpms}} ) {
484 next if $pkg->{done} || $repos->{$pkg->{repo}}->{orig} || $repos->{$pkg->{repo}}->{base};
485 $pkg->{delete}++;
486 my $src = $pkg->{rpm}->filename;
487 if ( ! $print && ($pkg->{delete} || $pkg->{repos} || ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) ) ) {
488 print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n";
489 $print++;
490 }
491 print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n";
492 qx(rm -f $src) unless $opts{t};
493 $repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage};
494 }
495 }
496 }
497
498 if ( %repochg ) {
499 print "\nrebuild repo ($disttag$ver)\n", "=" x length("rebuild repo ($disttag$ver)"), "\n";
500 }
501 foreach my $repo ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %repochg ) {
502 next if $repos->{$repo}->{orig} || $repos->{$repo}->{stage};
503 foreach my $arch ( @archs ) {
504 my $dir = $distrepo->{$ver}->{repo} . "$repo/$arch";
505 $dir = qx(readlink -f $dir);
506 if ( $dir ) {
507 chomp $dir;
508 } else {
509 $dir = $distrepo->{$ver}->{repo} . "$repo/$arch";
510 }
511 print "rebuild $repo/$arch\n";
512 unless ( $opts{t} ) {
513 my $checksum = "--checksum $distrepo->{$ver}->{checksum}";
514
515 my $exclude = "";
516 $exclude .= " --exclude ${osdir}/*" if -d "$dir/Packages";
517 $exclude .= " --exclude *smeserver-release*.rpm" if $dir =~ m{test/|-testing/};
518
519 my $groupfile = "";
520 $groupfile = "--simple-md-filenames --groupfile repodata/comps.xml" if -f "$dir/repodata/comps.xml";
521
522 qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm $checksum $exclude $groupfile $dir);
523 qx(repoview $dir);
524
525 qx(rm -rf $dir/.olddata) if -d "$dir/.olddata";
526 qx(rm -rf $dir/.repodata) if -d "$dir/.repodata";
527 qx(rm -rf $dir/repodata/index.html) if -f "$dir/repodata/index.html";
528 qx(rm -rf $dir/repodata/update-info) if -d "$dir/repodata/update-info";
529 qx(rm -rf $dir/repodata/repoview) if -d "$dir/repodata/repoview";
530 }
531 }
532 }
533 unless ( $opts{t} ) {
534 foreach (@{$distrepo->{$ver}->{builds}})
535 {
536 finddepth(sub{rmdir}, "$_") if -d "$_";
537 }
538 finddepth(sub{rmdir}, $distrepo->{$ver}->{community}) if -d "$distrepo->{$ver}->{community}";
539 }
540 }
541
542 sub verrel {
543 my $pkg = shift;
544 my $repo = shift;
545 my $counts = shift;
546
547 return 0 if $pkg->{src};
548 $counts->{$repo}->{$pkg->{ver}}->{$pkg->{rel}}++;
549 return 1 if $repos->{$repo}->{ver} && scalar keys %{$counts->{$repo}} > $repos->{$repo}->{ver};
550 return 1 if $repos->{$repo}->{rel} && scalar keys %{$counts->{$repo}->{$pkg->{ver}}} > $repos->{$repo}->{rel};
551 return 0;
552 }
553
554 sub pkgdest {
555 my $pkg = shift;
556 my $dest = shift;
557 my $hirepo = shift;
558 my $pkgs = shift;
559
560 foreach my $cmp ( @$pkgs ) {
561 next if $cmp->{src} || $repos->{$cmp->{repo}}->{prio} <= $repos->{$dest}->{prio};
562 next if $pkg->{name} ne ( $pkg->{src} ? $cmp->{base} : $cmp->{name} );
563 if ( $repos->{$cmp->{repo}}->{prio} > $repos->{$hirepo}->{prio} ) {
564 $dest = $hirepo;
565 last;
566 } else {
567 $dest = $cmp->{repo};
568 }
569 }
570 return $dest;
571 }
572
573 sub process_rpm {
574 my $rpm = shift;
575 my $ver = shift;
576 my $repo = shift;
577 return unless $rpm =~ m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$};
578 my $base = $1;
579 return unless ! $opts{r} || $base =~ m[$opts{r}];
580 return unless $latest{$base} || $sources{$base} || ! $repos->{$repo}->{base};
581
582 my $pkg;
583 eval { $pkg = RPM2->open_package($rpm, $rpm_flags); };
584 if ($@) { print " * corrupt package ($rpm)\n"; return; }
585 eval { my $sig = $pkg->siggpg };
586
587 my $nosig = 1;
588 eval { my $sig = $pkg->dsaheader }; $nosig &= ! $@;
589 eval { my $sig = $pkg->rsaheader }; $nosig &= ! $@;
590 eval { my $sig = $pkg->siggpg }; $nosig &= ! $@;
591 eval { my $sig = $pkg->sigpgp }; $nosig &= ! $@;
592
593 my $cmp = $latest{$pkg->name};
594 if ( $repos->{$repo}->{base} && ! $pkg->is_source_package ) {
595 return unless $cmp;
596 return if $repos->{$cmp->{repo}}->{base} && $repos->{$cmp->{repo}}->{prio} > $repos->{$repo}->{prio} && $pkg ge $cmp->{rpm};
597 }
598 my ($src, $version, $release) = ($pkg->is_source_package ? $pkg->filename : $pkg->sourcerpm) =~ m{(?:^|/)([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$};
599 return if $skippkg->{$ver}->{$repo} && ( $skippkg->{$ver}->{$repo}->{$src} || $skippkg->{$ver}->{$repo}->{$pkg->name} );
600 return if $repos->{$repo}->{base} && $nosig && $baserepo->{$ver}->{sign};
601 if ( $nosig && ! -f "$HOME/.rpmpass" ) { print " * missing signature (" .$pkg->filename . ")\n"; return; }
602 my $arch = 'unknown';
603 $arch = 'SRPMS' if $pkg->filename =~ m{[/-](SRPMS?|src|source)/};
604 $arch = 'x86_64' if $pkg->filename =~ m{[/-]x86_64/};
605 $arch = 'i386' if $pkg->filename =~ m{[/-](i[356]86)/};
606 $arch = 'noarch' if $pkg->filename =~ m{[/-]noarch/};
607
608 my $rpmhash = { base => $src,
609 name => $pkg->name,
610 repo => $repo,
611 nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ),
612 svr => $src.'-'.$version.'-'.$release,
613 src => $pkg->is_source_package,
614 arch => $arch,
615 ver => $version,
616 rel => $release,
617 rpm => $pkg,
618 nosig => $nosig,
619 };
620 if ( $pkg->is_source_package ) {
621 push @{$rpms->{$src}->{srpms}}, $rpmhash;
622 push @{$rpms->{$src}->{vers}->{$rpmhash->{svr}}}, $rpmhash;
623 } else {
624 push @{$rpms->{$src}->{rpms}}, $rpmhash;
625 }
626 $sources{$src}++;
627
628 return if $pkg->is_source_package || $repos->{$repo}->{stage};
629 if ( ! $repos->{$repo}->{base} ) {
630 if ( ! $cmp || $pkg gt $cmp->{rpm} ) {
631 $latest{$pkg->name} = $rpmhash;
632 }
633 } elsif ( ( $repos->{$repo}->{prio} >= $repos->{$cmp->{repo}}->{prio} || ! $repos->{$cmp->{repo}}->{base} ) && $pkg ge $cmp->{rpm} ) {
634 $latest{$pkg->name} = $rpmhash;
635 }
636 }

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