2008-02-01 21:42:26 +00:00
|
|
|
package xCAT::Yum;
|
|
|
|
use DBI;
|
|
|
|
use File::Find;
|
2008-03-26 15:04:32 +00:00
|
|
|
use File::Spec;
|
|
|
|
use File::Path;
|
2011-05-23 09:15:49 +00:00
|
|
|
|
2008-03-26 15:04:32 +00:00
|
|
|
my $yumrepofile;
|
|
|
|
my $distname;
|
|
|
|
my $arch;
|
|
|
|
my $installpfx;
|
2011-05-23 09:15:49 +00:00
|
|
|
|
2008-02-01 21:42:26 +00:00
|
|
|
sub localize_yumrepo {
|
2011-05-23 09:15:49 +00:00
|
|
|
my $self = shift;
|
|
|
|
my $installroot = shift;
|
|
|
|
$distname = shift;
|
|
|
|
$arch = shift;
|
|
|
|
|
|
|
|
$installpfx = "$installroot/$distname/$arch";
|
|
|
|
mkpath("$installroot/postscripts/repos/$distname/$arch/");
|
|
|
|
open($yumrepofile,">","$installroot/postscripts/repos/$distname/$arch/local-repository.tmpl");
|
2012-06-08 03:30:58 +00:00
|
|
|
my %options=(
|
|
|
|
wanted => \&check_tofix,
|
|
|
|
follow_fast => 1
|
|
|
|
);
|
|
|
|
find(\%options,$installpfx);
|
|
|
|
close($yumrepofile);
|
2008-02-01 21:42:26 +00:00
|
|
|
}
|
2012-06-08 03:30:58 +00:00
|
|
|
|
2008-02-01 21:42:26 +00:00
|
|
|
sub check_tofix {
|
|
|
|
if (-d $File::Find::name and $File::Find::name =~ /\/repodata$/) {
|
2011-07-01 11:27:04 +00:00
|
|
|
if($distname =~ /rhels5/)
|
|
|
|
{
|
|
|
|
fix_directory($File::Find::name);
|
|
|
|
}
|
|
|
|
generate_repo($File::Find::name);
|
2008-02-01 21:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-01 11:27:04 +00:00
|
|
|
sub generate_repo
|
|
|
|
{
|
2011-05-23 09:15:49 +00:00
|
|
|
#write local-repository.tmpl
|
|
|
|
my $dirlocation = shift;
|
|
|
|
my @dircomps = File::Spec->splitdir($dirlocation);
|
|
|
|
pop(@dircomps);
|
|
|
|
my $yumurl = File::Spec->catdir(@dircomps);
|
|
|
|
$yumurl =~ s!$installpfx!http://#INSTSERVER#/install/$distname/$arch/!;
|
|
|
|
my $reponame = $dircomps[$#dircomps];
|
|
|
|
print $yumrepofile "[local-$distname-$arch-$reponame]\n";
|
|
|
|
print $yumrepofile "name=xCAT configured yum repository for $distname/$arch/$reponame\n";
|
|
|
|
print $yumrepofile "baseurl=$yumurl\n";
|
|
|
|
print $yumrepofile "enabled=1\n";
|
|
|
|
print $yumrepofile "gpgcheck=0\n\n";
|
2011-07-01 11:27:04 +00:00
|
|
|
}
|
|
|
|
sub fix_directory {
|
|
|
|
|
|
|
|
my @xmlines=();
|
|
|
|
my $primaryxml;
|
2011-05-23 09:15:49 +00:00
|
|
|
|
2011-06-27 09:29:27 +00:00
|
|
|
$grep_result = system("grep sha256 $dirlocation/repomd.xml|grep \\<checksum");
|
|
|
|
if( $grep_result == 0 )
|
|
|
|
{
|
|
|
|
$sha_command = "sha256sum";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sha_command = "sha1sum";
|
|
|
|
}
|
2011-05-23 09:15:49 +00:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
my $oldsha;
|
|
|
|
my $newsha;
|
|
|
|
my $oldopensha;
|
|
|
|
my $newopensha;
|
|
|
|
|
|
|
|
if( -r "$dirlocation/primary.xml.gz")
|
|
|
|
{
|
2011-06-27 09:29:27 +00:00
|
|
|
$oldsha=`/usr/bin/$sha_command $dirlocation/primary.xml.gz`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$oldsha =~ s/\s.*//;
|
|
|
|
chomp($oldsha);
|
|
|
|
|
|
|
|
#update primary.xml.gz & primary.xml
|
2011-06-03 07:36:02 +00:00
|
|
|
if( -r "$dirlocation/primary.xml")
|
|
|
|
{
|
|
|
|
unlink("$dirlocation/primary.xml");
|
|
|
|
}
|
2011-05-23 09:15:49 +00:00
|
|
|
system("/bin/gunzip $dirlocation/primary.xml.gz");
|
|
|
|
|
2011-06-27 09:29:27 +00:00
|
|
|
$oldopensha=`/usr/bin/$sha_command $dirlocation/primary.xml`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$oldopensha =~ s/\s+.*//;
|
|
|
|
chomp($oldopensha);
|
|
|
|
|
|
|
|
open($primaryxml,"+<$dirlocation/primary.xml");
|
|
|
|
while (<$primaryxml>) {
|
|
|
|
s!xml:base="media://[^"]*"!!g;
|
|
|
|
push @xmlines,$_;
|
|
|
|
}
|
|
|
|
seek($primaryxml,0,0);
|
|
|
|
print $primaryxml (@xmlines);
|
|
|
|
truncate($primaryxml,tell($primaryxml));
|
|
|
|
@xmlines=();
|
|
|
|
close($primaryxml);
|
|
|
|
|
2011-06-27 09:29:27 +00:00
|
|
|
$newopensha=`/usr/bin/$sha_command $dirlocation/primary.xml`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$newopensha =~ s/\s.*//;
|
|
|
|
chomp($newopensha);
|
|
|
|
|
|
|
|
system("/bin/gzip $dirlocation/primary.xml");
|
2011-06-27 09:29:27 +00:00
|
|
|
$newsha=`/usr/bin/$sha_command $dirlocation/primary.xml.gz`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$newsha =~ s/\s.*//;
|
|
|
|
chomp($newsha);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
my $newdbsha;
|
|
|
|
my $olddbsha;
|
|
|
|
my $newdbopensha;
|
|
|
|
my $olddbopensha;
|
|
|
|
|
|
|
|
if (-r "$dirlocation/primary.sqlite.bz2") {
|
|
|
|
|
2011-06-27 09:29:27 +00:00
|
|
|
$olddbsha =`/usr/bin/$sha_command $dirlocation/primary.sqlite.bz2`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$olddbsha =~ s/\s.*//;
|
|
|
|
chomp($olddbsha);
|
|
|
|
|
|
|
|
#update primary.sqlite.bz2 & primary.sqlite
|
|
|
|
if ( -r "$dirlocation/primary.sqlite")
|
|
|
|
{
|
|
|
|
unlink("$dirlocation/primary.sqlite");
|
|
|
|
}
|
|
|
|
|
|
|
|
system("/usr/bin/bunzip2 $dirlocation/primary.sqlite.bz2");
|
2011-06-27 09:29:27 +00:00
|
|
|
$olddbopensha=`/usr/bin/$sha_command $dirlocation/primary.sqlite`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$olddbopensha =~ s/\s+.*//;
|
|
|
|
chomp($olddbopensha);
|
|
|
|
|
|
|
|
my $pdbh = DBI->connect("dbi:SQLite:$dirlocation/primary.sqlite","","",{AutoCommit=>1});
|
|
|
|
$pdbh->do('UPDATE "packages" SET "location_base" = NULL');
|
|
|
|
$pdbh->disconnect;
|
2011-06-27 09:29:27 +00:00
|
|
|
$newdbopensha=`/usr/bin/$sha_command $dirlocation/primary.sqlite`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$newdbopensha =~ s/\s.*//;
|
|
|
|
chomp($newdbopensha);
|
|
|
|
|
|
|
|
system("/usr/bin/bzip2 $dirlocation/primary.sqlite");
|
2011-06-27 09:29:27 +00:00
|
|
|
$newdbsha=`/usr/bin/$sha_command $dirlocation/primary.sqlite.bz2`;
|
2011-05-23 09:15:49 +00:00
|
|
|
$newdbsha =~ s/\s.*//;
|
|
|
|
chomp($newdbsha);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#update repomd.xml
|
|
|
|
open($primaryxml,"+<$dirlocation/repomd.xml");
|
|
|
|
while (<$primaryxml>) {
|
2011-06-27 09:29:27 +00:00
|
|
|
if($_ =~ m/\<size\>/)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($_ =~ m/\<open-size\>/)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2011-05-23 09:15:49 +00:00
|
|
|
s!xml:base="media://[^"]*"!!g;
|
|
|
|
if(defined($oldsha)){
|
|
|
|
s!$oldsha!$newsha!g;
|
|
|
|
}
|
|
|
|
if(defined($oldopensha)){
|
|
|
|
s!$oldopensha!$newopensha!g;
|
|
|
|
}
|
|
|
|
if(defined($olddbsha)){
|
|
|
|
s!$olddbsha!$newdbsha!g;
|
|
|
|
}
|
|
|
|
if(defined($olddbopensha)){
|
|
|
|
s!$olddbopensha!$newdbopensha!g;
|
|
|
|
}
|
|
|
|
push @xmlines,$_;
|
|
|
|
}
|
|
|
|
seek($primaryxml,0,0);
|
|
|
|
print $primaryxml (@xmlines);
|
|
|
|
truncate($primaryxml,tell($primaryxml));
|
|
|
|
close($primaryxml);
|
|
|
|
@xmlines=();
|
2008-02-01 21:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|