/[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.11 - (hide annotations) (download)
Sun Jun 3 04:13:57 2007 UTC (17 years, 6 months ago) by slords
Branch: MAIN
Changes since 1.10: +129 -159 lines
Tools update

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

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