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 $test_repo = '/releases/7/smedev'; |
11 |
my $releases = 2; |
12 |
|
13 |
my $rpm_flags = RPM2->vsf_nodsa; |
14 |
my @repositories = qw( |
15 |
/releases/7/smeos/i386/CentOS/RPMS/ |
16 |
/releases/7/smeupdates/i386/RPMS/ |
17 |
/releases/7/smeupdates-testing/i386/RPMS/ |
18 |
/releases/7/smeextras/i386/RPMS/ |
19 |
/releases/7/smetest/i386/RPMS/ |
20 |
/builds/rpms/RPMS/i386/ |
21 |
/builds/rpms/RPMS/i586/ |
22 |
/builds/rpms/RPMS/i686/ |
23 |
/builds/rpms/RPMS/noarch/ |
24 |
); |
25 |
|
26 |
my %repos; |
27 |
foreach my $repo (@repositories) { |
28 |
opendir RPMS, $repo; |
29 |
foreach my $rpm (grep { m#\.rpm# } readdir RPMS) |
30 |
{ |
31 |
my $header = RPM2->open_package("$repo/$rpm", $rpm_flags); |
32 |
if ($repo =~ m#^/releases/7/sme#) { |
33 |
push @{$repos{$header->tag("NAME").".".$header->tag("ARCH")}{releases}}, $header; |
34 |
} else { |
35 |
push @{$repos{$header->tag("NAME")."-".$header->tag("VERSION").".".$header->tag("ARCH")}{builds}}, $header; |
36 |
} |
37 |
} |
38 |
closedir RPMS; |
39 |
} |
40 |
|
41 |
my @testing = map { RPM2->open_package("$test_repo/i386/RPMS/$_", $rpm_flags) } grep { m#\.rpm# } readdir RPMS if opendir RPMS, "$test_repo/i386/RPMS"; |
42 |
closedir RPMS; |
43 |
|
44 |
my %pushed; |
45 |
foreach my $rpm (keys %repos) { |
46 |
next unless $repos{$rpm}{builds}; |
47 |
|
48 |
my @builds = reverse sort compare @{$repos{$rpm}{builds}}; |
49 |
my $cnt = $#builds > $releases-1 ? $releases-1 : $#builds; |
50 |
|
51 |
if ($repos{$builds[0]->tag("NAME").".".$builds[0]->tag("ARCH")}{releases}) { |
52 |
my @released = reverse sort compare @{$repos{$builds[0]->tag("NAME").".".$builds[0]->tag("ARCH")}{releases}}; |
53 |
push @{$pushed{$builds[0]->tag("NAME").".".$builds[0]->tag("ARCH")}}, grep { $_ gt $released[0] } @builds[0..$cnt]; |
54 |
} else { |
55 |
push @{$pushed{$builds[0]->tag("NAME").".".$builds[0]->tag("ARCH")}}, @builds[0..$cnt]; |
56 |
} |
57 |
} |
58 |
|
59 |
my $changed = 0; |
60 |
my @pushed; |
61 |
foreach my $package (sort keys %pushed) |
62 |
{ |
63 |
my @push = reverse sort compare @{$pushed{$package}}; |
64 |
my $cnt = $#push > $releases*2-1 ? $releases*2-1 : $#push; |
65 |
|
66 |
foreach my $rpm (@push[0..$cnt]) { |
67 |
push @pushed, $rpm; |
68 |
unless (grep { ! compare($_, $rpm) } @testing) { |
69 |
print "adding ".$rpm->filename."\n"; |
70 |
system(qw(cp -a), $rpm->filename, "$test_repo/i386/RPMS/"); |
71 |
$changed++; |
72 |
} |
73 |
} |
74 |
} |
75 |
|
76 |
foreach my $rpm (sort compare @testing) |
77 |
{ |
78 |
unless (grep { ! compare($_,$rpm) } @pushed) { |
79 |
print "removing ".$rpm->filename."\n"; |
80 |
unlink $rpm->filename; |
81 |
$changed++; |
82 |
} |
83 |
} |
84 |
|
85 |
if ($changed) { |
86 |
system(qw(/builds/bin/linksource -s), "$test_repo/i386/RPMS", '-d', "$test_repo/SRPMS"); |
87 |
system(qw(createrepo), "$test_repo/i386"); |
88 |
system(qw(repoview), "$test_repo/i386"); |
89 |
} |
90 |
|
91 |
sub compare($$) { |
92 |
my ($a, $b) = @_; |
93 |
return $a->tag("NAME") cmp $b->tag("NAME") || $a cmp $b; |
94 |
} |