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 |
slords |
1.5 |
"$releasedir/$smerel/smeos/$arch/SME/RPMS", |
23 |
|
|
"$releasedir/$smerel/smeos/$arch/RPMS", |
24 |
|
|
"$releasedir/$smerel/smeos/$arch/SME", |
25 |
slords |
1.2 |
"$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 |
slords |
1.4 |
"/mirrors/fedora/epel/$centosrel/SRPMS", |
46 |
slords |
1.2 |
"/mirrors/fedora/core/updates/$fedorarel/SRPMS", |
47 |
|
|
"/mirrors/fedora/core/$fedorarel/source/SRPMS", |
48 |
|
|
"/mirrors/fedora/extras/$fedorarel/SRPMS", |
49 |
|
|
"$builds/SRPMS", |
50 |
|
|
); |
51 |
slords |
1.1 |
|
52 |
|
|
my %repohash; |
53 |
|
|
my %srcrepohash; |
54 |
|
|
my %changed; |
55 |
|
|
my %copy; |
56 |
|
|
my @remove; |
57 |
|
|
|
58 |
slords |
1.2 |
my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa; |
59 |
|
|
|
60 |
slords |
1.1 |
%{$srcrepohash{$stagedir}} = map { $_ => 0 } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, "$stagedir/SRPMS" ); |
61 |
|
|
closedir SRPMS; |
62 |
|
|
|
63 |
|
|
foreach my $repo ( @repos ) { |
64 |
slords |
1.2 |
if ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) { |
65 |
|
|
my $srcrepo = $1; |
66 |
slords |
1.1 |
|
67 |
slords |
1.2 |
%{$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 |
slords |
1.1 |
} |
86 |
|
|
|
87 |
|
|
my %sources; |
88 |
|
|
foreach my $repo ( reverse @srcrepos ) { |
89 |
slords |
1.2 |
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo ); |
90 |
|
|
closedir SRPMS; |
91 |
slords |
1.1 |
|
92 |
slords |
1.2 |
%sources = (%sources, %temp_repo); |
93 |
slords |
1.1 |
} |
94 |
|
|
|
95 |
|
|
foreach my $pkg ( keys %repohash ) { |
96 |
slords |
1.2 |
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 |
slords |
1.6 |
} elsif ( ref($repohash{$pkg}{$pos}) eq 'ARRAY' ) { |
131 |
slords |
1.2 |
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 |
slords |
1.1 |
} |
147 |
|
|
|
148 |
slords |
1.2 |
print "\n"; |
149 |
slords |
1.1 |
foreach my $pkg ( sort grep { $repohash{$_}{builds} } keys %repohash ) { |
150 |
slords |
1.2 |
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 |
slords |
1.1 |
} |
181 |
|
|
|
182 |
|
|
print "\n"; |
183 |
|
|
foreach my $repo ( sort keys %srcrepohash ) { |
184 |
slords |
1.2 |
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 |
slords |
1.8 |
push @sources, $src if ($src =~ s/\.0\.el\d+\./\.at\./); |
197 |
|
|
push @sources, $src if ($src =~ s/\.el\d+\./\.at\./); |
198 |
|
|
|
199 |
slords |
1.2 |
|
200 |
|
|
my $found = 0; |
201 |
|
|
foreach my $source ( @sources ) { |
202 |
|
|
if ( $sources{$source} ) { |
203 |
|
|
unless ( -f "$repo/SRPMS/$source" ) { |
204 |
|
|
push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source"; |
205 |
|
|
$changed{$repo}++; |
206 |
|
|
} |
207 |
|
|
$srcrepohash{$repo}{$source}++; |
208 |
|
|
$found++; |
209 |
|
|
last; |
210 |
|
|
} elsif ( -f "$repo/SRPMS/$source" ) { |
211 |
|
|
print "Found missing source $repo/SRPMS/$source for ".$rpm->as_nvre()."\n"; |
212 |
|
|
$srcrepohash{$repo}{$source}++; |
213 |
|
|
$found++; |
214 |
|
|
} |
215 |
|
|
} |
216 |
|
|
print "Can't find source for ".$rpm->as_nvre()."\n" unless $found; |
217 |
|
|
} |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
foreach my $rpm ( keys %{$srcrepohash{$repo}} ) { |
221 |
|
|
unless ( $srcrepohash{$repo}{$rpm} ) { |
222 |
|
|
push @remove, "$repo/SRPMS/$rpm"; |
223 |
|
|
$changed{$repo}++; |
224 |
|
|
} |
225 |
|
|
} |
226 |
slords |
1.1 |
} |
227 |
|
|
|
228 |
|
|
print "\n"; |
229 |
|
|
foreach my $repo ( sort keys %copy ) { |
230 |
slords |
1.2 |
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) { |
231 |
|
|
print "copying $rpm to $repo/\n"; |
232 |
|
|
system(qw(cp --preserve=timestamps), $rpm, "$repo/"); |
233 |
|
|
} |
234 |
slords |
1.1 |
} |
235 |
|
|
|
236 |
|
|
print "\n"; |
237 |
|
|
foreach my $rpm ( sort keys %{{ map { $_ => 1 } @remove }} ) { |
238 |
slords |
1.2 |
print "removing $rpm\n"; |
239 |
|
|
unlink $rpm; |
240 |
slords |
1.1 |
} |
241 |
|
|
|
242 |
|
|
print "\n"; |
243 |
|
|
foreach my $repo ( sort keys %changed ) { |
244 |
slords |
1.2 |
next if $repo =~ m{^$stagedir}; |
245 |
slords |
1.1 |
|
246 |
slords |
1.7 |
my $dir=`readlink -f $repo/$arch`; |
247 |
|
|
chomp $dir; |
248 |
|
|
print "rebuilding $dir...\n"; |
249 |
|
|
system(qw(createrepo), "$dir"); |
250 |
|
|
system(qw(repoview), "$dir"); |
251 |
slords |
1.1 |
} |
252 |
slords |
1.2 |
|