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