3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use RPM2; |
use RPM2; |
6 |
|
use File::Find; |
7 |
|
use File::Basename; |
8 |
|
use Getopt::Std; |
9 |
|
use Term::ANSIColor; |
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
|
|
12 |
sub compare($$); |
delete $ENV{PATH}; |
13 |
|
my $HOME=$ENV{HOME}; |
14 |
|
umask 002; |
15 |
|
|
16 |
|
my $rpm_flags = RPM2->vsf_nosha1header | RPM2->vsf_nomd5header | RPM2->vsf_nodsaheader | RPM2->vsf_norsaheader; |
17 |
|
$rpm_flags |= RPM2->vsf_nosha1 | RPM2->vsf_nomd5 | RPM2->vsf_nodsa | RPM2->vsf_norsa; |
18 |
|
|
19 |
|
$Term::ANSIColor::AUTORESET = 1; |
20 |
|
$| = 1; |
21 |
|
|
22 |
|
my @archs = ( 'i386', 'x86_64' ); |
23 |
|
|
24 |
|
my $repos = { 'smeos' => { prio => 18, inc => 1, ver => 1, rel => 1, os => 1 }, |
25 |
|
'smeupdates' => { prio => 17, inc => 1, ver => 1, rel => 1 }, |
26 |
|
'smeupdates-testing' => { prio => 16, inc => 1, ver => 1, rel => 1 }, |
27 |
|
'smeextras' => { prio => 15, inc => 0, ver => 1, rel => 1 }, |
28 |
|
'smeaddons' => { prio => 14, inc => 0, ver => 1, rel => 1 }, |
29 |
|
'smecontribs' => { prio => 13, inc => 0, ver => 1, rel => 2, contribs => 1 }, |
30 |
|
'smetest' => { prio => 12, inc => 1, ver => 2, rel => 2, devel => 2 }, |
31 |
|
'smedev' => { prio => 11, inc => 0, ver => 2, rel => 2, devel => 1 }, |
32 |
|
'centos' => { prio => 10, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
33 |
|
'fedora/epel' => { prio => 9, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
34 |
|
'fedora/extras' => { prio => 8, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
35 |
|
'rpmforge' => { prio => 7, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
36 |
|
'atrpms' => { prio => 6, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
37 |
|
'fedora/core' => { prio => 5, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
38 |
|
'base' => { prio => 4, inc => 0, ver => 0, rel => 0, orig => 1, base => 1 }, |
39 |
|
'builds' => { prio => 3, inc => 0, ver => 0, rel => 0, orig => 1 }, |
40 |
|
'contribs' => { prio => 2, inc => 0, ver => 0, rel => 0, orig => 1 }, |
41 |
|
'stage' => { prio => 1, inc => 0, ver => 0, rel => 0, stage => 1, os => 1 }, |
42 |
|
}; |
43 |
|
|
44 |
|
my $distrepo = { '7' => { active => 1, |
45 |
|
centos => 4, |
46 |
|
fedora => 3, |
47 |
|
repo => '/releases/7/', |
48 |
|
os => 'SME/RPMS/', |
49 |
|
builds => '/builds/smeserver-7-core/', |
50 |
|
contribs => '/builds/smeserver-7-contribs/', |
51 |
|
stage => '/stage/7/', |
52 |
|
}, |
53 |
|
'8' => { active => 1, |
54 |
|
centos => 5, |
55 |
|
fedora => 6, |
56 |
|
repo => '/releases/testing/8/', |
57 |
|
os => 'SME/', |
58 |
|
builds => '/builds/smeserver-8-core/', |
59 |
|
contribs => '/builds/smeserver-8-contribs/', |
60 |
|
stage => '/stage/8/', |
61 |
|
}, |
62 |
|
}; |
63 |
|
|
64 |
|
my @baserepo = ( ( map { "/mirrors/centos/~C/$_/" } ('os','updates','fasttrack','extras') ), |
65 |
|
( map { "/mirrors/fedora/epel$_/~C/" } ('','/testing') ), |
66 |
|
'/mirrors/fedora/extras/~F/', |
67 |
|
'/mirrors/rpmforge/dag/redhat/el~C/en/~A/RPMS.dag/', |
68 |
|
'/mirrors/rpmforge/dag/source/', |
69 |
|
( map { "/mirrors/atrpms$_/el~C-~A/atrpms/stable/" } ('','/src') ), |
70 |
|
( map { "/mirrors/atrpms$_/el~C-~A/atrpms/testing/" } ('','/src') ), |
71 |
|
( map {"/mirrors/fedora/core$_/~F/" } ('','/updates') ), |
72 |
|
); |
73 |
|
|
74 |
|
my $skippkg = { '7' => { 'centos' => ['horde','imp-h3','ingo-h3','turba-h3','vim'], |
75 |
|
'fedora/epel' => ['perl-Razor-Agent'], |
76 |
|
'rpmforge' => ['perl-Test-Inline'], |
77 |
|
'atrpms' => ['dovecot','yum'], |
78 |
|
}, |
79 |
|
'8' => { 'centos' => ['horde','imp-h3','ingo-h3','turba-h3'], |
80 |
|
'fedora/epel' => ['perl-Razor-Agent','smolt'], |
81 |
|
'fedora/extras' => ['dstat','gocr','horde','oidentd','perl-Test-Inline','perl-Razor-Agent','smolt'], |
82 |
|
'rpmforge' => ['perl-Test-Inline'], |
83 |
|
'atrpms' => [], |
84 |
|
'fedora/core' => [], |
85 |
|
}, |
86 |
|
}; |
87 |
|
|
88 |
|
my %opts; |
89 |
|
getopts( 'dtvr:', \%opts ); |
90 |
|
$opts{r} ||= ''; |
91 |
|
|
92 |
|
my ($devel1, $devel2) = sort { $repos->{$a}->{devel} <=> $repos->{$b}->{devel} } grep { $repos->{$_}->{devel} } keys %$repos; |
93 |
|
$devel2 ||= $devel1; |
94 |
|
my ($contribs) = sort { $repos->{$a}->{contribs} <=> $repos->{$b}->{contribs} } grep { $repos->{$_}->{contribs} } keys %$repos; |
95 |
|
my ($stage) = sort { $repos->{$a}->{stage} <=> $repos->{$b}->{stage} } grep { $repos->{$_}->{stage} } keys %$repos; |
96 |
|
|
97 |
|
my ($rel, @rpms, %latest, %sources, $archs, $rebuild, $newline); |
98 |
|
foreach my $smever ( sort { $a <=> $b } grep { $distrepo->{$_}->{active} } keys %$distrepo ) { |
99 |
|
$rel = $smever; |
100 |
|
%latest = (); |
101 |
|
%sources = (); |
102 |
|
@rpms = (); |
103 |
|
$rebuild = (); |
104 |
|
|
105 |
|
# Load distro packages |
106 |
|
find( { wanted => \&loadpkg, no_chdir => 1, follow_fast => 1 }, map { $distrepo->{$smever}->{$_} } ('repo','builds','contribs','stage') ); |
107 |
|
printline('white', 0, "Distro (SME Server $rel) packages loaded.\n"); |
108 |
|
|
109 |
|
# Load base packages |
110 |
|
foreach my $base ( @baserepo ) { |
111 |
|
my $bdir = $base; |
112 |
|
$bdir =~ s/~C/$distrepo->{$smever}->{centos}/; |
113 |
|
$bdir =~ s/~F/$distrepo->{$smever}->{fedora}/; |
114 |
|
if ( $bdir =~ m{~A} ) { |
115 |
|
for my $arch ( @archs ) { |
116 |
|
my $basearch = $bdir; |
117 |
|
$basearch =~ s/~A/$arch/; |
118 |
|
find( { wanted => \&loadbase, no_chdir => 1, follow_fast => 1 }, $basearch ) if -r $basearch; |
119 |
|
} |
120 |
|
} else { |
121 |
|
find( { wanted => \&loadbase, no_chdir => 1, follow_fast => 1 }, $bdir ) if -r $bdir; |
122 |
|
} |
123 |
|
} |
124 |
|
printline('white', 0, 'Base (Centos: ', $distrepo->{$smever}->{centos}, ', Fedora: ', $distrepo->{$smever}->{fedora}, ") packages loaded.\n"); |
125 |
|
|
126 |
my $releases = 2; |
%latest = (); |
127 |
|
foreach my $name ( sort keys %{{ map { $_->{base} => 1 } @rpms }} ) { |
128 |
|
printline('white', 0, "Processing: $name"); |
129 |
|
my @pkgs = sort pkgsrt grep { $_->{base} eq $name } @rpms; |
130 |
|
my %seen = (); |
131 |
|
my $count = (); |
132 |
|
$archs = (); |
133 |
|
|
134 |
|
foreach my $pkg ( @pkgs ) { |
135 |
|
next if $pkg->{done} || $pkg->{obsolete} || $pkg->{rpm}->is_source_package || ! $repos->{$pkg->{repo}}; |
136 |
|
printline('bold black', 1, ' - ', $pkg->{rpm}->filename) if $opts{d}; |
137 |
|
my $orig = 0; |
138 |
|
|
139 |
|
# Find names of packages in same or higher repos |
140 |
|
my %names = names($pkg, @pkgs); |
141 |
|
|
142 |
|
# Stage packages should never be most current |
143 |
|
if ( rprop($pkg, 'stage') ) { |
144 |
|
printline('dark blue', 1, ' - checking stage') if $opts{d}; |
145 |
|
tagpkg($pkg, 'obsolete'); |
146 |
|
next; |
147 |
|
} |
148 |
|
|
149 |
|
# Move packages from base/builds to correct area |
150 |
|
elsif ( rprop($pkg, 'orig') ) { |
151 |
|
printline('dark blue', 1, ' - checking base/builds/contribs') if $opts{d}; |
152 |
|
my $repo = $names{$pkg->{name}} && $names{$pkg->{name}} > 1 ? $devel2 : $devel1; |
153 |
|
$repo = $contribs if $pkg->{repo} eq 'contribs'; |
154 |
|
if ( $pkg->{nonbase} ) { |
155 |
|
foreach my $up ( @pkgs ) { |
156 |
|
next if rprop($up, 'orig'); |
157 |
|
next if $up->{name} ne $pkg->{name} || ! $up->{obsolete} || $up->{rpm} ge $pkg->{rpm}; |
158 |
|
$repo = $up->{repo}; |
159 |
|
last; |
160 |
|
} |
161 |
|
} |
162 |
|
next if rprop($pkg, 'base') && $repo eq $devel1; |
163 |
|
movepkg($pkg, $repo); |
164 |
|
%names = names($pkg, @pkgs); |
165 |
|
$seen{$pkg->{nvra}}++; |
166 |
|
$orig++; |
167 |
|
} |
168 |
|
|
169 |
|
# Check version/release counts |
170 |
|
unless ( $pkg->{nonbase} ) { |
171 |
|
printline('dark blue', 1, ' - checking version/release counts') if $opts{d}; |
172 |
|
$count->{$pkg->{repo}}->{$pkg->{version}}->{$pkg->{release}}++; |
173 |
|
if ( rprop($pkg, 'ver') && scalar keys %{$count->{$pkg->{repo}}} > rprop($pkg, 'ver') ) { |
174 |
|
movepkg($_, 'delete') foreach grep { $_->{rpm} eq $pkg->{rpm} } @pkgs; |
175 |
|
next; |
176 |
|
} |
177 |
|
if ( rprop($pkg, 'rel') && scalar keys %{$count->{$pkg->{repo}}->{$pkg->{version}}} > rprop($pkg, 'rel') ) { |
178 |
|
movepkg($_, 'delete') foreach grep { $_->{rpm} eq $pkg->{rpm} } @pkgs; |
179 |
|
next; |
180 |
|
} |
181 |
|
} |
182 |
|
|
183 |
my $releasedir = '/releases'; |
foreach my $cmp ( grep { $_->{rpm}->is_source_package || ( ! $_->{done} && $_->{rpm} le $pkg->{rpm} && rprop($_, 'prio') <= rprop($pkg, 'prio') ) } @pkgs ) { |
184 |
my $smerel = '7'; |
printline('dark blue', 1, ' - ', $cmp->{rpm}->filename) if $opts{d}; |
185 |
my $centosrel = '4'; |
if ( $cmp->{rpm}->is_source_package ) { |
186 |
my $fedorarel = '3'; |
if ( $cmp->{name} eq $pkg->{base} ) { |
187 |
my $builds = '/builds/rpms'; |
if ( $cmp->{rpm} eq $pkg->{rpm} ) { |
188 |
my $stagedir = '/builds'; |
if ( $pkg->{repo} eq $cmp->{repo} || ! $pkg->{srpm} || $pkg->{srpm}->{rpm} ne $pkg->{rpm} ) { |
189 |
my $arch = `uname -i`; |
delete $pkg->{srpm}->{latest} if $pkg->{latest} && $pkg->{srpm} && $pkg->{srpm}->{latest}; |
190 |
chomp $arch; |
$pkg->{srpm} = $cmp; |
191 |
|
$pkg->{srpm}->{latest}++ if $pkg->{latest}; |
192 |
my @repos = ( |
} |
193 |
"$releasedir/$smerel/smeos/$arch/CentOS/RPMS", |
if ( $pkg->{latest} && rprop($cmp, 'stage') ) { |
194 |
"$releasedir/$smerel/smeos/$arch/SME/RPMS", |
tagpkg($cmp, 'inuse'); |
195 |
"$releasedir/$smerel/smeos/$arch/RPMS", |
$pkg->{srpm}->{latest}++; |
196 |
"$releasedir/$smerel/smeos/$arch/SME", |
} |
197 |
"$releasedir/$smerel/smeupdates/$arch/RPMS", |
if ( $pkg->{repo} eq $cmp->{repo} || ( $cmp->{oldrepo} && $pkg->{repo} eq $cmp->{oldrepo} ) || rprop($cmp, 'orig') ) { |
198 |
"$releasedir/$smerel/smeupdates-testing/$arch/RPMS", |
tagpkg($cmp, 'inuse') |
199 |
"$releasedir/$smerel/smeextras/$arch/RPMS", |
} |
|
"$releasedir/$smerel/smeaddons/$arch/RPMS", |
|
|
"$releasedir/$smerel/smetest/$arch/RPMS", |
|
|
"$releasedir/$smerel/smedev/$arch/RPMS", |
|
|
"$builds/RPMS/$arch", |
|
|
"$builds/RPMS/i586", |
|
|
"$builds/RPMS/i686", |
|
|
"$builds/RPMS/noarch", |
|
|
"$stagedir/RPMS", |
|
|
); |
|
|
|
|
|
my @srcrepos = ( |
|
|
"/mirrors/centos/$centosrel/fasttrack/SRPMS", |
|
|
"/mirrors/centos/$centosrel/updates/SRPMS", |
|
|
"/mirrors/centos/$centosrel/os/SRPMS", |
|
|
"/mirrors/centos/$centosrel/extras/SRPMS", |
|
|
"/mirrors/rpmforge/dag/source", |
|
|
"/mirrors/atrpms/src/el$centosrel-$arch/atrpms/stable", |
|
|
"/mirrors/fedora/epel/$centosrel/SRPMS", |
|
|
"/mirrors/fedora/core/updates/$fedorarel/SRPMS", |
|
|
"/mirrors/fedora/core/$fedorarel/source/SRPMS", |
|
|
"/mirrors/fedora/extras/$fedorarel/SRPMS", |
|
|
"$builds/SRPMS", |
|
|
); |
|
|
|
|
|
my $rpm_flags = RPM2->vsf_nodsaheader | RPM2->vsf_nodsa; |
|
|
|
|
|
my @rpms; |
|
|
my %srpms; |
|
|
my %sources; |
|
|
my %changed; |
|
|
my %copy; |
|
|
|
|
|
foreach my $repo ( @repos ) { |
|
|
my $r = $repo; |
|
|
if ( $repo =~ m{$stagedir/RPMS} ) { |
|
|
$r = $stagedir; |
|
|
} elsif ( $repo =~ m{$builds/RPMS} ) { |
|
|
$r = 'builds'; |
|
|
} elsif ( $repo =~ m{^($releasedir/$smerel/sme[^/]*)/} ) { |
|
|
$r = $1; |
|
|
} |
|
|
|
|
|
if ( $r ne 'builds' ) { |
|
|
opendir SRPMS, "$r/SRPMS" or next; |
|
|
foreach my $srpm ( grep { /\.rpm$/ } readdir SRPMS ) { |
|
|
$srpms{$r}{$srpm} = 0; |
|
|
$sources{$srpm} = "$r/SRPMS"; |
|
|
} |
|
|
closedir SRPMS; |
|
|
} |
|
|
|
|
|
opendir RPMS, $repo or next; |
|
|
foreach my $pkg ( reverse sort map { RPM2->open_package("$repo/$_", $rpm_flags); } grep { /\.rpm$/ } readdir RPMS ) { |
|
|
my $rpm = { name => $pkg->tag("NAME"), |
|
|
filename => join("-", map { $pkg->tag($_) } qw/name version release/) . "." . $pkg->tag("ARCH"), |
|
|
version => $pkg->tag("VERSION"), |
|
|
release => $pkg->tag("RELEASE"), |
|
|
repo => $r, |
|
|
rpm => $pkg, |
|
|
}; |
|
|
my $source = $pkg->tag("SOURCERPM"); |
|
|
$source =~ s#-$rpm->{version}-$rpm->{release}.*##; |
|
|
$rpm->{source} = $source; |
|
|
|
|
|
if ( $rpm->{repo} =~ m{^$releasedir/$smerel/} && $rpm->{repo} !~ m{/smedev$} ) { |
|
|
$rpm->{repo} = 'deleted' if grep { $_->{repo} ne $rpm->{repo} && $_->{name} eq $rpm->{name} && $_->{rpm} ge $rpm->{rpm} } @rpms; |
|
|
$rpm->{repo} = 'deleted' if grep { $_->{repo} eq $rpm->{repo} && $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @rpms; |
|
|
$changed{$r}++ if $rpm->{repo} eq 'deleted'; |
|
|
} |
|
|
|
|
|
push @rpms, $rpm; |
|
|
} |
|
|
closedir RPMS; |
|
|
} |
|
|
|
|
|
foreach my $repo ( reverse @srcrepos ) { |
|
|
my %temp_repo = map { $_ => $repo } grep { /\.rpm$/ } readdir SRPMS if ( opendir SRPMS, $repo ); |
|
|
closedir SRPMS; |
|
|
|
|
|
%sources = (%sources, %temp_repo); |
|
|
} |
|
|
|
|
|
my @latest; |
|
|
foreach my $rpm ( reverse grep { $_->{repo} =~ m{^$releasedir/$smerel/} && $_->{repo} !~ m{/smedev$} } @rpms ) { |
|
|
unless ( grep { $_->{name} eq $rpm->{name} && $_->{rpm} gt $rpm->{rpm} } @latest ) { |
|
|
push @latest, $rpm; |
|
|
unless ( grep { $_->{repo} eq $stagedir && $_->{filename} eq $rpm->{filename} } @rpms ) { |
|
|
push @{$copy{"$stagedir/RPMS"}}, $rpm->{rpm}->filename; |
|
|
push @rpms, { name => $rpm->{name}, |
|
|
filename => $rpm->{filename}, |
|
|
version => $rpm->{version}, |
|
|
release => $rpm->{release}, |
|
|
repo => $stagedir, |
|
|
rpm => $rpm->{rpm}, |
|
|
source => $rpm->{source} |
|
|
}; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
foreach my $rpm ( grep { $_->{repo} eq $stagedir } @rpms ) { |
|
|
$rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @latest; |
|
|
} |
|
|
|
|
|
my @devel; |
|
|
my %versions; |
|
|
foreach my $rpm ( grep { $_->{repo} eq 'builds' } @rpms ) { |
|
|
next if grep { $_->{name} eq $rpm->{name} && $_->{rpm} ge $rpm->{rpm} } @latest; |
|
|
|
|
|
$versions{$rpm->{name}}{$rpm->{version}}++ unless grep { $_->{name} eq $rpm->{name} && $_->{rpm} eq $rpm->{rpm} } @devel; |
|
|
next if $versions{$rpm->{name}}{$rpm->{version}} > $releases || scalar keys %{$versions{$rpm->{name}}} > $releases; |
|
|
print "Possible update " . $rpm->{rpm}->filename . "\n" if grep { $_->{name} eq $rpm->{name} } @latest; |
|
|
|
|
|
push @devel, $rpm; |
|
|
unless ( grep { $_->{repo} =~ m{/smedev$} && $_->{filename} eq $rpm->{filename} } @rpms ) { |
|
|
push @{$copy{"$releasedir/$smerel/smedev/$arch/RPMS"}}, $rpm->{rpm}->filename; |
|
|
$changed{"$releasedir/$smerel/smedev"}++; |
|
|
push @rpms, { name => $rpm->{name}, |
|
|
filename => $rpm->{filename}, |
|
|
version => $rpm->{version}, |
|
|
release => $rpm->{release}, |
|
|
repo => "$releasedir/$smerel/smedev", |
|
|
rpm => $rpm->{rpm}, |
|
|
source => $rpm->{source} |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
foreach my $rpm ( grep { $_->{repo} =~ m{/smedev$} } @rpms ) { |
|
|
$rpm->{repo} = 'deleted' unless grep { $_->{filename} eq $rpm->{filename} } @devel; |
|
|
} |
|
|
|
|
|
print "\n"; |
|
|
foreach my $rpm ( grep { $_->{repo} !~ m{^(builds|deleted)$} } @rpms ) { |
|
|
my $src; |
|
|
my $srpm = $rpm->{rpm}->tag("SOURCERPM"); |
|
|
|
|
|
my @sources = (); |
|
|
push @sources, ($src = $srpm); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.el\d\.rf\./\.rf\./); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.[0-3]\.el\d+\.rf\./\.rf\./); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d\.at//); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.at//); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.(el|fc)\d//); |
|
|
push @sources, $src if (($src = $srpm) =~ s/\.\d+\.(el|fc)\d//); |
|
|
|
|
|
my $found = 0; |
|
|
my $repo = $rpm->{repo}; |
|
|
foreach my $source ( @sources ) { |
|
|
if ( $sources{$source} ) { |
|
|
unless ( -f "$repo/SRPMS/$source" ) { |
|
|
push @{$copy{"$repo/SRPMS"}}, "$sources{$source}/$source"; |
|
|
$changed{$repo}++ unless $repo eq $stagedir; |
|
200 |
} |
} |
201 |
$srpms{$repo}{$source}++; |
next if $pkg->{srpm} && $pkg->{srpm}->{rpm} eq $pkg->{rpm}; |
202 |
$found++; |
|
203 |
last; |
my $src = $pkg->{rpm}->sourcerpm; |
204 |
|
my $source = basename $cmp->{rpm}->filename; |
205 |
|
SRC: { |
206 |
|
$src eq $source && last SRC; |
207 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.at(\.src)}{$1} && $src eq $source && last SRC; |
208 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.rf\.src)}{$1} && $src eq $source && last SRC; |
209 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d(\.rf\.src)}{$1$2} && $src eq $source && last SRC; |
210 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.rf(\.src)}{.dag$1} && $src eq $source && last SRC; |
211 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{(\d+)\.\d+\.el\d\.rf(\.src)}{$1.dag$2} && $src eq $source && last SRC; |
212 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d(\.src)}{$1} && $src eq $source && last SRC; |
213 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{(-\d+)\.\d+\.el\d(\.src)}{$1$2} && $src eq $source && last SRC; |
214 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.centos\d(\.src)}{$1} && $src eq $source && last SRC; |
215 |
|
($src = $pkg->{rpm}->sourcerpm) =~ s{\.el\d\.sme(\.src)}{$1} && $src eq $source && last SRC; |
216 |
|
$src = ''; |
217 |
|
} |
218 |
|
if ( $src eq $source && ( ! $pkg->{srpm} || $pkg->{srpm}->{rpm} eq $cmp->{rpm} ) ) { |
219 |
|
if ( ! $pkg->{srpm} || $pkg->{repo} eq $cmp->{repo} ) { |
220 |
|
delete $pkg->{srpm}->{latest} if $pkg->{latest} && $pkg->{srpm} && $pkg->{srpm}->{latest}; |
221 |
|
$pkg->{srpm} = $cmp; |
222 |
|
$pkg->{srpm}->{latest}++ if $pkg->{latest}; |
223 |
|
} |
224 |
|
if ( $pkg->{latest} && rprop($cmp, 'stage') ) { |
225 |
|
tagpkg($cmp, 'inuse'); |
226 |
|
$pkg->{srpm}->{latest}++; |
227 |
|
} |
228 |
|
tagpkg($cmp, 'inuse') if $pkg->{repo} eq $cmp->{repo} || rprop($cmp, 'orig'); |
229 |
|
} |
230 |
|
} |
231 |
|
} elsif ( $cmp->{rpm} eq $pkg->{rpm} ) { |
232 |
|
if ( $names{$cmp->{name}} ) { |
233 |
|
if ( $pkg->{repo} eq $cmp->{repo} ) { |
234 |
|
tagpkg($cmp, 'correct', 1); |
235 |
|
$seen{$cmp->{nvra}}++; |
236 |
|
} elsif ( $seen{$cmp->{nvra}} && rprop($cmp, 'stage') && $pkg->{latest} ) { |
237 |
|
$_->{latest}++ foreach grep { $_->{nvra} eq $cmp->{nvra} && $_->{latest} && $_->{done} } @pkgs; |
238 |
|
tagpkg($cmp, 'correct', 1); |
239 |
|
} elsif ( $seen{$cmp->{nvra}} ) { |
240 |
|
$orig++ if rprop($cmp, 'orig'); |
241 |
|
movepkg($cmp, 'delete', 1); |
242 |
|
} else { |
243 |
|
movepkg($cmp, $pkg->{repo}, 1, 1); |
244 |
|
$seen{$cmp->{nvra}}++; |
245 |
|
} |
246 |
|
} else { |
247 |
|
tagpkg($cmp, 'nonbase'); |
248 |
|
} |
249 |
|
} elsif ( rprop($cmp, 'prio') < rprop($pkg, 'prio') ) { |
250 |
|
tagpkg($cmp, 'obsolete'); |
251 |
|
} |
252 |
|
} |
253 |
|
printline('dark blue', 1, ' - checking source packages') if $opts{d}; |
254 |
|
if ( ! $pkg->{srpm} ) { |
255 |
|
printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (missing source ', $pkg->{rpm}->sourcerpm, ')'); |
256 |
|
} elsif ( $pkg->{srpm}->{repo} ne $pkg->{repo} && ( ! $pkg->{srpm}->{oldrepo} || $pkg->{srpm}->{oldrepo} ne $pkg->{repo} ) ) { |
257 |
|
movepkg($pkg->{srpm}, $pkg->{repo}, 0); |
258 |
|
} |
259 |
|
unless ( $orig ) { |
260 |
|
foreach ( grep { $_->{base} eq $pkg->{base} && $_->{repo} eq $pkg->{repo} } @pkgs ) { |
261 |
|
printline('bold yellow on_red', 1, ' - ', $_->{rpm}->filename, ' (missing original)'); |
262 |
} |
} |
263 |
|
} |
264 |
|
} |
265 |
|
printline('bold black', 1, ' - arch count check') if $opts{d}; |
266 |
|
foreach my $r ( keys %$archs ) { |
267 |
|
foreach my $p ( keys %{$archs->{$r}} ) { |
268 |
|
foreach my $a ( keys %{$archs->{$r}->{$p}} ) { |
269 |
|
my $p2 = ${$archs->{$r}->{$p}->{$a}}[0]; |
270 |
|
if ( $a eq 'noarch' ) { |
271 |
|
movepkg($p2, $p2->{repo}, 0) if ! $p2->{repos} && scalar @{$archs->{$r}->{$p}->{$a}} != scalar @archs; |
272 |
|
} elsif ( scalar @{$archs->{$r}->{$p}->{$a}} != 1 ) { |
273 |
|
printline('bold yellow on_red', 1, ' - ', $p2->{rpm}->filename, ' (many arch)'); |
274 |
|
} |
275 |
|
} |
276 |
|
} |
277 |
} |
} |
|
print "Can't find source for ".$rpm->{rpm}->filename."\n" unless $found; |
|
|
} |
|
278 |
|
|
279 |
my @remove; |
printline('bold black', 1, ' - missing stage packages') if $opts{d}; |
280 |
foreach my $repo ( keys %srpms ) { |
movepkg($_, $stage, 0) foreach grep { $_->{latest} && $_->{latest} == 1 } @pkgs; |
281 |
foreach my $rpm ( keys %{$srpms{$repo}} ) { |
|
282 |
unless ( $srpms{$repo}{$rpm} ) { |
printline('bold black', 1, ' - obsolete packages') if $opts{d}; |
283 |
push @remove, "$repo/SRPMS/$rpm"; |
movepkg($_, 'delete') foreach grep { ! rprop($_, 'base') && ! $_->{done} && ( $_->{obsolete} || ( $_->{rpm}->is_source_package && ! $_->{inuse} ) ) } @pkgs; |
284 |
$changed{$repo}++ unless $repo eq $stagedir; |
} |
285 |
|
printline('white', 0, "Finished processing.\n"); |
286 |
|
|
287 |
|
unless ( $opts{t} || $opts{r} ) { |
288 |
|
my %repochg = (); |
289 |
|
# Move / Copy / Delete packages and tag repo for rebuild. |
290 |
|
foreach my $pkg ( grep { $_->{oldrepo} } @rpms ) { |
291 |
|
printline('white', 0, 'Copy/move: ', $pkg->{rpm}->filename); |
292 |
|
my $src = $pkg->{rpm}->filename; |
293 |
|
|
294 |
|
qx(cat $HOME/.rpmpass | setsid rpm --addsign $src >& /dev/null) if $pkg->{nosig}; |
295 |
|
if ( $pkg->{repos} ) { |
296 |
|
foreach my $dest ( dest($pkg, @{$pkg->{repos}}) ) { |
297 |
|
qx(cp --preserve=timestamps $src $dest) unless -f "$dest"; |
298 |
} |
} |
299 |
|
$repochg{$_}++ foreach @{$pkg->{repos}}; |
300 |
|
} |
301 |
|
if ( $pkg->{remove} ) { |
302 |
|
qx(rm -f $src); |
303 |
|
$repochg{$pkg->{oldrepo}}++; |
304 |
|
} |
305 |
|
} |
306 |
|
finddepth(sub{rmdir}, $distrepo->{$rel}->{builds}); |
307 |
|
finddepth(sub{rmdir}, $distrepo->{$rel}->{contribs}); |
308 |
|
printline('white', 0, "Finished copying/moving.\n"); |
309 |
|
|
310 |
|
foreach my $repo ( sort keys %repochg ) { |
311 |
|
next if ! $repos->{$repo} || $repos->{$repo}->{orig} || $repos->{$repo}->{stage}; |
312 |
|
foreach my $arch ( @archs ) { |
313 |
|
my $dir = $distrepo->{$rel}->{repo} . "$repo/$arch"; |
314 |
|
$dir = qx(readlink -f $dir); |
315 |
|
chomp $dir; |
316 |
|
printline('white', 0, "Createrepo: $repo/$arch"); |
317 |
|
qx(createrepo $dir); |
318 |
|
printline('white', 0, "Repoview: $repo/$arch"); |
319 |
|
qx(repoview $dir); |
320 |
|
qx(rm -rf $dir/.olddata) if -d "$dir/.olddata"; |
321 |
|
qx(rm -rf $dir/.repodata) if -d "$dir/.repodata"; |
322 |
|
} |
323 |
} |
} |
324 |
|
printline('white', 0, "Finished rebuilding repos.\n"); |
325 |
|
} |
326 |
|
|
327 |
|
print "\n================================================================================\n\n"; |
328 |
} |
} |
329 |
|
|
330 |
print "\n"; |
sub pkgsrt { |
331 |
foreach my $repo ( sort keys %copy ) { |
return $a->{rpm}->is_source_package <=> $b->{rpm}->is_source_package || $b->{rpm} cmp $a->{rpm} || rprop($b, 'prio') <=> rprop($a, 'prio'); |
332 |
foreach my $rpm ( keys %{{ map { $_ => 1 } @{$copy{$repo}} }} ) { |
} |
333 |
print "copying $rpm to $repo/\n"; |
|
334 |
system(qw(cp --preserve=timestamps), $rpm, "$repo/"); |
sub rprop { |
335 |
} |
my ($pkg, $prop) = @_; |
336 |
|
return $repos->{$pkg->{repo}} ? $repos->{$pkg->{repo}}->{$prop} : 0; |
337 |
|
} |
338 |
|
|
339 |
|
sub names { |
340 |
|
my $pkg = shift; |
341 |
|
my @rpms = @_; |
342 |
|
return map { $_->{name} => rprop($_, 'inc') ? 2 : 1 } grep { $_->{base} eq $pkg->{base} && |
343 |
|
rprop($_, 'prio') >= rprop($pkg, 'prio') && |
344 |
|
! rprop($_, 'orig') && |
345 |
|
! $_->{rpm}->is_source_package |
346 |
|
} @rpms; |
347 |
|
} |
348 |
|
|
349 |
|
sub dest { |
350 |
|
my ($pkg, @repos) = @_; |
351 |
|
my @d = (); |
352 |
|
foreach my $repo ( @repos ) { |
353 |
|
my $base = $distrepo->{$rel}->{repo} . $repo; |
354 |
|
$base = $distrepo->{$rel}->{stage} if $repos->{$repo}->{stage}; |
355 |
|
if ( $pkg->{arch} eq 'noarch' ) { |
356 |
|
push @d, "$base/i386/" . |
357 |
|
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
358 |
|
basename $pkg->{rpm}->filename; |
359 |
|
push @d, "$base/x86_64/" . |
360 |
|
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
361 |
|
basename $pkg->{rpm}->filename; |
362 |
|
} elsif ( $pkg->{arch} =~ m{^(i[356]86)$} ) { |
363 |
|
push @d, "$base/i386/" . |
364 |
|
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
365 |
|
basename $pkg->{rpm}->filename; |
366 |
|
} elsif ( $pkg->{arch} eq 'x86_64' ) { |
367 |
|
push @d, "$base/x86_64/" . |
368 |
|
( $repos->{$repo}->{os} ? $distrepo->{$rel}->{os} : 'RPMS/' ) . |
369 |
|
basename $pkg->{rpm}->filename; |
370 |
|
} elsif ( $pkg->{arch} eq 'zsrc' ) { |
371 |
|
push @d, "$base/SRPMS/" . |
372 |
|
basename $pkg->{rpm}->filename; |
373 |
|
} else { |
374 |
|
printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (bad arch: ', $pkg->{arch}, ')'); |
375 |
|
} |
376 |
|
} |
377 |
|
return @d; |
378 |
} |
} |
379 |
|
|
380 |
print "\n"; |
sub movepkg { |
381 |
foreach my $rpm ( keys %{{ map { $_ => 1 } (@remove, map { $_->{rpm}->filename } grep { $_->{repo} eq 'deleted' } @rpms) }} ) { |
my ($pkg, $repo, $done, $remove) = @_; |
382 |
print "removing $rpm\n"; |
defined $done or $done = 2; |
383 |
unlink $rpm; |
defined $remove or $remove = 0; |
384 |
|
$remove = 0 if rprop($pkg, 'orig'); |
385 |
|
$remove = 1 if $repo eq 'delete'; |
386 |
|
|
387 |
|
if ( $repo eq 'delete' && ( rprop($pkg, 'base') || ( rprop($pkg, 'orig') && $done == 1 ) ) ) { |
388 |
|
tagpkg($pkg, 'inuse', 1); |
389 |
|
} else { |
390 |
|
printline('bold magenta', 1, " - ($repo) ", $pkg->{rpm}->filename) if $opts{d}; |
391 |
|
my $color = 'bold white'; |
392 |
|
$color = 'bold yellow' if rprop($pkg, 'orig'); |
393 |
|
$color = 'dark green' if $repos->{$repo} && $repos->{$repo}->{devel}; |
394 |
|
$color = 'dark red' if $repo eq 'delete'; |
395 |
|
push @{$pkg->{repos}}, $repo unless $repo eq 'delete'; |
396 |
|
$pkg->{oldrepo} = $pkg->{repo} unless $pkg->{oldrepo}; |
397 |
|
$pkg->{repo} = $repo; |
398 |
|
$pkg->{remove}++ if $remove; |
399 |
|
printline($color, 1, ' - ', $pkg->{rpm}->filename, ' (', $pkg->{oldrepo}, " to $repo)") if $opts{v} || $opts{d}; |
400 |
|
done($pkg) if $done; |
401 |
|
} |
402 |
|
} |
403 |
|
|
404 |
|
sub tagpkg { |
405 |
|
my ($pkg, $tag, $done) = @_; |
406 |
|
defined $done or $done = 0; |
407 |
|
|
408 |
|
printline('bold magenta', 1, " - ($tag) ", $pkg->{rpm}->filename) if $opts{d}; |
409 |
|
delete $pkg->{obsolete} if $pkg->{obsolete}; |
410 |
|
$pkg->{$tag}++; |
411 |
|
done($pkg) if $done; |
412 |
|
} |
413 |
|
|
414 |
|
sub done { |
415 |
|
my $pkg = shift; |
416 |
|
printline('bold yellow on_red', 1, " - ", $pkg->{rpm}->filename, " (already processed)") if $pkg->{done}; |
417 |
|
$pkg->{done}++; |
418 |
|
delete $pkg->{obsolete} if $pkg->{obsolete}; |
419 |
|
|
420 |
|
if ( $repos->{$pkg->{repo}} && ! rprop($pkg, 'orig') ) { |
421 |
|
# FIXME: Nasty hack for comps package |
422 |
|
if ( $pkg->{name} eq 'comps' ) { |
423 |
|
if ( ! $latest{$pkg->{name}.'.'.$pkg->{arch}} || $latest{$pkg->{name}.'.'.$pkg->{arch}}->{rpm} eq $pkg->{rpm} ) { |
424 |
|
if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) { |
425 |
|
$latest{$pkg->{name}.'.'.$pkg->{arch}} = $pkg if ! $latest{$pkg->{name}.'.'.$pkg->{arch}}; |
426 |
|
$pkg->{latest}++; |
427 |
|
} |
428 |
|
} |
429 |
|
} elsif ( ! $latest{$pkg->{name}} || $latest{$pkg->{name}}->{rpm} eq $pkg->{rpm} ) { |
430 |
|
if ( rprop($pkg, 'inc') && ! $pkg->{rpm}->is_source_package ) { |
431 |
|
$latest{$pkg->{name}} = $pkg if ! $latest{$pkg->{name}}; |
432 |
|
$pkg->{latest}++; |
433 |
|
} |
434 |
|
} |
435 |
|
unless ( $pkg->{oldrepo} ) { |
436 |
|
my $goodarch = 0; |
437 |
|
$goodarch++ if $pkg->{rpm}->filename =~ m{/(i386|x86_64)/.*\.noarch\.rpm$}; |
438 |
|
$goodarch++ if $pkg->{rpm}->filename =~ m{/i386/.*\.(i[56]86)\.rpm$}; |
439 |
|
$goodarch++ if $pkg->{rpm}->filename =~ m{/(noarch|i[356]86|x86_64)/.*\.\1\.rpm$}; |
440 |
|
printline('bold yellow on_red', 1, ' - ', $pkg->{rpm}->filename, ' (wrong arch)') unless $goodarch; |
441 |
|
} |
442 |
|
push @{$archs->{$pkg->{repo}}->{$pkg->{rpm}->as_nvre}->{$pkg->{rpm}->is_source_package ? 'src' : $pkg->{rpm}->arch}}, $pkg; |
443 |
|
} |
444 |
} |
} |
445 |
|
|
446 |
print "\n"; |
sub printline { |
447 |
foreach my $repo ( sort keys %changed ) { |
my $color = shift; |
448 |
my $dir=`readlink -f $repo/$arch`; |
my $nline = shift; |
449 |
chomp $dir; |
my $string = join '', @_; |
450 |
print "rebuilding $dir...\n"; |
|
451 |
system(qw(createrepo), "$dir"); |
if ( $nline ) { |
452 |
system(qw(repoview), "$dir"); |
print "\n" unless $newline; |
453 |
|
$newline++; |
454 |
|
} else { |
455 |
|
$newline = 0; |
456 |
|
print "\r\e[0K"; |
457 |
|
} |
458 |
|
print color $color; |
459 |
|
print $string; |
460 |
|
print color 'reset'; |
461 |
|
print "\n" if $nline; |
462 |
|
} |
463 |
|
|
464 |
|
sub loadpkg { |
465 |
|
printline('white', 0, "Loading: $_") if -d _; |
466 |
|
return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ( ! $opts{r} || $1 =~ m{$opts{r}} ); |
467 |
|
|
468 |
|
my $pkg; |
469 |
|
eval { $pkg = RPM2->open_package($_, $rpm_flags); }; |
470 |
|
if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; } |
471 |
|
eval { my $sig = $pkg->siggpg }; |
472 |
|
my $nosig = ! $@; |
473 |
|
|
474 |
|
my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm}; |
475 |
|
foreach my $repo ( keys %{$skippkg->{$rel}} ) { return if (dirname $pkg->filename) =~ m{/$repo/} && grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}}; } |
476 |
|
my $reponame = 'unknown'; |
477 |
|
if ( substr($_, 0, length($distrepo->{$rel}->{builds})) eq $distrepo->{$rel}->{builds} ) { |
478 |
|
$reponame = 'builds'; |
479 |
|
} elsif ( substr($_, 0, length($distrepo->{$rel}->{contribs})) eq $distrepo->{$rel}->{contribs} ) { |
480 |
|
$reponame = 'contribs'; |
481 |
|
} elsif ( substr($_, 0, length($distrepo->{$rel}->{stage})) eq $distrepo->{$rel}->{stage} ) { |
482 |
|
$reponame = 'stage'; |
483 |
|
} elsif ( (dirname $pkg->filename) =~ m{\d/(sme[^/]+)/} ) { |
484 |
|
$reponame = $1; |
485 |
|
} |
486 |
|
if ( $nosig && ( ! -f "$HOME/.rpmpass" || ! $repos->{$reponame}->{orig} ) ) { |
487 |
|
printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)'); |
488 |
|
return; |
489 |
|
} |
490 |
|
push @rpms, { base => $srcname, |
491 |
|
name => $pkg->name, |
492 |
|
repo => $reponame, |
493 |
|
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
494 |
|
arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'), |
495 |
|
version => $version, |
496 |
|
release => $release, |
497 |
|
rpm => $pkg, |
498 |
|
nosig => $nosig, |
499 |
|
}; |
500 |
|
$sources{$srcname}++; |
501 |
|
if ( ! $pkg->is_source_package && ! $repos->{$reponame}->{stage} ) { |
502 |
|
$latest{$pkg->name} = $rpms[$#rpms] if ! $latest{$pkg->name} || $pkg gt $latest{$pkg->name}->{rpm}; |
503 |
|
} |
504 |
|
} |
505 |
|
|
506 |
|
sub loadbase { |
507 |
|
printline('white', 0, "Loading: $_") if -d _; |
508 |
|
return unless m{/([^/]*)-[^-]+-[^-]+\.\w+.rpm} && ($latest{$1} || $sources{$1}); |
509 |
|
|
510 |
|
my $pkg; |
511 |
|
eval { $pkg = RPM2->open_package($_, $rpm_flags); }; |
512 |
|
if ($@) { printline('bold yellow on_red', 1, "Corrupt package $_"); return; } |
513 |
|
eval { my $sig = $pkg->siggpg }; |
514 |
|
unless ($@) { printline('bold yellow on_red', 1, ' - ', $pkg->filename, ' (missing signature)'); return; } |
515 |
|
|
516 |
|
my $cmp = $latest{$pkg->name}; |
517 |
|
my ($srcname, $version, $release) = ($pkg->is_source_package ? basename $pkg->filename : $pkg->sourcerpm) =~ m{^([^/]*)-([^-]+)-([^-]+)\.\w+.rpm}; |
518 |
|
my $pkgrepo = 'base'; |
519 |
|
foreach my $repo ( keys %{$skippkg->{$rel}} ) { |
520 |
|
if ( (dirname $pkg->filename) =~ m{/$repo/} ) { |
521 |
|
return if grep { $_ eq $srcname } @{$skippkg->{$rel}->{$repo}}; |
522 |
|
$pkgrepo = $repo; |
523 |
|
return unless $pkg->is_source_package || $cmp; |
524 |
|
return if ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && rprop($cmp, 'base') && rprop($cmp, 'prio') > $repos->{$pkgrepo}->{prio}; |
525 |
|
last; |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
|
push @rpms, { base => $srcname, |
530 |
|
name => $pkg->name, |
531 |
|
repo => $pkgrepo, |
532 |
|
nvra => $pkg->name.'-'.$pkg->version.'-'.$pkg->release.'.'.( $pkg->is_source_package ? 'src' : $pkg->tag('ARCH') ), |
533 |
|
arch => $pkg->is_source_package ? 'zsrc' : $pkg->tag('ARCH'), |
534 |
|
version => $version, |
535 |
|
release => $release, |
536 |
|
rpm => $pkg, |
537 |
|
nosig => 0, |
538 |
|
}; |
539 |
|
if ( ! $pkg->is_source_package && $pkg ge $cmp->{rpm} && ( $repos->{$pkgrepo}->{prio} >= rprop($cmp, 'prio') || ! rprop($cmp, 'base') ) ) { |
540 |
|
$latest{$pkg->name} = $rpms[$#rpms]; |
541 |
|
} |
542 |
} |
} |
543 |
|
|