/[smeserver]/builds_bin/update_repos
ViewVC logotype

Contents of /builds_bin/update_repos

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


Revision 1.18 - (show annotations) (download)
Thu Jul 19 19:59:15 2007 UTC (17 years, 4 months ago) by slords
Branch: MAIN
Changes since 1.17: +31 -12 lines
Tools update

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 $releasedir = '/releases';
13 my $smerel = '7';
14 my $centosrel = '4';
15 my $fedorarel = '3';
16 my $builds = '/builds/rpms';
17 my $stagedir = '/builds';
18 my $arch = `uname -i`;
19 chomp $arch;
20
21 my @repos = (
22 "$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",
26 "$releasedir/$smerel/smeupdates-testing/$arch/RPMS",
27 "$releasedir/$smerel/smeextras/$arch/RPMS",
28 "$releasedir/$smerel/smeaddons/$arch/RPMS",
29 "$releasedir/$smerel/smecontribs/$arch/RPMS",
30 "$releasedir/$smerel/smetest/$arch/RPMS",
31 "$releasedir/$smerel/smedev/$arch/RPMS",
32 "$builds/RPMS/$arch",
33 "$builds/RPMS/i586",
34 "$builds/RPMS/i686",
35 "$builds/RPMS/noarch",
36 "$stagedir/RPMS-$arch",
37 );
38
39 my @srcrepos = (
40 "/mirrors/centos/$centosrel/fasttrack/SRPMS",
41 "/mirrors/centos/$centosrel/updates/SRPMS",
42 "/mirrors/centos/$centosrel/os/SRPMS",
43 "/mirrors/centos/$centosrel/extras/SRPMS",
44 "/mirrors/rpmforge/dag/source",
45 "/mirrors/atrpms/src/el$centosrel-$arch/atrpms/stable",
46 "/mirrors/atrpms/src/el$centosrel-$arch/atrpms/testing",
47 "/mirrors/fedora/epel/$centosrel/SRPMS",
48 "/mirrors/fedora/core/updates/$fedorarel/SRPMS",
49 "/mirrors/fedora/core/$fedorarel/source/SRPMS",
50 "/mirrors/fedora/extras/$fedorarel/SRPMS",
51 "$builds/SRPMS",
52 );
53
54 my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa;
55
56 my @rpms;
57 my %srpms;
58 my %sources;
59 my %changed;
60 my %copy;
61
62 print "\nReading repos...\n";
63 foreach my $repo ( @repos ) {
64 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 eq $stagedir ) {
74 opendir SRPMS, "$r/SRPMS-$arch" or next;
75 foreach my $srpm ( grep { /\.rpm$/ } readdir SRPMS ) {
76 $srpms{$r}{$srpm} = 0;
77 $sources{$srpm} = "$r/SRPMS-$arch";
78 }
79 closedir SRPMS;
80 } elsif ( $r ne 'builds' ) {
81 opendir SRPMS, "$r/SRPMS" or next;
82 foreach my $srpm ( grep { /\.rpm$/ } readdir SRPMS ) {
83 $srpms{$r}{$srpm} = 0;
84 $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 print "\nReading source repos...\n";
115 foreach my $repo ( reverse @srcrepos ) {
116 my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo );
117 closedir SRPMS;
118
119 %sources = (%sources, %temp_repo);
120 }
121
122 print "\nFinding latest packages...\n";
123 my @latest;
124 foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} !~ m{/sme(addons|contribs|dev|extras)$} } @rpms ) {
125 unless ( grep { $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @latest ) {
126 push @latest, $rpm;
127 unless ( grep { $_->{repo} eq $stagedir && $_->{filename} eq $rpm->{filename} } @rpms ) {
128 push @{$copy{"$stagedir/RPMS-$arch"}}, $rpm->{rpm}->filename;
129 push @rpms, { name => $rpm->{name},
130 filename => $rpm->{filename},
131 version => $rpm->{version},
132 release => $rpm->{release},
133 repo => $stagedir,
134 rpm => $rpm->{rpm},
135 source => $rpm->{source}
136 };
137 }
138 }
139 }
140
141 foreach my $rpm ( grep { $_->{repo} eq $stagedir } @rpms ) {
142 $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @latest;
143 }
144
145 foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} =~ m{/sme(addons|contribs|extras)$} } @rpms ) {
146 unless ( grep { $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @latest ) {
147 push @latest, $rpm;
148 }
149 }
150
151 print "\nFinding development packages...\n";
152 my @devel;
153 my %versions;
154 foreach my $rpm ( grep { $_->{repo} eq 'builds' } @rpms ) {
155 next if grep { $_->{name} eq $rpm->{name} && $_->{rpm} ge $rpm->{rpm} } @latest;
156
157 $versions{$rpm->{name}}{$rpm->{version}}++ unless grep { $_->{name} eq $rpm->{name} && $_->{rpm} eq $rpm->{rpm} } @devel;
158 next if $versions{$rpm->{name}}{$rpm->{version}} > $releases || scalar keys %{$versions{$rpm->{name}}} > $releases;
159 print "Possible update " . $rpm->{rpm}->filename . "\n" if grep { $_->{name} eq $rpm->{name} } @latest;
160
161 push @devel, $rpm;
162 unless ( grep { $_->{repo} =~ m{/smedev$} && $_->{filename} eq $rpm->{filename} } @rpms ) {
163 push @{$copy{"$releasedir/$smerel/smedev/$arch/RPMS"}}, $rpm->{rpm}->filename;
164 $changed{"$releasedir/$smerel/smedev"}++;
165 push @rpms, { name => $rpm->{name},
166 filename => $rpm->{filename},
167 version => $rpm->{version},
168 release => $rpm->{release},
169 repo => "$releasedir/$smerel/smedev",
170 rpm => $rpm->{rpm},
171 source => $rpm->{source}
172 };
173 }
174 }
175
176 foreach my $rpm ( grep { $_->{repo} =~ m{/smedev$} } @rpms ) {
177 $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @devel;
178 }
179
180 print "\nFinding source packages...\n";
181 foreach my $rpm ( grep { $_->{repo} !~ m{^(builds|deleted)$} } @rpms ) {
182 my $src;
183 my $srpm = $rpm->{rpm}->tag("SOURCERPM");
184
185 my @sources = ();
186 push @sources, ($src = $srpm);
187 push @sources, $src if (($src = $srpm) =~ s/\.el\d\.rf\./\.rf\./);
188 push @sources, $src if (($src = $srpm) =~ s/\.[0-3]\.el\d+\.rf\./\.rf\./);
189 push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d\.at//);
190 push @sources, $src if (($src = $srpm) =~ s/\.at//);
191 push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d//);
192 push @sources, $src if (($src = $srpm) =~ s/\.\d+\.(el|fc)\d//);
193
194 my $found = 0;
195 my $repo = $rpm->{repo};
196 foreach my $source ( @sources ) {
197 if ( $sources{$source} ) {
198 if ($repo eq $stagedir) {
199 push @{$copy{"$repo/SRPMS-$arch"}}, "$sources{$source}/$source" unless -f "$repo/SRPMS-$arch/$source";
200 } else {
201 unless ( -f "$repo/SRPMS/$source" ) {
202 push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source";
203 $changed{$repo}++;
204 }
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 my @remove;
215 foreach my $repo ( keys %srpms ) {
216 foreach my $rpm ( keys %{$srpms{$repo}} ) {
217 unless ( $srpms{$repo}{$rpm} ) {
218 if ($repo eq $stagedir) {
219 push @remove, "$repo/SRPMS-$arch/$rpm";
220 } else {
221 push @remove, "$repo/SRPMS/$rpm";
222 $changed{$repo}++;
223 }
224 }
225 }
226 }
227
228 print "\n";
229 foreach my $repo ( sort keys %copy ) {
230 foreach my $rpm ( keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) {
231 print "copying $rpm to $repo/\n";
232 mkdir "$repo" unless -d "$repo";
233 system(qw(cp --preserve=timestamps), $rpm, "$repo/");
234 }
235 }
236
237 print "\n";
238 foreach my $rpm ( keys %{{ map { $_ => 1 } (@remove, map { $_->{rpm}->filename } grep { $_->{repo} eq 'deleted' } @rpms) }} ) {
239 print "removing $rpm\n";
240 unlink $rpm;
241 }
242
243 print "\n";
244 foreach my $repo ( sort keys %changed ) {
245 my $dir=`readlink -f $repo/$arch`;
246 chomp $dir;
247 print "rebuilding $dir...\n";
248 system(qw(createrepo), "$dir");
249 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 }

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