Generic Yum repository fixup for copycds and the anaconda platforms
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@378 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
c00ac45f26
commit
0f029bcc8d
88
perl-xCAT-2.0/xCAT/Yum.pm
Normal file
88
perl-xCAT-2.0/xCAT/Yum.pm
Normal file
@ -0,0 +1,88 @@
|
||||
package xCAT::Yum;
|
||||
use DBI;
|
||||
use File::Find;
|
||||
sub localize_yumrepo {
|
||||
my $self = shift;
|
||||
my $installroot = shift;
|
||||
my $distname = shift;
|
||||
my $arch = shift;
|
||||
my $dosqlite = 0;
|
||||
my $repomdfile;
|
||||
my $primaryxml;
|
||||
my @xmlines;
|
||||
my $dirlocation = "$installroot/$distname/$arch/";
|
||||
find(\&check_tofix,$dirlocation);
|
||||
}
|
||||
sub check_tofix {
|
||||
if (-d $File::Find::name and $File::Find::name =~ /\/repodata$/) {
|
||||
fix_directory($File::Find::name);
|
||||
}
|
||||
}
|
||||
sub fix_directory {
|
||||
my $dirlocation = shift;
|
||||
my $oldsha=`/usr/bin/sha1sum $dirlocation/primary.xml.gz`;
|
||||
my $olddbsha;
|
||||
$oldsha =~ s/\s.*//;
|
||||
chomp($oldsha);
|
||||
unlink("$dirlocation/primary.xml");
|
||||
system("/bin/gunzip $dirlocation/primary.xml.gz");
|
||||
my $oldopensha=`/usr/bin/sha1sum $dirlocation/primary.xml`;
|
||||
$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);
|
||||
my $newopensha=`/usr/bin/sha1sum $dirlocation/primary.xml`;
|
||||
system("/bin/gzip $dirlocation/primary.xml");
|
||||
my $newsha=`/usr/bin/sha1sum $dirlocation/primary.xml.gz`;
|
||||
$newopensha =~ s/\s.*//;
|
||||
$newsha =~ s/\s.*//;
|
||||
chomp($newopensha);
|
||||
chomp($newsha);
|
||||
my $newdbsha;
|
||||
my $newdbopensha;
|
||||
my $olddbopensha;
|
||||
if (-r "$dirlocation/primary.sqlite.bz2") {
|
||||
$olddbsha =`/usr/bin/sha1sum $dirlocation/primary.sqlite.bz2`;
|
||||
$olddbsha =~ s/\s.*//;
|
||||
chomp($olddbsha);
|
||||
unlink("$dirlocation/primary.sqlite");
|
||||
system("/usr/bin/bunzip2 $dirlocation/primary.sqlite.bz2");
|
||||
$olddbopensha=`/usr/bin/sha1sum $dirlocation/primary.sqlite`;
|
||||
$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;
|
||||
$newdbopensha=`/usr/bin/sha1sum $dirlocation/primary.sqlite`;
|
||||
system("/usr/bin/bzip2 $dirlocation/primary.sqlite");
|
||||
$newdbsha=`/usr/bin/sha1sum $dirlocation/primary.sqlite.bz2`;
|
||||
$newdbopensha =~ s/\s.*//;
|
||||
$newdbsha =~ s/\s.*//;
|
||||
chomp($newdbopensha);
|
||||
chomp($newdbsha);
|
||||
}
|
||||
open($primaryxml,"+<$dirlocation/repomd.xml");
|
||||
while (<$primaryxml>) {
|
||||
s!xml:base="media://[^"]*"!!g;
|
||||
s!$oldsha!$newsha!g;
|
||||
s!$oldopensha!$newopensha!g;
|
||||
if ($olddbsha) { s!$olddbsha!$newdbsha!g; }
|
||||
if ($olddbsha) { s!$olddbopensha!$newdbopensha!g; }
|
||||
push @xmlines,$_;
|
||||
}
|
||||
seek($primaryxml,0,0);
|
||||
print $primaryxml (@xmlines);
|
||||
truncate($primaryxml,tell($primaryxml));
|
||||
close($primaryxml);
|
||||
}
|
||||
|
||||
|
||||
1;
|
@ -325,6 +325,7 @@ sub copycd {
|
||||
umask $omask;
|
||||
my $rc = system("cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch");
|
||||
chmod 0755,"$installroot/$distname/$arch";
|
||||
xCAT::Yum->localize_yumrepo($installroot,$distname,$arch);
|
||||
if ($rc != 0) {
|
||||
$callback->({error=>"Media copy operation failed, status $rc"});
|
||||
} else {
|
||||
|
@ -3,6 +3,7 @@ package xCAT_plugin::fedora;
|
||||
use Storable qw(dclone);
|
||||
use Sys::Syslog;
|
||||
use DBI;
|
||||
use xCAT::Yum;
|
||||
use xCAT::Table;
|
||||
use xCAT::Template;
|
||||
use xCAT::Postage;
|
||||
@ -335,65 +336,7 @@ sub copycd {
|
||||
#my $rc = system("cd $path; find . | cpio -dump $installroot/$distname/$arch");
|
||||
my $rc = system("cd $path;rsync -a . $installroot/$distname/$arch/");
|
||||
chmod 0755,"$installroot/$distname/$arch";
|
||||
my $repomdfile;
|
||||
my $primaryxml;
|
||||
my @xmlines;
|
||||
my $oldsha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.xml.gz`;
|
||||
my $olddbsha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.sqlite.bz2`;
|
||||
$oldsha =~ s/\s.*//;
|
||||
chomp($oldsha);
|
||||
$olddbsha =~ s/\s.*//;
|
||||
chomp($olddbsha);
|
||||
unlink("$installroot/$distname/$arch/repodata/primary.sqlite");
|
||||
unlink("$installroot/$distname/$arch/repodata/primary.xml");
|
||||
system("/usr/bin/bunzip2 $installroot/$distname/$arch/repodata/primary.sqlite.bz2");
|
||||
system("/bin/gunzip $installroot/$distname/$arch/repodata/primary.xml.gz");
|
||||
my $oldopensha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.xml`;
|
||||
$oldopensha =~ s/\s+.*//;
|
||||
chomp($oldopensha);
|
||||
my $olddbopensha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.sqlite`;
|
||||
$olddbopensha =~ s/\s+.*//;
|
||||
chomp($olddbopensha);
|
||||
my $pdbh = DBI->connect("dbi:SQLite:$installroot/$distname/$arch/repodata/primary.sqlite","","",{AutoCommit=>1});
|
||||
$pdbh->do('UPDATE "packages" SET "location_base" = NULL');
|
||||
$pdbh->disconnect;
|
||||
open($primaryxml,"+<$installroot/$distname/$arch/repodata/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);
|
||||
my $newopensha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.xml`;
|
||||
my $newdbopensha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.sqlite`;
|
||||
system("/bin/gzip $installroot/$distname/$arch/repodata/primary.xml");
|
||||
system("/usr/bin/bzip2 $installroot/$distname/$arch/repodata/primary.sqlite");
|
||||
my $newsha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.xml.gz`;
|
||||
my $newdbsha=`/usr/bin/sha1sum $installroot/$distname/$arch/repodata/primary.sqlite.bz2`;
|
||||
$newopensha =~ s/\s.*//;
|
||||
$newdbopensha =~ s/\s.*//;
|
||||
$newsha =~ s/\s.*//;
|
||||
$newdbsha =~ s/\s.*//;
|
||||
chomp($newopensha);
|
||||
chomp($newdbopensha);
|
||||
chomp($newsha);
|
||||
chomp($newdbsha);
|
||||
open($primaryxml,"+<$installroot/$distname/$arch/repodata/repomd.xml");
|
||||
while (<$primaryxml>) {
|
||||
s!xml:base="media://[^"]*"!!g;
|
||||
s!$oldsha!$newsha!g;
|
||||
s!$oldopensha!$newopensha!g;
|
||||
s!$olddbsha!$newdbsha!g;
|
||||
s!$olddbopensha!$newdbopensha!g;
|
||||
push @xmlines,$_;
|
||||
}
|
||||
seek($primaryxml,0,0);
|
||||
print $primaryxml (@xmlines);
|
||||
truncate($primaryxml,tell($primaryxml));
|
||||
close($primaryxml);
|
||||
xCAT::Yum->localize_yumrepo($installroot,$distname,$arch);
|
||||
if ($rc != 0) {
|
||||
$callback->({error=>"Media copy operation failed, status $rc"});
|
||||
} else {
|
||||
|
@ -342,6 +342,7 @@ sub copycd {
|
||||
umask $omask;
|
||||
my $rc = system("cd $path; find . | cpio -dump $installroot/$distname/$arch");
|
||||
chmod 0755,"$installroot/$distname/$arch";
|
||||
xCAT::Yum->localize_yumrepo($installroot,$distname,$arch);
|
||||
if ($rc != 0) {
|
||||
$callback->({error=>"Media copy operation failed, status $rc"});
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user