/[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.13 - (show annotations) (download)
Mon Jun 4 16:39:15 2007 UTC (17 years, 5 months ago) by slords
Branch: MAIN
Changes since 1.12: +1 -0 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/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",
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 foreach my $repo ( @repos ) {
63 my $r = $repo;
64 if ( $repo =~ m{$stagedir/RPMS} ) {
65 $r = $stagedir;
66 } elsif ( $repo =~ m{$builds/RPMS} ) {
67 $r = 'builds';
68 } elsif ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) {
69 $r = $1;
70 }
71
72 if ( $r ne 'builds' ) {
73 opendir SRPMS, "$r/SRPMS" or next;
74 foreach my $srpm ( grep { /\.rpm$/ } readdir SRPMS ) {
75 $srpms{$r}{$srpm} = 0;
76 $sources{$srpm} = "$r/SRPMS";
77 }
78 closedir SRPMS;
79 }
80
81 opendir RPMS, $repo or next;
82 foreach my $pkg ( reverse sort map { RPM2->open_package("$repo/$_", $rpm_flags); } grep { /\.rpm$/ } readdir RPMS ) {
83 my $rpm = { name => $pkg->tag("NAME"),
84 filename => join("-", map { $pkg->tag($_) } qw/name version release/) . "." . $pkg->tag("ARCH"),
85 version => $pkg->tag("VERSION"),
86 release => $pkg->tag("RELEASE"),
87 repo => $r,
88 rpm => $pkg,
89 };
90 my $source = $pkg->tag("SOURCERPM");
91 $source =~ s#-$rpm->{version}-$rpm->{release}.*##;
92 $rpm->{source} = $source;
93
94 if ( $rpm->{repo} =~ m{^$releasedir/$smerel/} && $rpm->{repo} !~ m{/smedev$} ) {
95 $rpm->{repo} = 'deleted' if grep { $_->{repo} ne $rpm->{repo} && $_->{name} eq $rpm->{name} && $_->{rpm} ge $rpm->{rpm} } @rpms;
96 $rpm->{repo} = 'deleted' if grep { $_->{repo} eq $rpm->{repo} && $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @rpms;
97 $changed{$r}++ if $rpm->{repo} eq 'deleted';
98 }
99
100 push @rpms, $rpm;
101 }
102 closedir RPMS;
103 }
104
105 foreach my $repo ( reverse @srcrepos ) {
106 my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo );
107 closedir SRPMS;
108
109 %sources = (%sources, %temp_repo);
110 }
111
112 my @latest;
113 foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} !~ m{/smedev$} } @rpms ) {
114 unless ( grep { $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @latest ) {
115 push @latest, $rpm;
116 unless ( grep { $_->{repo} eq $stagedir && $_->{filename} eq $rpm->{filename} } @rpms ) {
117 push @{$copy{"$stagedir/RPMS"}}, $rpm->{rpm}->filename;
118 push @rpms, { name => $rpm->{name},
119 filename => $rpm->{filename},
120 version => $rpm->{version},
121 release => $rpm->{release},
122 repo => $stagedir,
123 rpm => $rpm->{rpm},
124 source => $rpm->{source}
125 };
126 }
127 }
128 }
129
130 foreach my $rpm ( grep { $_->{repo} eq $stagedir } @rpms ) {
131 $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @latest;
132 }
133
134 my @devel;
135 my %versions;
136 foreach my $rpm ( grep { $_->{repo} eq 'builds' } @rpms ) {
137 next if grep { $_->{name} eq $rpm->{name} && $_->{rpm} ge $rpm->{rpm} } @latest;
138
139 $versions{$rpm->{name}}{$rpm->{version}}++ unless grep { $_->{name} eq $rpm->{name} && $_->{rpm} eq $rpm->{rpm} } @devel;
140 next if $versions{$rpm->{name}}{$rpm->{version}} > $releases || scalar keys %{$versions{$rpm->{name}}} > $releases;
141 print "Possible update " . $rpm->{rpm}->filename . "\n" if grep { $_->{name} eq $rpm->{name} } @latest;
142
143 push @devel, $rpm;
144 unless ( grep { $_->{repo} =~ m{/smedev$} && $_->{filename} eq $rpm->{filename} } @rpms ) {
145 push @{$copy{"$releasedir/$smerel/smedev/$arch/RPMS"}}, $rpm->{rpm}->filename;
146 $changed{"$releasedir/$smerel/smedev"}++;
147 push @rpms, { name => $rpm->{name},
148 filename => $rpm->{filename},
149 version => $rpm->{version},
150 release => $rpm->{release},
151 repo => "$releasedir/$smerel/smedev",
152 rpm => $rpm->{rpm},
153 source => $rpm->{source}
154 };
155 }
156 }
157
158 foreach my $rpm ( grep { $_->{repo} =~ m{/smedev$} } @rpms ) {
159 $rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @devel;
160 }
161
162 print "\n";
163 foreach my $rpm ( grep { $_->{repo} !~ m{^(builds|deleted)$} } @rpms ) {
164 my $src;
165 my $srpm = $rpm->{rpm}->tag("SOURCERPM");
166
167 my @sources = ();
168 push @sources, ($src = $srpm);
169 push @sources, $src if (($src = $srpm) =~ s/\.el\d\.rf\./\.rf\./);
170 push @sources, $src if (($src = $srpm) =~ s/\.[0-3]\.el\d+\.rf\./\.rf\./);
171 push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d\.at//);
172 push @sources, $src if (($src = $srpm) =~ s/\.at//);
173 push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d//);
174 push @sources, $src if (($src = $srpm) =~ s/\.\d+\.(el|fc)\d//);
175
176 my $found = 0;
177 my $repo = $rpm->{repo};
178 foreach my $source ( @sources ) {
179 if ( $sources{$source} ) {
180 unless ( -f "$repo/SRPMS/$source" ) {
181 push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source";
182 $changed{$repo}++ unless $repo eq $stagedir;
183 }
184 $srpms{$repo}{$source}++;
185 $found++;
186 last;
187 }
188 }
189 print "Can't find source for ".$rpm->{rpm}->filename."\n" unless $found;
190 }
191
192 my @remove;
193 foreach my $repo ( keys %srpms ) {
194 foreach my $rpm ( keys %{$srpms{$repo}} ) {
195 unless ( $srpms{$repo}{$rpm} ) {
196 push @remove, "$repo/SRPMS/$rpm";
197 $changed{$repo}++ unless $repo eq $stagedir;
198 }
199 }
200 }
201
202 print "\n";
203 foreach my $repo ( sort keys %copy ) {
204 foreach my $rpm ( keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) {
205 print "copying $rpm to $repo/\n";
206 system(qw(cp --preserve=timestamps), $rpm, "$repo/");
207 }
208 }
209
210 print "\n";
211 foreach my $rpm ( keys %{{ map { $_ => 1 } (@remove, map { $_->{rpm}->filename } grep { $_->{repo} eq 'deleted' } @rpms) }} ) {
212 print "removing $rpm\n";
213 unlink $rpm;
214 }
215
216 print "\n";
217 foreach my $repo ( sort keys %changed ) {
218 my $dir=`readlink -f $repo/$arch`;
219 chomp $dir;
220 print "rebuilding $dir...\n";
221 system(qw(createrepo), "$dir");
222 system(qw(repoview), "$dir");
223 }

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