3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use RPM2; |
use RPM2; |
6 |
|
use File::Find; |
7 |
|
use File::Basename; |
8 |
|
use Getopt::Std; |
9 |
use Data::Dumper; |
use Data::Dumper; |
10 |
|
|
11 |
sub compare($$); |
delete $ENV{PATH}; |
12 |
|
my $HOME=$ENV{HOME}; |
13 |
my $releases = 2; |
umask 002; |
14 |
|
$| = 1; |
15 |
my $rpm_flags = RPM2->vsf_nodsa; |
|
16 |
my $repodir = '/releases/7'; |
my %opts; |
17 |
my $stagedir = '/builds'; |
getopts( 'osqtr:', \%opts ); |
18 |
my @repos = qw( |
$opts{r} ||= ''; |
19 |
/releases/7/smeos/i386/CentOS/RPMS |
|
20 |
/releases/7/smeupdates/i386/RPMS |
my $rpm_flags = RPM2->vsf_nosha1header | RPM2->vsf_nomd5header | RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader; |
21 |
/releases/7/smeupdates-testing/i386/RPMS |
$rpm_flags |= RPM2->vsf_nosha1 | RPM2->vsf_nomd5 | RPM2->vsf_nodsa | RPM2->vsf_norsa; |
22 |
/releases/7/smeextras/i386/RPMS |
|
23 |
/releases/7/smeaddons/i386/RPMS |
my @archs = ( 'i386', 'x86_64' ); |
24 |
/releases/7/smetest/i386/RPMS |
|
25 |
/releases/7/smedev/i386/RPMS |
my $distrepo = { '7' => { active => 1, |
26 |
/builds/rpms/RPMS/i386 |
centos => 4, |
27 |
/builds/rpms/RPMS/i586 |
fedora => 3, |
28 |
/builds/rpms/RPMS/i686 |
repo => '/releases/7/', |
29 |
/builds/rpms/RPMS/noarch |
os => 'RPMS/', |
30 |
/builds/RPMS |
builds => '/builds/smeserver-7-core/', |
31 |
); |
contribs => '/builds/smeserver-7-contribs/', |
32 |
my $devrepo = (grep { m{/sme} } reverse @repos)[0]; |
qa => '/builds/smeserver-7-qa/', |
33 |
|
stage => '/stage/7/', |
34 |
my @srcrepos = qw( |
}, |
35 |
/mirrors/centos/4/fasttrack/SRPMS |
'8' => { active => 1, |
36 |
/mirrors/centos/4/updates/SRPMS |
centos => 5, |
37 |
/mirrors/centos/4/os/SRPMS |
fedora => 6, |
38 |
/mirrors/centos/4/extras/SRPMS |
repo => '/releases/testing/8/', |
39 |
/mirrors/rpmforge/dag/source |
os => '', |
40 |
/mirrors/atrpms/src/el4-i386/atrpms/stable |
builds => '/builds/smeserver-8-core/', |
41 |
/builds/rpms/SRPMS |
contribs => '/builds/smeserver-8-contribs/', |
42 |
); |
qa => '/builds/smeserver-8-qa/', |
43 |
|
stage => '/stage/8/', |
44 |
my %repohash; |
}, |
45 |
my %srcrepohash; |
}; |
46 |
my %changed; |
|
47 |
my %copy; |
my $repos = { 'smeos' => { prio => 18, inc => 1, ver => 1, rel => 1, os => 1 }, |
48 |
my @remove; |
'smeupdates' => { prio => 17, inc => 1, ver => 1, rel => 1 }, |
49 |
|
'smeupdates-testing' => { prio => 16, inc => 1, ver => 1, rel => 1 }, |
50 |
%{$srcrepohash{$stagedir}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$stagedir/SRPMS" ); |
'smeextras' => { prio => 15, inc => 0, ver => 1, rel => 1 }, |
51 |
closedir SRPMS; |
'smeaddons' => { prio => 14, inc => 0, ver => 1, rel => 1 }, |
52 |
|
'smecontribs' => { prio => 13, inc => 0, ver => 1, rel => 1 }, |
53 |
print "\n"; |
'smetest' => { prio => 12, inc => 0, ver => 2, rel => 2, devel => 2 }, |
54 |
foreach my $repo ( @repos ) { |
'smedev' => { prio => 11, inc => 0, ver => 2, rel => 2, devel => 1 }, |
55 |
if ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
'centos' => { prio => 10, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
56 |
my $srcrepo = $1; |
'epel' => { prio => 9, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
57 |
|
'fedora-extras' => { prio => 8, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
58 |
%{$srcrepohash{$srcrepo}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$srcrepo/SRPMS" ); |
'rpmforge' => { prio => 7, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
59 |
closedir SRPMS; |
'atrpms' => { prio => 6, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
60 |
} |
'fedora' => { prio => 5, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
61 |
|
'builds' => { prio => 4, inc => 0, ver => 0, rel => 0, orig => 1 }, |
62 |
opendir RPMS, $repo; |
'contribs' => { prio => 2, inc => 0, ver => 0, rel => 0, orig => 1 }, |
63 |
foreach my $rpm ( grep { m{\.rpm} } readdir RPMS ) { |
'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 }, |
64 |
my $header = RPM2->open_package("$repo/$rpm", $rpm_flags); |
}; |
65 |
my $pkg = $header->tag("NAME").".".$header->tag("ARCH"); |
|
66 |
if ( $repo =~ m{/builds/RPMS} ) { |
my $baserepo = { '~Ssmeos/~A/SME/~O' => 'smeos', |
67 |
push @{$repohash{$pkg}{$stagedir}}, $header; |
'~Ssmeupdates/~A/RPMS/' => 'smeupdates', |
68 |
} elsif ( $repo =~ m{/builds/} ) { |
'~Ssmeupdates-testing/~A/RPMS/' => 'smeupdates-testing', |
69 |
push @{$repohash{$pkg}{builds}}, $header; |
'~Ssmeextras/~A/RPMS/' => 'smeextras', |
70 |
} elsif ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
'~Ssmeaddons/~A/RPMS/' => 'smeaddons', |
71 |
my $pos = $1; |
'~Ssmecontribs/~A/RPMS/' => 'smecontribs', |
72 |
push @{$repohash{$pkg}{$pos}}, $header; |
'~Ssmetest/~A/RPMS/' => 'smetest', |
73 |
} |
'~Ssmedev/~A/RPMS/' => 'smedev', |
74 |
} |
'/stage/~s/~A/SME/~O' => 'stage', |
75 |
closedir RPMS; |
'/mirrors/centos/~C/fasttrack/~A/RPMS/' => 'centos', |
76 |
|
'/mirrors/centos/~C/updates/~A/RPMS/' => 'centos', |
77 |
|
'/mirrors/centos/~C/os/~A/CentOS/~O' => 'centos', |
78 |
|
'/mirrors/centos/~C/extras/~A/RPMS/' => 'centos', |
79 |
|
'/mirrors/fedora/epel/~C/~A/' => 'epel', |
80 |
|
'/mirrors/fedora/epel/testing/~C/~A/' => 'epel', |
81 |
|
'/mirrors/fedora/extras/~F/~A/' => 'fedora-extras', |
82 |
|
'/mirrors/rpmforge/dag/redhat/el~C/en/~A/dag/RPMS/' => 'rpmforge', |
83 |
|
'/mirrors/rpmforge/dag/source/' => 'rpmforge', |
84 |
|
'/mirrors/atrpms/el~C-~A/atrpms/stable/' => 'atrpms', |
85 |
|
'/mirrors/atrpms/el~C-~A/atrpms/testing/' => 'atrpms', |
86 |
|
'/mirrors/atrpms/src/el~C-~A/atrpms/stable/' => 'atrpms', |
87 |
|
'/mirrors/atrpms/src/el~C-~A/atrpms/testing/' => 'atrpms', |
88 |
|
'/mirrors/fedora/core/~F/~A/os/Fedora/RPMS/' => 'fedora', |
89 |
|
'/mirrors/fedora/core/updates/~F/~A/' => 'fedora', |
90 |
|
}; |
91 |
|
|
92 |
|
if ( $opts{q} ) { |
93 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/fasttrack/~A/RPMS/'} = 'centos'; |
94 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/updates/~A/RPMS/'} = 'centos'; |
95 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/os/~A/CentOS/~O'} = 'centos'; |
96 |
|
$baserepo->{'/mirrors/centos-qa/CentOS/~C/extras/~A/RPMS/'} = 'centos'; |
97 |
} |
} |
98 |
|
|
99 |
my %sources; |
my $skippkg = { '7' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3', 'vim' ) }, |
100 |
foreach my $repo ( reverse @srcrepos ) { |
'epel' => { map { $_ => 1 } ( 'clamav', 'perl-Razor-Agent' ) }, |
101 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo ); |
'rpmforge' => { map { $_ => 1 } ( 'perl-Test-Inline' ) }, |
102 |
closedir SRPMS; |
'atrpms' => { map { $_ => 1 } ( 'dovecot', 'trac', 'yum' ) }, |
103 |
|
}, |
104 |
%sources = (%sources, %temp_repo); |
'8' => { 'centos' => { map { $_ => 1 } ( 'horde', 'imp-h3', 'ingo-h3', 'turba-h3' ) }, |
105 |
} |
'fedora' => { map { $_ => 1 } ( 'kernel-xen' ) }, |
106 |
|
'epel' => { map { $_ => 1 } ( 'clamav', 'perl-Razor-Agent', 'smolt' ) }, |
107 |
|
'fedora-extras' => { map { $_ => 1 } ( 'dstat', 'gocr', 'horde', 'oidentd', 'perl-Test-Inline', 'perl-Razor-Agent', 'smolt' ) }, |
108 |
|
'rpmforge' => { map { $_ => 1 } ( 'perl-Test-Inline' ) }, |
109 |
|
}, |
110 |
|
}; |
111 |
|
|
112 |
|
my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos; |
113 |
|
my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos; |
114 |
|
$devel2 ||= $devel1; |
115 |
|
|
116 |
|
my ($rpms, %base, %latest, %sources); |
117 |
|
foreach my $smever ( sort { $a <=> $b } keys %$distrepo ) { |
118 |
|
next unless $distrepo->{$smever}->{active}; |
119 |
|
my %repochg = (); |
120 |
|
$rpms = (); |
121 |
|
%latest = (); |
122 |
|
%sources = (); |
123 |
|
%base = (); |
124 |
|
|
125 |
|
foreach my $dir ( sort { $repos->{$baserepo->{$b}}->{prio} <=> $repos->{$baserepo->{$a}}->{prio} || $a cmp $b } keys %$baserepo ) { |
126 |
|
my $bdir = $dir; |
127 |
|
$bdir =~ s/~O/$distrepo->{$smever}->{os}/; |
128 |
|
$bdir =~ s/~S/$distrepo->{$smever}->{repo}/; |
129 |
|
$bdir =~ s/~s/$smever/; |
130 |
|
$bdir =~ s/~C/$distrepo->{$smever}->{centos}/; |
131 |
|
$bdir =~ s/~F/$distrepo->{$smever}->{fedora}/; |
132 |
|
for my $arch ( @archs, 'SRPMS/' ) { |
133 |
|
my $adir = $bdir; |
134 |
|
if ( $arch eq 'SRPMS/' ) { |
135 |
|
$adir =~ s/~A.*/$arch/ if $arch eq 'SRPMS/'; |
136 |
|
} else { |
137 |
|
$adir =~ s/~A/$arch/; |
138 |
|
} |
139 |
|
opendir DIR, $adir or next; |
140 |
|
next unless -d $adir; |
141 |
|
process_rpm("$adir$_", $smever, $baserepo->{$dir}) foreach readdir DIR; |
142 |
|
closedir DIR; |
143 |
|
last unless $dir =~ m{~A}; |
144 |
|
} |
145 |
|
} |
146 |
|
find( { wanted => sub { process_rpm($_, $smever, 'builds'); }, no_chdir => 1, follow_fast => 1 }, ( $distrepo->{$smever}->{'builds'}, $distrepo->{$smever}->{'qa'} ) ); |
147 |
|
find( { wanted => sub { process_rpm($_, $smever, 'contribs'); }, no_chdir => 1, follow_fast => 1 }, $distrepo->{$smever}->{'contribs'} ); |
148 |
|
|
149 |
|
foreach my $base ( sort keys %$rpms ) { |
150 |
|
next unless $rpms->{$base}->{rpms}; |
151 |
|
my %track = (); |
152 |
|
my %seen = (); |
153 |
|
my %counts = (); |
154 |
|
my $acnt = (); |
155 |
|
my $print = 0; |
156 |
|
%latest = (); |
157 |
|
|
158 |
|
foreach my $pkg ( sort { $b->{rpm} cmp $a->{rpm} } @{$rpms->{$base}->{rpms}} ) { |
159 |
|
next if $pkg->{done}; |
160 |
|
|
161 |
|
my $tmp = $pkg->{svr}; |
162 |
|
SRC: { |
163 |
|
$rpms->{$base}->{vers}->{$tmp} && last SRC; |
164 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
165 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.at$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
166 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d(\.rf)$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
167 |
|
($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d(\.rf)$}{$1$2} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
168 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.rf$}{.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
169 |
|
($tmp = $pkg->{svr}) =~ s{(\d+)\.\d+\.el\d\.rf$}{$1.dag} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
170 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
171 |
|
($tmp = $pkg->{svr}) =~ s{(-\d+)\.\d+\.el\d$}{$1} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
172 |
|
($tmp = $pkg->{svr}) =~ s{\.centos\d$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
173 |
|
($tmp = $pkg->{svr}) =~ s{\.el\d\.sme$}{} && $rpms->{$base}->{vers}->{$tmp} && last SRC; |
174 |
|
} |
175 |
|
if ( $rpms->{$base}->{vers}->{$tmp} ) { |
176 |
|
foreach $tmp ( @{$rpms->{$base}->{vers}->{$tmp}} ) { |
177 |
|
$tmp->{svr} = $pkg->{svr}; |
178 |
|
push @{$rpms->{$base}->{rpms}}, $tmp unless $tmp->{added}; |
179 |
|
$tmp->{added}++; |
180 |
|
} |
181 |
|
} |
182 |
|
|
183 |
foreach my $pkg ( keys %repohash ) { |
my %orig = (); |
184 |
foreach my $repo ( @repos ) { |
my %pkgs = (); |
185 |
if ( $repo =~ m{/builds/RPMS} ) { |
my %reposrc = (); |
186 |
next unless $repohash{$pkg}{latest} || $repohash{$pkg}{$stagedir}; |
my $srpm = undef; |
187 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$stagedir}}; |
foreach my $cmp ( sort { $a->{src} <=> $b->{src} || $repos->{$b->{repo}}->{prio} <=> $repos->{$a->{repo}}->{prio} } @{$rpms->{$base}->{rpms}} ) { |
188 |
delete $repohash{$pkg}{$stagedir}; |
next unless $cmp->{svr} eq $pkg->{svr}; |
189 |
push @remove, map { $_->filename } @rest if @rest; |
|
190 |
if ( $repohash{$pkg}{latest} ) { |
if ( ! $track{repo} || $repos->{$cmp->{repo}}->{prio} > $repos->{$track{repo}}->{prio} ) { |
191 |
if ($repohash{$pkg}{latest} ne $latest ) { |
if ( $cmp->{src} ) { |
192 |
push @remove, $latest->filename; |
if ( ! $track{repo} ) { |
193 |
push @{$copy{"$stagedir/RPMS"}}, $repohash{$pkg}{latest}->filename; |
$cmp->{delete}++; |
194 |
$repohash{$pkg}{$stagedir} = $repohash{$pkg}{latest}; |
$cmp->{done}++; |
195 |
|
next; |
196 |
|
} |
197 |
|
} else { |
198 |
|
$track{repo} = $cmp->{repo}; |
199 |
|
$track{svr} = $cmp->{svr}; |
200 |
|
} |
201 |
|
} |
202 |
|
if ( $cmp->{svr} eq $track{svr} ) { |
203 |
|
if ( $seen{$cmp->{nvra}} ) { |
204 |
|
if ( $track{repo} ne $cmp->{repo} ) { |
205 |
|
if ($repos->{$cmp->{repo}}->{stage} ) { |
206 |
|
if ( $seen{$cmp->{nvra}}->{latest} ) { |
207 |
|
$seen{$cmp->{nvra}}->{latest}++; |
208 |
} else { |
} else { |
209 |
$repohash{$pkg}{$stagedir} = $latest; |
$cmp->{delete}++; |
210 |
} |
} |
211 |
} else { |
} elsif ( $repos->{$cmp->{repo}}->{orig}) { |
212 |
push @remove, $latest->filename; |
$orig{$cmp->{nvra}}++; |
213 |
|
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
214 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
215 |
|
} elsif ( $seen{$cmp->{nvra}}->{repo} ne $cmp->{repo} ) { |
216 |
|
$cmp->{delete}++; |
217 |
|
} |
218 |
} |
} |
219 |
} elsif ( $repo =~ m{^(.*/[0-9]+/sme[^/]*)/} ) { |
} elsif ($repos->{$cmp->{repo}}->{stage} ) { |
220 |
my $pos = $1; |
$cmp->{delete}++; |
221 |
next unless $repohash{$pkg}{$pos}; |
} else { |
222 |
if ( $pos =~ m{/smedev$} ) { |
$srpm = $cmp if ! $srpm && $cmp->{src}; |
223 |
next unless $repohash{$pkg}{latest}; |
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
224 |
my @rest = grep { $_ le $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
225 |
if ( @rest ) { |
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
226 |
push @remove, map { $_->filename } @rest; |
if ( $cmp->{repo} ne $dest ) { |
227 |
$changed{$pos}++; |
push @{$cmp->{repos}}, $dest; |
228 |
@{$repohash{$pkg}{$pos}} = grep { $_ gt $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
229 |
delete $repohash{$pkg}{$pos}; |
$orig{$cmp->{nvra}}++; |
230 |
} |
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
231 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
232 |
|
} else { |
233 |
|
$cmp->{delete}++; |
234 |
|
} |
235 |
|
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
236 |
|
$cmp->{repo} = $dest; |
237 |
|
$track{repo} = $dest unless $dest eq $track{repo}; |
238 |
|
} |
239 |
|
if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
240 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
241 |
|
} |
242 |
|
} |
243 |
|
} else { |
244 |
|
if ( $track{repo} eq $cmp->{repo} ) { |
245 |
|
if ( verrel($cmp, $cmp->{repo}, \%counts) ) { |
246 |
|
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
247 |
|
} elsif ( $cmp->{src} ) { |
248 |
|
$cmp->{delete}++ unless $repos->{$cmp->{repo}}->{base}; |
249 |
} else { |
} else { |
250 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$pos}}; |
$track{svr} = $cmp->{svr}; |
251 |
delete $repohash{$pkg}{$pos}; |
} |
252 |
if ( $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $latest ) { |
} elsif ( ! $repos->{$cmp->{repo}}->{base} ) { |
253 |
push @rest, $latest; |
if ( $repos->{$cmp->{repo}}->{orig} ) { |
254 |
|
$srpm = $cmp if ! $srpm && $cmp->{src}; |
255 |
|
my $dest = $repos->{$track{repo}}->{prio} > $repos->{$devel2}->{prio} ? $track{repo} : $devel2; |
256 |
|
$dest = pkgdest($cmp, $devel1, $dest, $rpms->{$base}->{rpms}); |
257 |
|
$dest = $devel1 if verrel($cmp, $dest, \%counts); |
258 |
|
unless ( verrel($cmp, $dest, \%counts) ) { |
259 |
|
push @{$cmp->{repos}}, $dest; |
260 |
|
if ( $repos->{$cmp->{repo}}->{orig} ) { |
261 |
|
$orig{$cmp->{nvra}}++; |
262 |
|
} elsif ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
263 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
264 |
} else { |
} else { |
265 |
$repohash{$pkg}{latest} = $latest; |
$cmp->{delete}++; |
|
$repohash{$pkg}{$pos} = $latest; |
|
266 |
} |
} |
267 |
if ( @rest ) { |
$cmp->{oldrepo} = $cmp->{repo} unless $cmp->{oldrepo}; |
268 |
push @remove, map { $_->filename } @rest; |
$cmp->{repo} = $dest; |
269 |
$changed{$pos}++; |
if ( $cmp->{src} && $reposrc{$cmp->{repo}} ) { |
270 |
|
$reposrc{$cmp->{repo}}->{srpm} = $cmp; |
271 |
} |
} |
272 |
|
} else { |
273 |
|
$cmp->{delete}++; |
274 |
|
} |
275 |
|
} else { |
276 |
|
$cmp->{delete}++; |
277 |
} |
} |
278 |
|
} |
279 |
|
} |
280 |
|
unless ( $repos->{$cmp->{repo}}->{orig} || ( $cmp->{delete} && ! $cmp->{repos} ) ) { |
281 |
|
$pkgs{$cmp->{nvra}}++; |
282 |
|
$latest{$cmp->{base}} = $cmp->{svr} if $repos->{$cmp->{repo}}->{inc} && ! $latest{$cmp->{base}}; |
283 |
|
$reposrc{$cmp->{repo}} = $cmp unless $reposrc{$cmp->{repo}} || $cmp->{src} || $repos->{$cmp->{repo}}->{stage}; |
284 |
|
unless ( $seen{$cmp->{nvra}} ) { |
285 |
|
$seen{$cmp->{nvra}} = $cmp; |
286 |
|
$cmp->{latest}++ if $latest{$cmp->{base}} && $cmp->{svr} eq $latest{$cmp->{base}} && $repos->{$cmp->{repo}}->{inc}; |
287 |
|
} |
288 |
|
push @{$acnt->{$cmp->{repo}}->{$cmp->{rpm}->as_nvre}->{$cmp->{src} ? 'src' : $cmp->{rpm}->arch}}, $cmp; |
289 |
} |
} |
290 |
|
$cmp->{done}++; |
291 |
|
} |
292 |
|
if ( $srpm ) { |
293 |
|
foreach my $r ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %reposrc ) { |
294 |
|
unless ( $reposrc{$r}->{srpm} ) { |
295 |
|
unshift @{$srpm->{repos}}, $r; |
296 |
|
$srpm->{oldrepo} = $srpm->{repo} unless $srpm->{oldrepo}; |
297 |
|
$srpm->{repo} = $r; |
298 |
|
$reposrc{$r}->{srpm} = $srpm; |
299 |
|
} |
300 |
|
} |
301 |
|
} elsif ( scalar keys %pkgs && $opts{s} ) { |
302 |
|
print "\n * missing source (sme$smever, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n"; |
303 |
|
} |
304 |
|
print "\n * missing originals (sme$smever, ", $pkg->{repo}, ", ", $pkg->{svr}, ")\n" if $opts{o} && scalar keys %orig != scalar keys %pkgs; |
305 |
} |
} |
|
} |
|
306 |
|
|
307 |
foreach my $pkg ( sort grep { $repohash{$_}{builds} } keys %repohash ) { |
foreach my $r ( keys %$acnt ) { |
308 |
my %versions = (); |
foreach my $p ( keys %{$acnt->{$r}} ) { |
309 |
foreach my $ver ( sort { $b cmp $a } @{$repohash{$pkg}{builds}} ) { |
foreach my $a ( keys %{$acnt->{$r}->{$p}} ) { |
310 |
next if $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $ver; |
if ( $a eq 'noarch' ) { |
311 |
|
my $p2 = ${$acnt->{$r}->{$p}->{$a}}[0]; |
312 |
$versions{$ver->tag("VERSION")}++; |
if ( ! $p2->{repos} && scalar @{$acnt->{$r}->{$p}->{$a}} != scalar @archs ) { |
313 |
if ( $versions{$ver->tag("VERSION")} > $releases || (scalar keys %versions) > $releases ) { |
$p2->{oldrepo} = $p2->{repo}; |
314 |
foreach my $rpm ( grep { $ver eq $_ } @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
push @{$p2->{repos}}, $p2->{repo}; |
|
push @remove, $rpm->filename; |
|
|
@{$repohash{$pkg}{"$repodir/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$repodir/smedev"}}; |
|
|
$changed{"$repodir/smedev"}++; |
|
|
} |
|
|
} else { |
|
|
print "Possible update " . $ver->filename . "\n" if $repohash{$pkg}{latest}; |
|
|
if ( ! grep { $ver eq $_ } @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
|
|
push @{$copy{$devrepo}}, $ver->filename; |
|
|
push @{$repohash{$pkg}{"$repodir/smedev"}}, $ver; |
|
|
$changed{"$repodir/smedev"}++; |
|
315 |
} |
} |
316 |
|
} elsif ( scalar @{$acnt->{$r}->{$p}->{$a}} != 1 ) { |
317 |
|
print "\n * many packages ($r, $a, $p)\n"; |
318 |
|
} |
319 |
} |
} |
320 |
|
} |
321 |
} |
} |
|
} |
|
322 |
|
|
323 |
foreach my $pkg ( grep { $repohash{$_}{"$repodir/smedev"} } keys %repohash ) { |
foreach my $pkg ( sort { $a->{nvra} cmp $b->{nvra} } @{$rpms->{$base}->{rpms}} ) { |
324 |
foreach my $rpm ( @{$repohash{$pkg}{"$repodir/smedev"}} ) { |
if ( $pkg->{latest} && $pkg->{latest} == 1 ) { |
325 |
unless ( grep { $rpm eq $_ } @{$repohash{$pkg}{builds}} ) { |
$pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo}; |
326 |
push @remove, $rpm->filename; |
$pkg->{repo} = $stage; |
327 |
@{$repohash{$pkg}{"$repodir/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$repodir/smedev"}}; |
push @{$pkg->{repos}}, $stage; |
328 |
$changed{"$repodir/smedev"}++; |
} |
329 |
|
if ( ! $print && ($pkg->{delete} || $pkg->{repos} || $pkg->{nosig} ) ) { |
330 |
|
print "\n$base (sme$smever)\n", "=" x length("$base (sme$smever)"), "\n"; |
331 |
|
$print++; |
332 |
|
} |
333 |
|
|
334 |
|
my $src = $pkg->{rpm}->filename; |
335 |
|
if ( $pkg->{nosig} ) { |
336 |
|
print "sign package (", basename($pkg->{rpm}->filename), ")\n"; |
337 |
|
unless ( $opts{t} ) { |
338 |
|
qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null); |
339 |
|
if ($?) { |
340 |
|
print " * failed to sign package\n"; |
341 |
|
next; |
342 |
|
} |
343 |
} |
} |
344 |
} |
} |
345 |
} |
|
346 |
|
if ( $pkg->{repos} ) { |
347 |
|
foreach my $repo ( @{$pkg->{repos}} ) { |
348 |
|
if ( $pkg->{delete} ) { |
349 |
|
print "move from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
350 |
|
$pkg->{delete} = 0; |
351 |
|
$repochg{$pkg->{oldrepo}}++ unless $repos->{$pkg->{oldrepo}}->{base} || $repos->{$pkg->{oldrepo}}->{stage}; |
352 |
|
} elsif ( $pkg->{oldrepo} eq $repo ) { |
353 |
|
print "distribute noarch in $repo (", basename($pkg->{rpm}->filename), ")\n"; |
354 |
|
} else { |
355 |
|
print "copy from ", $pkg->{oldrepo}, " to $repo (", basename($pkg->{rpm}->filename), ")\n"; |
356 |
|
} |
357 |
|
$repochg{$repo}++ unless $repos->{$repo}->{base} || $repos->{$repo}->{stage}; |
358 |
|
$pkg->{oldrepo} = $repo unless $pkg->{oldrepo} eq ${$pkg->{repos}}[0]; |
359 |
|
|
360 |
|
my @d = (); |
361 |
|
my $head = $distrepo->{$smever}->{repo} . $repo . '/'; |
362 |
|
$head = $distrepo->{$smever}->{stage} if $repos->{$repo}->{stage}; |
363 |
|
my $tail = $repos->{$repo}->{os} ? 'SME/' . $distrepo->{$smever}->{os} : 'RPMS/'; |
364 |
|
if ( $pkg->{src} ) { |
365 |
|
push @d, "${head}SRPMS/" . basename($pkg->{rpm}->filename); |
366 |
|
} elsif ( $pkg->{rpm}->arch eq 'noarch' ) { |
367 |
|
push @d, map { "${head}$_/$tail" . basename($pkg->{rpm}->filename) } @archs; |
368 |
|
} elsif ( $pkg->{rpm}->arch =~ m{^(i[356]86)$} ) { |
369 |
|
push @d, "${head}i386/$tail" . basename($pkg->{rpm}->filename); |
370 |
|
} else { |
371 |
|
push @d, $head . $pkg->{rpm}->arch . "/$tail" . basename($pkg->{rpm}->filename); |
372 |
|
} |
373 |
|
foreach my $dest ( @d ) { |
374 |
|
qx(cp --preserve=timestamps $src $dest) unless $opts{t} || -f "$dest"; |
375 |
|
} |
376 |
|
|
|
print "\n"; |
|
|
foreach my $repo ( sort keys %srcrepohash ) { |
|
|
foreach my $pkg ( sort grep { $repohash{$_}{$repo} } keys %repohash ) { |
|
|
my @rpms = ref($repohash{$pkg}{$repo}) eq "ARRAY" ? @{$repohash{$pkg}{$repo}} : ($repohash{$pkg}{$repo}); |
|
|
foreach my $rpm ( sort @rpms ) { |
|
|
my $src = $rpm->tag("SOURCERPM"); |
|
|
|
|
|
my @sources = (); |
|
|
push @sources, $src; |
|
|
push @sources, $src if ($src =~ s/\.2\.el4\.rf\./\.rf\./); |
|
|
push @sources, $src if ($src =~ s/\.el4\.rf\./\.rf\./); |
|
|
push @sources, $src if ($src =~ s/\.el4\.at\./\.at\./); |
|
|
push @sources, $src if ($src =~ s/\.rf\./\.dag\./); |
|
|
|
|
|
my $found = 0; |
|
|
foreach my $source ( @sources ) { |
|
|
if ( $sources{$source} ) { |
|
|
unless ( -f "$repo/SRPMS/$source" ) { |
|
|
push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source"; |
|
|
$changed{$repo}++; |
|
|
} |
|
|
$srcrepohash{$repo}{$source}++; |
|
|
$found++; |
|
|
last; |
|
|
} elsif ( -f "$repo/SRPMS/$source" ) { |
|
|
print "Found missing source $repo/SRPMS/$source for ".$rpm->as_nvre()."\n"; |
|
|
$srcrepohash{$repo}{$source}++; |
|
|
$found++; |
|
|
} |
|
|
} |
|
|
print "Can't find source for ".$rpm->as_nvre()."\n" unless $found; |
|
377 |
} |
} |
378 |
|
qx(rm -f $src) if exists $pkg->{delete} && ! $opts{t}; |
379 |
|
} elsif ( $pkg->{delete} ) { |
380 |
|
print "delete from ", $pkg->{repo}, " (", $pkg->{arch}, ", ", basename($pkg->{rpm}->filename), ")\n"; |
381 |
|
qx(rm -f $src) unless $opts{t}; |
382 |
|
$repochg{$pkg->{repo}}++ unless $repos->{$pkg->{repo}}->{base} || $repos->{$pkg->{repo}}->{stage}; |
383 |
|
} |
384 |
} |
} |
385 |
|
} |
386 |
|
|
387 |
foreach my $rpm ( keys %{$srcrepohash{$repo}} ) { |
if ( %repochg ) { |
388 |
unless ( $srcrepohash{$repo}{$rpm} ) { |
print "\nrebuild repo (sme$smever)\n", "=" x length("rebuild repo (sme$smever)"), "\n"; |
389 |
push @remove, "$repo/SRPMS/$rpm"; |
} |
390 |
$changed{$repo}++; |
foreach my $repo ( sort { $repos->{$b}->{prio} <=> $repos->{$a}->{prio} } keys %repochg ) { |
391 |
|
next if $repos->{$repo}->{orig} || $repos->{$repo}->{stage}; |
392 |
|
foreach my $arch ( @archs ) { |
393 |
|
my $dir = $distrepo->{$smever}->{repo} . "$repo/$arch"; |
394 |
|
$dir = qx(readlink -f $dir); |
395 |
|
chomp $dir; |
396 |
|
print "rebuild $repo/$arch\n"; |
397 |
|
unless ( $opts{t} ) { |
398 |
|
if ( -f "$dir/repodata/comps.xml" ) { |
399 |
|
qx(createrepo -g repodata/comps.xml $dir); |
400 |
|
} else { |
401 |
|
qx(createrepo $dir); |
402 |
} |
} |
403 |
|
qx(repoview $dir); |
404 |
|
qx(rm -rf $dir/.olddata) if -d "$dir/.olddata"; |
405 |
|
qx(rm -rf $dir/.repodata) if -d "$dir/.repodata"; |
406 |
|
} |
407 |
} |
} |
408 |
|
} |
409 |
|
unless ( $opts{t} ) { |
410 |
|
finddepth(sub{rmdir}, $distrepo->{$smever}->{$_}) foreach ('builds','contribs','qa'); |
411 |
|
} |
412 |
} |
} |
413 |
|
|
414 |
print "\n"; |
sub verrel { |
415 |
foreach my $repo ( sort keys %copy ) { |
my $pkg = shift; |
416 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) { |
my $repo = shift; |
417 |
print "copying $rpm to $repo/\n"; |
my $counts = shift; |
418 |
system(qw(cp --preserve=timestamps), $rpm, "$repo/"); |
|
419 |
} |
return 0 if $pkg->{src}; |
420 |
|
$counts->{$repo}->{$pkg->{ver}}->{$pkg->{rel}}++; |
421 |
|
return 1 if $repos->{$repo}->{ver} && scalar keys %{$counts->{$repo}} > $repos->{$repo}->{ver}; |
422 |
|
return 1 if $repos->{$repo}->{rel} && scalar keys %{$counts->{$repo}->{$pkg->{ver}}} > $repos->{$repo}->{rel}; |
423 |
|
return 0; |
424 |
} |
} |
425 |
|
|
426 |
print "\n"; |
sub pkgdest { |
427 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @remove }} ) { |
my $pkg = shift; |
428 |
print "removing $rpm\n"; |
my $dest = shift; |
429 |
unlink $rpm; |
my $hirepo = shift; |
430 |
|
my $pkgs = shift; |
431 |
|
|
432 |
|
foreach my $cmp ( @$pkgs ) { |
433 |
|
next if $cmp->{src} || $repos->{$cmp->{repo}}->{prio} <= $repos->{$dest}->{prio}; |
434 |
|
next if $pkg->{name} ne ( $pkg->{src} ? $cmp->{base} : $cmp->{name} ); |
435 |
|
if ( $repos->{$cmp->{repo}}->{prio} > $repos->{$hirepo}->{prio} ) { |
436 |
|
$dest = $hirepo; |
437 |
|
last; |
438 |
|
} else { |
439 |
|
$dest = $cmp->{repo}; |
440 |
|
} |
441 |
|
} |
442 |
|
return $dest; |
443 |
} |
} |
444 |
|
|
445 |
print "\n"; |
sub process_rpm { |
446 |
foreach my $repo ( sort keys %changed ) { |
my $rpm = shift; |
447 |
next if $repo =~ m{^/builds}; |
my $smever = shift; |
448 |
|
my $repo = shift; |
449 |
print "rebuilding $repo/i386...\n"; |
return unless $rpm =~ m{/([^/]*)-[^-]+-[^-]+\.\w+\.rpm$}; |
450 |
system(qw(createrepo), "$repo/i386"); |
my $base = $1; |
451 |
system(qw(repoview), "$repo/i386"); |
return unless ! $opts{r} || $base =~ m[$opts{r}]; |
452 |
|
return unless $latest{$base} || $sources{$base} || ! $repos->{$repo}->{base}; |
453 |
|
|
454 |
|
my $pkg; |
455 |
|
eval { $pkg = RPM2->open_package($rpm, $rpm_flags); }; |
456 |
|
if ($@) { print " * corrupt package ($rpm)\n"; return; } |
457 |
|
eval { my $sig = $pkg->siggpg }; |
458 |
|
my $nosig = ! $@; |
459 |
|
|
460 |
|
my $cmp = $latest{$pkg->name}; |
461 |
|
if ( $repos->{$repo}->{base} && ! $pkg->is_source_package ) { |
462 |
|
return unless $cmp; |
463 |
|
return if $repos->{$cmp->{repo}}->{base} && $repos->{$cmp->{repo}}->{prio} > $repos->{$repo}->{prio} && $pkg ge $cmp->{rpm}; |
464 |
|
} |
465 |
|
my ($src, $version, $release) = ($pkg->is_source_package ? $pkg->filename : $pkg->sourcerpm) =~ m{(?:^|/)([^/]*)-([^-]+)-([^-]+)\.\w+\.rpm$}; |
466 |
|
return if $skippkg->{$smever}->{$repo} && $skippkg->{$smever}->{$repo}->{$src}; |
467 |
|
return if $repos->{$repo}->{base} && $nosig; |
468 |
|
if ( $nosig && ! -f "$HOME/.rpmpass" ) { print " * missing signature (" .$pkg->filename . ")\n"; return; } |
469 |
|
my $arch = 'unknown'; |
470 |
|
$arch = 'SRPMS' if $pkg->filename =~ m{[/-](SRPMS?|src|source)/}; |
471 |
|
$arch = 'x86_64' if $pkg->filename =~ m{[/-]x86_64/}; |
472 |
|
$arch = 'i386' if $pkg->filename =~ m{[/-](i[356]86)/}; |
473 |
|
$arch = 'noarch' if $pkg->filename =~ m{[/-]noarch/}; |
474 |
|
|
475 |
|
my $rpmhash = { base => $src, |
476 |
|
name => $pkg->name, |
477 |
|
repo => $repo, |
478 |
|
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
479 |
|
svr => $src.'-'.$version.'-'.$release, |
480 |
|
src => $pkg->is_source_package, |
481 |
|
arch => $arch, |
482 |
|
ver => $version, |
483 |
|
rel => $release, |
484 |
|
rpm => $pkg, |
485 |
|
nosig => $nosig, |
486 |
|
}; |
487 |
|
if ( $pkg->is_source_package ) { |
488 |
|
push @{$rpms->{$src}->{srpms}}, $rpmhash; |
489 |
|
push @{$rpms->{$src}->{vers}->{$rpmhash->{svr}}}, $rpmhash; |
490 |
|
} else { |
491 |
|
push @{$rpms->{$src}->{rpms}}, $rpmhash; |
492 |
|
} |
493 |
|
$sources{$src}++; |
494 |
|
|
495 |
|
return if $pkg->is_source_package || $repos->{$repo}->{stage}; |
496 |
|
if ( ! $repos->{$repo}->{base} ) { |
497 |
|
if ( ! $cmp || $pkg gt $cmp->{rpm} ) { |
498 |
|
$latest{$pkg->name} = $rpmhash; |
499 |
|
} |
500 |
|
} elsif ( ( $repos->{$repo}->{prio} >= $repos->{$cmp->{repo}}->{prio} || ! $repos->{$cmp->{repo}}->{base} ) && $pkg ge $cmp->{rpm} ) { |
501 |
|
$latest{$pkg->name} = $rpmhash; |
502 |
|
} |
503 |
} |
} |