/[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.19 - (hide annotations) (download)
Tue Oct 16 21:36:23 2007 UTC (17 years, 1 month ago) by slords
Branch: MAIN
Changes since 1.18: +3 -0 lines
updates

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.19 #$arch = 'x86_64';
21 slords 1.2
22     my @repos = (
23 slords 1.18 "$releasedir/$smerel/smeos/$arch/SME",
24     "$releasedir/$smerel/smeos/$arch/SME/RPMS",
25 slords 1.2 "$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 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 slords 1.18 "$stagedir/RPMS-$arch",
38 slords 1.2 );
39 slords 1.19 @repos = grep { ! m{/i[56]86$} } @repos if $arch eq 'x86_64';
40 slords 1.2
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 slords 1.13 "/mirrors/atrpms/src/el$centosrel-$arch/atrpms/testing",
49 slords 1.4 "/mirrors/fedora/epel/$centosrel/SRPMS",
50 slords 1.19 "/mirrors/fedora/epel/testing/$centosrel/SRPMS",
51 slords 1.2 "/mirrors/fedora/core/updates/$fedorarel/SRPMS",
52     "/mirrors/fedora/core/$fedorarel/source/SRPMS",
53     "/mirrors/fedora/extras/$fedorarel/SRPMS",
54     "$builds/SRPMS",
55     );
56 slords 1.1
57 slords 1.11 my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa;
58    
59     my @rpms;
60     my %srpms;
61     my %sources;
62 slords 1.1 my %changed;
63     my %copy;
64    
65 slords 1.18 print "\nReading repos...\n";
66 slords 1.1 foreach my $repo ( @repos ) {
67 slords 1.11 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 slords 1.18 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 slords 1.11 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 slords 1.18 print " - $repo\n";
94 slords 1.11 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 slords 1.1 }
116    
117 slords 1.18 print "\nReading source repos...\n";
118 slords 1.1 foreach my $repo ( reverse @srcrepos ) {
119 slords 1.2 my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo );
120     closedir SRPMS;
121 slords 1.1
122 slords 1.2 %sources = (%sources, %temp_repo);
123 slords 1.1 }
124    
125 slords 1.18 print "\nFinding latest packages...\n";
126 slords 1.11 my @latest;
127 slords 1.14 foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} !~ m{/sme(addons|contribs|dev|extras)$} } @rpms ) {
128 slords 1.11 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 slords 1.18 push @{$copy{"$stagedir/RPMS-$arch"}}, $rpm->{rpm}->filename;
132 slords 1.11 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 slords 1.14 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 slords 1.18 print "\nFinding development packages...\n";
155 slords 1.11 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 slords 1.1 }
178    
179 slords 1.11 foreach my $rpm ( grep { $_->{repo} =~ m{/smedev$} } @rpms ) {
180     $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @devel;
181 slords 1.2 }
182    
183 slords 1.18 print "\nFinding source packages...\n";
184 slords 1.11 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 slords 1.18 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 slords 1.11 }
209     $srpms{$repo}{$source}++;
210     $found++;
211     last;
212     }
213     }
214     print "Can't find source for ".$rpm->{rpm}->filename."\n" unless $found;
215 slords 1.1 }
216    
217 slords 1.11 my @remove;
218     foreach my $repo ( keys %srpms ) {
219     foreach my $rpm ( keys %{$srpms{$repo}} ) {
220     unless ( $srpms{$repo}{$rpm} ) {
221 slords 1.18 if ($repo eq $stagedir) {
222     push @remove, "$repo/SRPMS-$arch/$rpm";
223     } else {
224     push @remove, "$repo/SRPMS/$rpm";
225     $changed{$repo}++;
226     }
227 slords 1.11 }
228     }
229 slords 1.1 }
230    
231     print "\n";
232     foreach my $repo ( sort keys %copy ) {
233 slords 1.12 foreach my $rpm ( keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) {
234 slords 1.2 print "copying $rpm to $repo/\n";
235 slords 1.17 mkdir "$repo" unless -d "$repo";
236 slords 1.2 system(qw(cp --preserve=timestamps), $rpm, "$repo/");
237     }
238 slords 1.1 }
239    
240     print "\n";
241 slords 1.12 foreach my $rpm ( keys %{{ map { $_ => 1 } (@remove, map { $_->{rpm}->filename } grep { $_->{repo} eq 'deleted' } @rpms) }} ) {
242 slords 1.2 print "removing $rpm\n";
243     unlink $rpm;
244 slords 1.1 }
245    
246     print "\n";
247     foreach my $repo ( sort keys %changed ) {
248 slords 1.7 my $dir=`readlink -f $repo/$arch`;
249     chomp $dir;
250     print "rebuilding $dir...\n";
251     system(qw(createrepo), "$dir");
252 slords 1.17 system(qw(rm -rf), "$dir/.olddata") if -d "$dir/.olddata";
253 slords 1.7 system(qw(repoview), "$dir");
254 slords 1.17 system(qw(rm -rf), "$dir/.repodata") if "$dir/.repodata";
255 slords 1.1 }

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