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