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