/[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.90 - (show annotations) (download)
Fri Feb 8 06:26:29 2019 UTC (5 years, 9 months ago) by jpp
Branch: MAIN
Changes since 1.89: +26 -21 lines
pre openfusion

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

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