/[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.17 - (show annotations) (download)
Thu Jul 5 14:17:56 2007 UTC (17 years, 4 months ago) by slords
Branch: MAIN
Changes since 1.16: +3 -2 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/CentOS/RPMS",
23 "$releasedir/$smerel/smeos/$arch/SME/RPMS",
24 "$releasedir/$smerel/smeos/$arch/RPMS",
25 "$releasedir/$smerel/smeos/$arch/SME",
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 "$releasedir/$smerel/smecontribs/$arch/RPMS",
31 "$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 "/mirrors/atrpms/src/el$centosrel-$arch/atrpms/testing",
48 "/mirrors/fedora/epel/$centosrel/SRPMS",
49 "/mirrors/fedora/core/updates/$fedorarel/SRPMS",
50 "/mirrors/fedora/core/$fedorarel/source/SRPMS",
51 "/mirrors/fedora/extras/$fedorarel/SRPMS",
52 "$builds/SRPMS",
53 );
54
55 my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa;
56
57 my @rpms;
58 my %srpms;
59 my %sources;
60 my %changed;
61 my %copy;
62
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 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 }
105
106 foreach my $repo ( reverse @srcrepos ) {
107 my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo );
108 closedir SRPMS;
109
110 %sources = (%sources, %temp_repo);
111 }
112
113 my @latest;
114 foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} !~ m{/sme(addons|contribs|dev|extras)$} } @rpms ) {
115 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 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 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 }
164
165 foreach my $rpm ( grep { $_->{repo} =~ m{/smedev$} } @rpms ) {
166 $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @devel;
167 }
168
169 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 }
198
199 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 }
208
209 print "\n";
210 foreach my $repo ( sort keys %copy ) {
211 foreach my $rpm ( keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) {
212 print "copying $rpm to $repo/\n";
213 mkdir "$repo" unless -d "$repo";
214 system(qw(cp --preserve=timestamps), $rpm, "$repo/");
215 }
216 }
217
218 print "\n";
219 foreach my $rpm ( keys %{{ map { $_ => 1 } (@remove, map { $_->{rpm}->filename } grep { $_->{repo} eq 'deleted' } @rpms) }} ) {
220 print "removing $rpm\n";
221 unlink $rpm;
222 }
223
224 print "\n";
225 foreach my $repo ( sort keys %changed ) {
226 my $dir=`readlink -f $repo/$arch`;
227 chomp $dir;
228 print "rebuilding $dir...\n";
229 system(qw(createrepo), "$dir");
230 system(qw(rm -rf), "$dir/.olddata") if -d "$dir/.olddata";
231 system(qw(repoview), "$dir");
232 system(qw(rm -rf), "$dir/.repodata") if "$dir/.repodata";
233 }

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