/[smeserver]/builds_bin/update_repos
ViewVC logotype

Annotation of /builds_bin/update_repos

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (hide annotations) (download)
Mon Apr 30 03:23:48 2007 UTC (17 years, 6 months ago) by slords
Branch: MAIN
Changes since 1.3: +1 -0 lines
Add epel repo

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

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed