1 |
#!/usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use RPM2; |
6 |
use Data::Dumper; |
7 |
|
8 |
sub compare($$); |
9 |
|
10 |
my $releases = 2; |
11 |
|
12 |
my $releasedir = '/releases'; |
13 |
my $smerel = '7'; |
14 |
my $arch = 'i386'; |
15 |
my $centosrel = '4'; |
16 |
my $fedorarel = '3'; |
17 |
my $builds = '/builds/rpms'; |
18 |
my $stagedir = '/builds'; |
19 |
|
20 |
my @repos = ( |
21 |
"$releasedir/$smerel/smeos/$arch/CentOS/RPMS", |
22 |
"$releasedir/$smerel/smeos/$arch/SME/RPMS", |
23 |
"$releasedir/$smerel/smeos/$arch/RPMS", |
24 |
"$releasedir/$smerel/smeos/$arch/SME", |
25 |
"$releasedir/$smerel/smeupdates/$arch/RPMS", |
26 |
"$releasedir/$smerel/smeupdates-testing/$arch/RPMS", |
27 |
"$releasedir/$smerel/smeextras/$arch/RPMS", |
28 |
"$releasedir/$smerel/smeaddons/$arch/RPMS", |
29 |
"$releasedir/$smerel/smetest/$arch/RPMS", |
30 |
"$releasedir/$smerel/smedev/$arch/RPMS", |
31 |
"$builds/RPMS/$arch", |
32 |
"$builds/RPMS/i586", |
33 |
"$builds/RPMS/i686", |
34 |
"$builds/RPMS/noarch", |
35 |
"$stagedir/RPMS", |
36 |
); |
37 |
|
38 |
my @srcrepos = ( |
39 |
"/mirrors/centos/$centosrel/fasttrack/SRPMS", |
40 |
"/mirrors/centos/$centosrel/updates/SRPMS", |
41 |
"/mirrors/centos/$centosrel/os/SRPMS", |
42 |
"/mirrors/centos/$centosrel/extras/SRPMS", |
43 |
"/mirrors/rpmforge/dag/source", |
44 |
"/mirrors/atrpms/src/el$centosrel-$arch/atrpms/stable", |
45 |
"/mirrors/fedora/epel/$centosrel/SRPMS", |
46 |
"/mirrors/fedora/core/updates/$fedorarel/SRPMS", |
47 |
"/mirrors/fedora/core/$fedorarel/source/SRPMS", |
48 |
"/mirrors/fedora/extras/$fedorarel/SRPMS", |
49 |
"$builds/SRPMS", |
50 |
); |
51 |
|
52 |
my %repohash; |
53 |
my %srcrepohash; |
54 |
my %changed; |
55 |
my %copy; |
56 |
my @remove; |
57 |
|
58 |
my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa; |
59 |
|
60 |
%{$srcrepohash{$stagedir}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$stagedir/SRPMS" ); |
61 |
closedir SRPMS; |
62 |
|
63 |
foreach my $repo ( @repos ) { |
64 |
if ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) { |
65 |
my $srcrepo = $1; |
66 |
|
67 |
%{$srcrepohash{$srcrepo}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$srcrepo/SRPMS" ); |
68 |
closedir SRPMS; |
69 |
} |
70 |
|
71 |
opendir RPMS, $repo; |
72 |
foreach my $rpm ( grep { m{\.rpm} } readdir RPMS ) { |
73 |
my $header = RPM2->open_package("$repo/$rpm", $rpm_flags); |
74 |
my $pkg = $header->tag("NAME").".".$header->tag("ARCH"); |
75 |
if ( $repo =~ m{$stagedir/RPMS} ) { |
76 |
push @{$repohash{$pkg}{$stagedir}}, $header; |
77 |
} elsif ( $repo =~ m{$builds/RPMS} ) { |
78 |
push @{$repohash{$pkg}{builds}}, $header; |
79 |
} elsif ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) { |
80 |
my $pos = $1; |
81 |
push @{$repohash{$pkg}{$pos}}, $header; |
82 |
} |
83 |
} |
84 |
closedir RPMS; |
85 |
} |
86 |
|
87 |
my %sources; |
88 |
foreach my $repo ( reverse @srcrepos ) { |
89 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo ); |
90 |
closedir SRPMS; |
91 |
|
92 |
%sources = (%sources, %temp_repo); |
93 |
} |
94 |
|
95 |
foreach my $pkg ( keys %repohash ) { |
96 |
foreach my $repo ( @repos ) { |
97 |
if ( $repo =~ m{$stagedir/RPMS} ) { |
98 |
next unless $repohash{$pkg}; |
99 |
if ( $repohash{$pkg}{$stagedir} ) { |
100 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$stagedir}}; |
101 |
delete $repohash{$pkg}{$stagedir}; |
102 |
push @remove, map { $_->filename } @rest if @rest; |
103 |
if ( $repohash{$pkg}{latest} ) { |
104 |
if ($repohash{$pkg}{latest} ne $latest ) { |
105 |
push @remove, $latest->filename; |
106 |
push @{$copy{"$stagedir/RPMS"}}, $repohash{$pkg}{latest}->filename; |
107 |
$repohash{$pkg}{$stagedir} = $repohash{$pkg}{latest}; |
108 |
} else { |
109 |
$repohash{$pkg}{$stagedir} = $latest; |
110 |
} |
111 |
} else { |
112 |
push @remove, $latest->filename; |
113 |
} |
114 |
} elsif ( $repohash{$pkg}{latest} ) { |
115 |
push @{$copy{"$stagedir/RPMS"}}, $repohash{$pkg}{latest}->filename; |
116 |
$repohash{$pkg}{$stagedir} = $repohash{$pkg}{latest}; |
117 |
} |
118 |
} elsif ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) { |
119 |
my $pos = $1; |
120 |
next unless $repohash{$pkg}{$pos}; |
121 |
if ( $pos =~ m{/smedev$} ) { |
122 |
next unless $repohash{$pkg}{latest}; |
123 |
my @rest = grep { $_ le $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
124 |
if ( @rest ) { |
125 |
push @remove, map { $_->filename } @rest; |
126 |
$changed{$pos}++; |
127 |
@{$repohash{$pkg}{$pos}} = grep { $_ gt $repohash{$pkg}{latest} } @{$repohash{$pkg}{$pos}}; |
128 |
delete $repohash{$pkg}{$pos}; |
129 |
} |
130 |
} elsif ( ref($repohash{$pkg}{$pos}) eq 'ARRAY' ) { |
131 |
my ($latest, @rest) = sort { $b cmp $a } @{$repohash{$pkg}{$pos}}; |
132 |
delete $repohash{$pkg}{$pos}; |
133 |
if ( $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $latest ) { |
134 |
push @rest, $latest; |
135 |
} else { |
136 |
$repohash{$pkg}{latest} = $latest; |
137 |
$repohash{$pkg}{$pos} = $latest; |
138 |
} |
139 |
if ( @rest ) { |
140 |
push @remove, map { $_->filename } @rest; |
141 |
$changed{$pos}++; |
142 |
} |
143 |
} |
144 |
} |
145 |
} |
146 |
} |
147 |
|
148 |
print "\n"; |
149 |
foreach my $pkg ( sort grep { $repohash{$_}{builds} } keys %repohash ) { |
150 |
my %versions = (); |
151 |
foreach my $ver ( sort { $b cmp $a } @{$repohash{$pkg}{builds}} ) { |
152 |
next if $repohash{$pkg}{latest} && $repohash{$pkg}{latest} ge $ver; |
153 |
|
154 |
$versions{$ver->tag("VERSION")}++; |
155 |
if ( $versions{$ver->tag("VERSION")} > $releases || (scalar keys %versions) > $releases ) { |
156 |
foreach my $rpm ( grep { $ver eq $_ } @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}} ) { |
157 |
push @remove, $rpm->filename; |
158 |
@{$repohash{$pkg}{"$releasedir/$smerel/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}}; |
159 |
$changed{"$releasedir/$smerel/smedev"}++; |
160 |
} |
161 |
} else { |
162 |
print "Possible update " . $ver->filename . "\n" if $repohash{$pkg}{latest}; |
163 |
if ( ! grep { $ver eq $_ } @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}} ) { |
164 |
push @{$copy{"$releasedir/$smerel/smedev/$arch/RPMS"}}, $ver->filename; |
165 |
push @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}}, $ver; |
166 |
$changed{"$releasedir/$smerel/smedev"}++; |
167 |
} |
168 |
} |
169 |
} |
170 |
} |
171 |
|
172 |
foreach my $pkg ( grep { $repohash{$_}{"$releasedir/$smerel/smedev"} } keys %repohash ) { |
173 |
foreach my $rpm ( @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}} ) { |
174 |
unless ( grep { $rpm eq $_ } @{$repohash{$pkg}{builds}} ) { |
175 |
push @remove, $rpm->filename; |
176 |
@{$repohash{$pkg}{"$releasedir/$smerel/smedev"}} = grep { $rpm ne $_ } @{$repohash{$pkg}{"$releasedir/$smerel/smedev"}}; |
177 |
$changed{"$releasedir/$smerel/smedev"}++; |
178 |
} |
179 |
} |
180 |
} |
181 |
|
182 |
print "\n"; |
183 |
foreach my $repo ( sort keys %srcrepohash ) { |
184 |
foreach my $pkg ( sort grep { $repohash{$_}{$repo} } keys %repohash ) { |
185 |
my @rpms = ref($repohash{$pkg}{$repo}) eq "ARRAY" ? @{$repohash{$pkg}{$repo}} : ($repohash{$pkg}{$repo}); |
186 |
foreach my $rpm ( sort @rpms ) { |
187 |
my $src = $rpm->tag("SOURCERPM"); |
188 |
|
189 |
my @sources = (); |
190 |
push @sources, $src; |
191 |
push @sources, $src if ($src =~ s/\.\d+\.el\d+\.rf\./\.rf\./); |
192 |
push @sources, $src if ($src =~ s/\.el\d\.rf\./\.rf\./); |
193 |
push @sources, $src if ($src =~ s/\.el\d\.at\./\.at\./); |
194 |
push @sources, $src if ($src =~ s/\.fc\d\.at\./\.at\./); |
195 |
push @sources, $src if ($src =~ s/\.rf\./\.dag\./); |
196 |
|
197 |
my $found = 0; |
198 |
foreach my $source ( @sources ) { |
199 |
if ( $sources{$source} ) { |
200 |
unless ( -f "$repo/SRPMS/$source" ) { |
201 |
push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source"; |
202 |
$changed{$repo}++; |
203 |
} |
204 |
$srcrepohash{$repo}{$source}++; |
205 |
$found++; |
206 |
last; |
207 |
} elsif ( -f "$repo/SRPMS/$source" ) { |
208 |
print "Found missing source $repo/SRPMS/$source for ".$rpm->as_nvre()."\n"; |
209 |
$srcrepohash{$repo}{$source}++; |
210 |
$found++; |
211 |
} |
212 |
} |
213 |
print "Can't find source for ".$rpm->as_nvre()."\n" unless $found; |
214 |
} |
215 |
} |
216 |
|
217 |
foreach my $rpm ( keys %{$srcrepohash{$repo}} ) { |
218 |
unless ( $srcrepohash{$repo}{$rpm} ) { |
219 |
push @remove, "$repo/SRPMS/$rpm"; |
220 |
$changed{$repo}++; |
221 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
print "\n"; |
226 |
foreach my $repo ( sort keys %copy ) { |
227 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) { |
228 |
print "copying $rpm to $repo/\n"; |
229 |
system(qw(cp --preserve=timestamps), $rpm, "$repo/"); |
230 |
} |
231 |
} |
232 |
|
233 |
print "\n"; |
234 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @remove }} ) { |
235 |
print "removing $rpm\n"; |
236 |
unlink $rpm; |
237 |
} |
238 |
|
239 |
print "\n"; |
240 |
foreach my $repo ( sort keys %changed ) { |
241 |
next if $repo =~ m{^$stagedir}; |
242 |
|
243 |
my $dir=`readlink -f $repo/$arch`; |
244 |
chomp $dir; |
245 |
print "rebuilding $dir...\n"; |
246 |
system(qw(createrepo), "$dir"); |
247 |
system(qw(repoview), "$dir"); |
248 |
} |
249 |
|