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