/[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.71 - (show annotations) (download)
Wed Feb 13 19:36:25 2013 UTC (11 years, 9 months ago) by slords
Branch: MAIN
Changes since 1.70: +72 -36 lines
Tools updates

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

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