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