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

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

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