/[smeserver]/builds_bin/update_repos
ViewVC logotype

Annotation of /builds_bin/update_repos

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


Revision 1.72 - (hide 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 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 slords 1.1 use Data::Dumper;
10    
11 slords 1.20 delete $ENV{PATH};
12     my $HOME=$ENV{HOME};
13     umask 002;
14 slords 1.30 $| = 1;
15    
16     my %opts;
17 slords 1.31 getopts( 'osqtr:', \%opts );
18 slords 1.30 $opts{r} ||= '';
19 slords 1.20
20 slords 1.72 my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader | RPM2->vsf_nodsa | RPM2->vsf_norsa;
21 slords 1.20
22 slords 1.52 my $osdir = 'SME';
23     my $disttag = 'sme';
24     my $repotag = 'sme';
25    
26 slords 1.20 my @archs = ( 'i386', 'x86_64' );
27    
28 slords 1.71 my $distrepo = { '7' => { active => 0,
29 slords 1.53 centos => 4,
30 slords 1.70 repo => '/build/smeserver/repo/7/',
31 slords 1.71 builds => ['/build/builds/smeserver-7-core/'],
32 slords 1.70 community => '/build/builds/smeserver-7-contribs/',
33     stage => '/build/smeserver/stage/7/',
34 slords 1.67 sign => 1,
35 slords 1.66 checksum => 'sha',
36 slords 1.20 },
37 slords 1.53 '8' => { active => 1,
38     centos => 5,
39 slords 1.70 repo => '/build/smeserver/repo/8/',
40 slords 1.71 builds => ['/build/builds/smeserver-8-core/'],
41 slords 1.70 community => '/build/builds/smeserver-8-contribs/',
42     stage => '/build/smeserver/stage/8/',
43 slords 1.67 sign => 1,
44 slords 1.66 checksum => 'sha',
45 slords 1.20 },
46 slords 1.71 '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 slords 1.72 sign => 1,
53 slords 1.71 checksum => 'sha256',
54     },
55 slords 1.20 };
56    
57 slords 1.67 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 slords 1.52 '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 slords 1.53 'community' => { prio => 2, inc => 0, ver => 0, rel => 0, orig => 1 },
71 slords 1.52 'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 },
72 slords 1.30 };
73    
74 slords 1.71 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 slords 1.30 '/mirrors/fedora/epel/~C/~A/' => 'epel',
92     '/mirrors/fedora/epel/testing/~C/~A/' => 'epel',
93 slords 1.71 '/mirrors/rpmforge/redhat/el~C/en/~A/dag/' => 'rpmforge',
94     '/mirrors/rpmforge/redhat/el~C/en/~A/extras/' => 'rpmforge',
95 slords 1.60 '/mirrors/rpmforge/source/' => 'rpmforge',
96 slords 1.30 '/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 slords 1.31 if ( $opts{q} ) {
103 slords 1.71 $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 slords 1.31 }
108    
109 slords 1.49 my $skippkg = { '7' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) },
110 slords 1.60 '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 slords 1.68 'rpmforge' => { map { $_ => 1 } ( 'dovecot', 'mod_auth_tkt', 'perl-Test-Inline', 'perl-libwww-perl', 'spamassassin' ) },
112 slords 1.42 'atrpms' => { map { $_ => 1 } ( 'check4updates', 'dovecot', 'trac', 'yum' ) },
113 slords 1.20 },
114 slords 1.58 '8' => { 'atrpms' => { map { $_ => 1 } ( 'gnupg' ) },
115     'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) },
116 slords 1.68 '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 slords 1.67 'rpmforge' => { map { $_ => 1 } ( 'dovecot', 'libtalloc', 'mod_auth_tkt', 'perl-Test-Inline', 'spamassassin' ) },
118 slords 1.20 },
119 slords 1.71 '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 slords 1.20 };
124    
125 slords 1.30 my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos;
126 slords 1.20 my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos;
127     $devel2 ||= $devel1;
128    
129 slords 1.30 my ($rpms, %base, %latest, %sources);
130 slords 1.52 foreach my $ver ( sort { $a <=> $b } keys %$distrepo ) {
131     next unless $distrepo->{$ver}->{active};
132 slords 1.30 my %repochg = ();
133     $rpms = ();
134 slords 1.21 %latest = ();
135 slords 1.20 %sources = ();
136 slords 1.30 %base = ();
137 slords 1.20
138 slords 1.30 foreach my $dir ( sort { $repos->{$baserepo->{$b}}->{prio} <=> $repos->{$baserepo->{$a}}->{prio} || $a cmp $b } keys %$baserepo ) {
139     my $bdir = $dir;
140 slords 1.52 $bdir =~ s/~S/$distrepo->{$ver}->{repo}/;
141     $bdir =~ s/~s/$ver/;
142     $bdir =~ s/~C/$distrepo->{$ver}->{centos}/;
143 slords 1.30 for my $arch ( @archs, 'SRPMS/' ) {
144     my $adir = $bdir;
145     if ( $arch eq 'SRPMS/' ) {
146 slords 1.71 $adir =~ s/~A.*//;
147     if ( -d "${adir}SRPMS" ) {
148     $adir .= "SRPMS/";
149     } elsif ( -d "${adir}Source/SPackages" ) {
150     $adir .= "Source/SPackages/";
151     }
152 slords 1.30 } else {
153     $adir =~ s/~A/$arch/;
154 slords 1.71 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 slords 1.30 }
168 slords 1.71 next unless -d $adir;
169 slords 1.30 opendir DIR, $adir or next;
170 slords 1.52 process_rpm("$adir$_", $ver, $baserepo->{$dir}) foreach readdir DIR;
171 slords 1.30 closedir DIR;
172     last unless $dir =~ m{~A};
173 slords 1.20 }
174     }
175 slords 1.71 find( { wanted => sub { process_rpm($_, $ver, 'builds'); }, no_chdir => 1, follow_fast => 1 }, "$_" ) foreach @{$distrepo->{$ver}->{'builds'}};
176 slords 1.53 find( { wanted => sub { process_rpm($_, $ver, 'community'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$ver}->{'community'} ) if $distrepo->{$ver}->{'community'};
177 slords 1.20
178 slords 1.30 foreach my $base ( sort keys %$rpms ) {
179 slords 1.35 next unless $rpms->{$base}->{rpms};
180 slords 1.30 my %track = ();
181 slords 1.20 my %seen = ();
182 slords 1.30 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 slords 1.31 my $tmp = $pkg->{svr};
191 slords 1.60 # srpm transformations to match up binary and source rpms
192 slords 1.31 SRC: {
193 slords 1.60 # 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 slords 1.66 # rpmforge (.el4.rfx to .rf, rfb,rft,rfx switched to rf)
199 slords 1.60 ($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)[btx]$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
200 slords 1.66 # 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 slords 1.60 # 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 slords 1.66 # atrpms (remove .at)
208     ($tmp = $pkg->{svr}) =~ s{\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC;
209 slords 1.60 # 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 slords 1.31 }
227     if ( $rpms->{$base}->{vers}->{$tmp} ) {
228     foreach $tmp ( @{$rpms->{$base}->{vers}->{$tmp}} ) {
229 slords 1.30 $tmp->{svr} = $pkg->{svr};
230 slords 1.31 push @{$rpms->{$base}->{rpms}}, $tmp unless $tmp->{added};
231     $tmp->{added}++;
232 slords 1.30 }
233 slords 1.20 }
234    
235 slords 1.30 my %orig = ();
236     my %pkgs = ();
237     my %reposrc = ();
238     my $srpm = undef;
239 slords 1.31 foreach my $cmp ( sort { $a->{src} <=> $b->{src} || $repos->{$b->{repo}}->{prio} <=> $repos->{$a->{repo}}->{prio} } @{$rpms->{$base}->{rpms}} ) {
240 slords 1.30 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 slords 1.31 if ( ! $track{repo} ) {
245 slords 1.30 $cmp->{delete}++;
246 slords 1.31 $cmp->{done}++;
247     next;
248 slords 1.30 }
249 slords 1.31 } 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 slords 1.30 if ( $track{repo} ne $cmp->{repo} ) {
257     if ($repos->{$cmp->{repo}}->{stage} ) {
258     if ( $seen{$cmp->{nvra}}->{latest} ) {
259     $seen{$cmp->{nvra}}->{latest}++;
260 slords 1.60 delete $cmp->{delete} if $cmp->{delete};
261 slords 1.30 } else {
262     $cmp->{delete}++;
263     }
264 slords 1.62 } elsif ( $repos->{$cmp->{repo}}->{orig} ) {
265 slords 1.30 $orig{$cmp->{nvra}}++;
266 slords 1.42 unless ( $repos->{$cmp->{repo}}->{base} ) {
267 slords 1.52 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel};
268 slords 1.45 qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED";
269 slords 1.42 }
270 slords 1.62 } elsif ( $cmp->{src} ) {
271     if ( $cmp->{delete} && $cmp->{oldrepo} && $reposrc{$cmp->{oldrepo}}) {
272 slords 1.60 $cmp->{repo} = $cmp->{oldrepo};
273     delete $cmp->{delete};
274     }
275 slords 1.62 if ( $reposrc{$cmp->{repo}} ) {
276 slords 1.60 $reposrc{$cmp->{repo}}->{srpm} = $cmp;
277     $srpm = $cmp if ! $srpm;
278 slords 1.62 } elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} && ! $cmp->{done} ) {
279 slords 1.60 $cmp->{delete}++;
280     }
281 slords 1.62 } elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} ) {
282     $cmp->{delete}++;
283 slords 1.26 }
284 slords 1.62 } 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 slords 1.20 }
306 slords 1.66 } elsif ( $repos->{$cmp->{repo}}->{stage} ) {
307 slords 1.30 $cmp->{delete}++;
308     } else {
309 slords 1.31 $srpm = $cmp if ! $srpm && $cmp->{src};
310 slords 1.30 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 slords 1.42 unless ( $repos->{$cmp->{repo}}->{base} ) {
318 slords 1.52 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$cmp->{repo}}, $cmp->{name}, $cmp->{ver}, $cmp->{rel};
319 slords 1.45 qx(touch $tag/PUSHED) if ! $opts{t} && -d $tag && ! -f "$tag/PUSHED";
320 slords 1.42 }
321 slords 1.31 } elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) {
322     $reposrc{$cmp->{repo}}->{srpm} = $cmp;
323 slords 1.30 } else {
324     $cmp->{delete}++;
325 slords 1.21 }
326 slords 1.30 $cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo};
327     $cmp->{repo} = $dest;
328 slords 1.39 if ( ! $cmp->{src} && $repos->{$dest}->{prio} > $repos->{$track{repo}}->{prio} ) {
329 slords 1.38 $track{repo} = $dest;
330 slords 1.39 $track{svr} = $cmp->{svr};
331 slords 1.38 }
332 slords 1.20 }
333 slords 1.31 if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) {
334     $reposrc{$cmp->{repo}}->{srpm} = $cmp;
335     }
336 slords 1.20 }
337 slords 1.30 } else {
338     if ( $track{repo} eq $cmp->{repo} ) {
339     if ( verrel($cmp, $cmp->{repo}, \%counts) ) {
340     $cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base};
341 slords 1.32 } elsif ( $cmp->{src} ) {
342     $cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base};
343 slords 1.18 } else {
344 slords 1.30 $track{svr} = $cmp->{svr};
345 slords 1.11 }
346 slords 1.30 } elsif ( ! $repos->{$cmp->{repo}}->{base} ) {
347 slords 1.36 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 slords 1.55 unless ( $cmp->{src} && ! $reposrc{$dest} ) {
353 slords 1.60 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 slords 1.44 }
364 slords 1.36 }
365     } else {
366     $cmp->{delete}++;
367     }
368 slords 1.30 }
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 slords 1.31 $reposrc{$cmp->{repo}} = $cmp unless $reposrc{$cmp->{repo}} || $cmp->{src} || $repos->{$cmp->{repo}}->{stage};
374 slords 1.60 if ( $latest{$cmp->{base}} && $cmp->{svr} eq $latest{$cmp->{base}} && $repos->{$cmp->{repo}}->{inc} ) {
375     $cmp->{latest}++ if ! $seen{$cmp->{nvra}} || $cmp->{src};
376 slords 1.20 }
377 slords 1.60 $seen{$cmp->{nvra}} = $cmp unless $seen{$cmp->{nvra}};
378 slords 1.62 push @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{$cmp->{src} ? 'src' : $cmp->{rpm}->arch}}, $cmp unless $cmp->{done};
379 slords 1.20 }
380 slords 1.30 $cmp->{done}++;
381 slords 1.20 }
382 slords 1.30 if ( $srpm ) {
383 slords 1.31 foreach my $r ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %reposrc ) {
384 slords 1.30 unless ( $reposrc{$r}->{srpm} ) {
385 slords 1.31 unshift @{$srpm->{repos}}, $r;
386 slords 1.30 $srpm->{oldrepo} = $srpm->{repo} unless $srpm->{oldrepo};
387     $srpm->{repo} = $r;
388     $reposrc{$r}->{srpm} = $srpm;
389     }
390 slords 1.20 }
391 slords 1.31 } elsif ( scalar keys %pkgs && $opts{s} ) {
392 slords 1.52 print "\n * missing source ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n";
393 slords 1.20 }
394 slords 1.52 print "\n * missing originals ($disttag$ver, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n" if $opts{o} && scalar keys %orig != scalar keys %pkgs;
395 slords 1.20 }
396 slords 1.30
397     foreach my $r ( keys %$acnt ) {
398     foreach my $p ( keys %{$acnt->{$r}} ) {
399     foreach my $a ( keys %{$acnt->{$r}->{$p}} ) {
400 slords 1.20 if ( $a eq 'noarch' ) {
401 slords 1.30 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 slords 1.20 }
409     }
410     }
411     }
412 slords 1.25
413 slords 1.30 foreach my $pkg ( sort { $a->{nvra} cmp $b->{nvra} } @{$rpms->{$base}->{rpms}} ) {
414     if ( $pkg->{latest} && $pkg->{latest} == 1 ) {
415 slords 1.65 unless ( grep { $_->{nvra} eq $pkg->{nvra} && $_->{repo} eq $stage } @{$rpms->{$base}->{rpms}} ) {
416 slords 1.63 $pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo};
417     $pkg->{repo} = $stage;
418     push @{$pkg->{repos}}, $stage;
419     }
420 slords 1.30 }
421 slords 1.67 if ( ! $print && ($pkg->{delete} || $pkg->{repos} || ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) ) ) {
422 slords 1.52 print "\n$base ($disttag$ver)\n", "=" x length("$base ($disttag$ver)"), "\n";
423 slords 1.30 $print++;
424     }
425 slords 1.20
426     my $src = $pkg->{rpm}->filename;
427 slords 1.67 if ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) {
428 slords 1.33 print "sign package (", basename($pkg->{rpm}->filename), ")\n";
429 slords 1.30 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 slords 1.20
438     if ( $pkg->{repos} ) {
439 slords 1.30 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 slords 1.52 my $head = $distrepo->{$ver}->{repo} . $repo . '/';
454     $head = $distrepo->{$ver}->{stage} if $repos->{$repo}->{stage};
455 slords 1.71 my $tail = $repos->{$repo}->{os} ? "$osdir/" : 'RPMS/';
456 slords 1.30 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 slords 1.11 }
470 slords 1.30 qx(rm -f $src) if exists $pkg->{delete} && ! $opts{t};
471     } elsif ( $pkg->{delete} ) {
472 slords 1.34 print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n";
473 slords 1.31 qx(rm -f $src) unless $opts{t};
474 slords 1.30 $repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage};
475 slords 1.42 if ( $repos->{$pkg->{repo}}->{orig} && ! $repos->{$pkg->{repo}}->{base} ) {
476 slords 1.52 my $tag = sprintf '%s%s/%s-%s', $distrepo->{$ver}->{$pkg->{repo}}, $pkg->{name}, $pkg->{ver}, $pkg->{rel};
477 slords 1.45 qx(rm -f $tag/PUSHED) if ! $opts{t} && -d $tag && -f "$tag/PUSHED";
478 slords 1.42 }
479 slords 1.20 }
480     }
481 slords 1.59
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 slords 1.67 if ( ! $print && ($pkg->{delete} || $pkg->{repos} || ( $pkg->{nosig} && $distrepo->{$ver}->{sign} ) ) ) {
488 slords 1.59 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 slords 1.30 }
497    
498     if ( %repochg ) {
499 slords 1.52 print "\nrebuild repo ($disttag$ver)\n", "=" x length("rebuild repo ($disttag$ver)"), "\n";
500 slords 1.30 }
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 slords 1.52 my $dir = $distrepo->{$ver}->{repo} . "$repo/$arch";
505 slords 1.30 $dir = qx(readlink -f $dir);
506 slords 1.71 if ( $dir ) {
507     chomp $dir;
508     } else {
509     $dir = $distrepo->{$ver}->{repo} . "$repo/$arch";
510     }
511 slords 1.30 print "rebuild $repo/$arch\n";
512     unless ( $opts{t} ) {
513 slords 1.66 my $checksum = "--checksum $distrepo->{$ver}->{checksum}";
514    
515     my $exclude = "";
516 slords 1.71 $exclude .= " --exclude ${osdir}/*" if -d "$dir/Packages";
517 slords 1.72 $exclude .= " --exclude *smeserver-release*.rpm" if $dir =~ m{test/|-testing/};
518 slords 1.66
519     my $groupfile = "";
520 slords 1.72 $groupfile = "--simple-md-filenames --groupfile repodata/comps.xml" if -f "$dir/repodata/comps.xml";
521 slords 1.66
522     qx(createrepo --update --database --exclude *.src.rpm --exclude *-debuginfo-*.rpm $checksum $exclude $groupfile $dir);
523 slords 1.20 qx(repoview $dir);
524 slords 1.66
525 slords 1.20 qx(rm -rf $dir/.olddata) if -d "$dir/.olddata";
526     qx(rm -rf $dir/.repodata) if -d "$dir/.repodata";
527 slords 1.60 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 slords 1.20 }
531 slords 1.11 }
532 slords 1.20 }
533 slords 1.30 unless ( $opts{t} ) {
534 slords 1.71 foreach (@{$distrepo->{$ver}->{builds}})
535     {
536     finddepth(sub{rmdir}, "$_") if -d "$_";
537     }
538 slords 1.53 finddepth(sub{rmdir}, $distrepo->{$ver}->{community}) if -d "$distrepo->{$ver}->{community}";
539 slords 1.30 }
540 slords 1.1 }
541    
542 slords 1.30 sub verrel {
543     my $pkg = shift;
544     my $repo = shift;
545     my $counts = shift;
546 slords 1.20
547 slords 1.31 return 0 if $pkg->{src};
548 slords 1.30 $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 slords 1.20 }
553    
554 slords 1.30 sub pkgdest {
555 slords 1.20 my $pkg = shift;
556 slords 1.30 my $dest = shift;
557     my $hirepo = shift;
558     my $pkgs = shift;
559    
560     foreach my $cmp ( @$pkgs ) {
561 slords 1.31 next if $cmp->{src} || $repos->{$cmp->{repo}}->{prio} <= $repos->{$dest}->{prio};
562     next if $pkg->{name} ne ( $pkg->{src} ? $cmp->{base} : $cmp->{name} );
563 slords 1.30 if ( $repos->{$cmp->{repo}}->{prio} > $repos->{$hirepo}->{prio} ) {
564     $dest = $hirepo;
565     last;
566 slords 1.20 } else {
567 slords 1.30 $dest = $cmp->{repo};
568 slords 1.20 }
569     }
570 slords 1.30 return $dest;
571 slords 1.20 }
572    
573 slords 1.30 sub process_rpm {
574     my $rpm = shift;
575 slords 1.52 my $ver = shift;
576 slords 1.30 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 slords 1.20
582     my $pkg;
583 slords 1.30 eval { $pkg = RPM2->open_package($rpm, $rpm_flags); };
584     if ($@) { print " * corrupt package ($rpm)\n"; return; }
585 slords 1.20 eval { my $sig = $pkg->siggpg };
586 slords 1.72
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 slords 1.30 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 slords 1.52 return if $skippkg->{$ver}->{$repo} && ( $skippkg->{$ver}->{$repo}->{$src} || $skippkg->{$ver}->{$repo}->{$pkg->name} );
600 slords 1.71 return if $repos->{$repo}->{base} && $nosig && $baserepo->{$ver}->{sign};
601 slords 1.30 if ( $nosig && ! -f "$HOME/.rpmpass" ) { print " * missing signature (" .$pkg->filename . ")\n"; return; }
602 slords 1.34 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 slords 1.30
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 slords 1.34 arch => $arch,
615 slords 1.30 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 slords 1.26 }
626 slords 1.30 $sources{$src}++;
627 slords 1.20
628 slords 1.30 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 slords 1.20 }
633 slords 1.30 } elsif ( ( $repos->{$repo}->{prio} >= $repos->{$cmp->{repo}}->{prio} || ! $repos->{$cmp->{repo}}->{base} ) && $pkg ge $cmp->{rpm} ) {
634     $latest{$pkg->name} = $rpmhash;
635 slords 1.20 }
636 slords 1.1 }

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