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