/[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.70 - (hide annotations) (download)
Fri Jul 27 18:07:11 2012 UTC (12 years, 4 months ago) by slords
Branch: MAIN
Changes since 1.69: +9 -9 lines
Tools path change

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

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