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