From cbce11c51c6aa5674b01821a7adc7c31f7999c7e Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 28 Jul 2007 14:11:27 +0000 Subject: * changed several class interfaces as a result of trying to integrate support for Debian & Ubunto installation (which is still not complete, though) * fixed some bugs along the way (especially the meta-packagers trying to invoke a private function of OpenSLX::OSSetup::Engine) git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1281 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSSetup/Distro/Base.pm | 62 +++++++- installer/OpenSLX/OSSetup/Distro/SUSE.pm | 6 +- installer/OpenSLX/OSSetup/Distro/SUSE_10_1.pm | 2 +- installer/OpenSLX/OSSetup/Distro/Ubuntu_6_10.pm | 7 +- installer/OpenSLX/OSSetup/Engine.pm | 183 +++++++++++++----------- installer/OpenSLX/OSSetup/MetaPackager/Base.pm | 27 ---- installer/OpenSLX/OSSetup/MetaPackager/smart.pm | 8 +- installer/OpenSLX/OSSetup/MetaPackager/yum.pm | 8 +- installer/OpenSLX/OSSetup/Packager/dpkg.pm | 8 +- 9 files changed, 180 insertions(+), 131 deletions(-) (limited to 'installer') diff --git a/installer/OpenSLX/OSSetup/Distro/Base.pm b/installer/OpenSLX/OSSetup/Distro/Base.pm index 9b59a828..020215ea 100644 --- a/installer/OpenSLX/OSSetup/Distro/Base.pm +++ b/installer/OpenSLX/OSSetup/Distro/Base.pm @@ -20,6 +20,7 @@ our $VERSION = 1.01; # API-version . implementation-version use File::Basename; use OpenSLX::Basics; +use OpenSLX::Utils; ################################################################################ ### interface methods @@ -121,6 +122,63 @@ sub initDistroInfo sub startSession { + my $self = shift; + my $osDir = shift; + + # ensure that the session will be finished even if the script crashes: + addCleanupFunction( + "slxos-setup::distro::chroot", sub { $self->finishSession(); } + ); + + # make sure there's a /dev/zero and /dev/null + if (!-e "$osDir/dev" && !mkdir("$osDir/dev")) { + die _tr("unable to create folder '%s' (%s)\n", "$osDir/dev", $!); + } + if (!-e "$osDir/dev/zero" && slxsystem("mknod $osDir/dev/zero c 1 5")) { + die _tr("unable to create node '%s' (%s)\n", "$osDir/dev/zero", $!); + } + if (!-e "$osDir/dev/null" && slxsystem("mknod $osDir/dev/null c 1 3")) { + die _tr("unable to create node '%s' (%s)\n", "$osDir/dev/null", $!); + } + + # fake proc, depending on what is needed ... + if (!-e "$osDir/proc" && !mkdir("$osDir/proc")) { + die _tr("unable to create folder '%s' (%s)\n", "$osDir/proc", $!); + } + if (!-e "$osDir/proc/cpuinfo" && slxsystem("cp /proc/cpuinfo $osDir/proc/")) { + die _tr("unable to copy file '%s' (%s)\n", "/proc/cpuinfo", $!); + } + # TODO: alternatively, we could mount proc, but that causes problems + # when we are not able to umount it properly (which may happen + # if 'umount' is not available in the chroot!) + # + # mount /proc +# if (!-e "$osDir/proc") { +# slxsystem("mkdir -p $osDir/proc"); +# } +# if (slxsystem("mount -t proc proc $osDir/proc 2>/dev/null")) { +# die _tr("unable to mount '%s' (%s)\n", "$osDir/proc", $!); +# } + + # enter chroot jail + chrootInto($osDir); + $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin"; + + return; +} + +sub finishSession +{ + my $self = shift; + + removeCleanupFunction('slxos-setup::distro::chroot'); + + # unmount /proc +# if (slxsystem('ash', '-c', 'umount /proc 2>/dev/null')) { +# die _tr("unable to unmount '%s' (%s)\n", "/proc", $!); +# } + + return; } sub updateDistroConfig @@ -130,10 +188,6 @@ sub updateDistroConfig } } -sub finishSession -{ -} - sub pickKernelFile { my $self = shift; diff --git a/installer/OpenSLX/OSSetup/Distro/SUSE.pm b/installer/OpenSLX/OSSetup/Distro/SUSE.pm index 065fbf2c..0662cd64 100644 --- a/installer/OpenSLX/OSSetup/Distro/SUSE.pm +++ b/installer/OpenSLX/OSSetup/Distro/SUSE.pm @@ -49,12 +49,8 @@ sub updateDistroConfig { my $self = shift; - # make sure there's a /dev/zero, as SuSEconfig requires it: - if (!-e "/dev/zero" && slxsystem("mknod /dev/zero c 1 5")) { - die _tr("unable to create node '%s' (%s)\n", "/dev/zero", $!); - } # invoke SuSEconfig in order to allow it to update the configuration: - if (slxsystem("SuSEconfig")) { + if (slxsystem('SuSEconfig')) { die _tr("unable to run SuSEconfig (%s)", $!); } $self->SUPER::updateDistroConfig(); diff --git a/installer/OpenSLX/OSSetup/Distro/SUSE_10_1.pm b/installer/OpenSLX/OSSetup/Distro/SUSE_10_1.pm index 27125f41..3a00dd0c 100644 --- a/installer/OpenSLX/OSSetup/Distro/SUSE_10_1.pm +++ b/installer/OpenSLX/OSSetup/Distro/SUSE_10_1.pm @@ -57,7 +57,7 @@ sub initDistroInfo ftp://ftp.estpak.ee/pub/suse/opensuse/distribution/SL-10.1/non-oss-inst-source ftp://ftp.jaist.ac.jp/pub/Linux/openSUSE/distribution/SL-10.1/non-oss-inst-source ", - 'name' => 'openSUSE 10.2 non-OSS', + 'name' => 'openSUSE 10.1 non-OSS', 'repo-subdir' => 'suse', }, 'base_update' => { diff --git a/installer/OpenSLX/OSSetup/Distro/Ubuntu_6_10.pm b/installer/OpenSLX/OSSetup/Distro/Ubuntu_6_10.pm index 4225b9aa..2882212f 100644 --- a/installer/OpenSLX/OSSetup/Distro/Ubuntu_6_10.pm +++ b/installer/OpenSLX/OSSetup/Distro/Ubuntu_6_10.pm @@ -27,7 +27,9 @@ sub new { my $class = shift; my $self = { - 'base-name' => 'ubuntu-6.10', + 'base-name' => 'ubuntu-6.10', + 'arch' => 'i386', + 'release-name' => 'edgy', }; return bless $self, $class; } @@ -38,6 +40,7 @@ sub initDistroInfo $self->{config}->{'repository'} = { 'base' => { 'urls' => " + ftp://localhost/pub/ubuntu ", 'name' => 'Ubuntu 6.10', 'repo-subdir' => 'dists/edgy', @@ -47,7 +50,7 @@ sub initDistroInfo $self->{config}->{'package-subdir'} = 'pool'; $self->{config}->{'prereq-packages'} = " - main/d/debootstrap/debootstrap_0.3.3.0ubuntu7_all.deb + main/d/debootstrap/debootstrap_1.0.0_all.deb "; $self->{config}->{'bootstrap-prereq-packages'} = " diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index d55277d7..a89f6e10 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -432,8 +432,9 @@ sub startChrootedShellForVendorOS sub callChrootedFunctionForVendorOS { - my $self = shift; - my $function = shift; + my $self = shift; + my $function = shift; + my $updateConfig = shift || 0; if (!-e $self->{'vendor-os-path'}) { die _tr( @@ -447,7 +448,11 @@ sub callChrootedFunctionForVendorOS callInSubprocess( sub { $self->_changePersonalityIfNeeded(); - $self->_callChrootedFunctionInStage1D($function); + $self->_callChrootedFunction({ + chrootDir => $self->{'vendor-os-path'}, + function => $function, + updateConfig => $updateConfig, + }); } ); @@ -746,12 +751,10 @@ sub _sortRepositoryURLs my $self = shift; my $repoInfo = shift; - if (defined $repoInfo->{'url'} && $repoInfo->{'url'} =~ m[^local:]) { + if (defined $repoInfo->{'url'} && $repoInfo->{'avoid-mirrors'}) { # a local URL blocks all the others, in order to avoid causing - # (external) network traffic: - my $localURL = $repoInfo->{'url'} || ''; - $localURL =~ s[^local:][http:]; - return [$localURL]; + # (external) network traffic, so we return the local URL only: + return [$repoInfo->{'url'}]; } my %urlInfo; @@ -832,7 +835,8 @@ sub _startLocalURLServersAsNeeded my $port = 5080; foreach my $repoInfo (values %{$self->{'distro-info'}->{repository}}) { my $localURL = $repoInfo->{url} || ''; - next if $localURL =~ m[^\w+:]; + next if !$localURL; + next if $localURL =~ m[^\w+:]; # anything with a protcol-spec is non-local if (!exists $self->{'local-http-servers'}->{$localURL}) { my $busyboxName = $self->_hostIs64Bit() @@ -1048,38 +1052,42 @@ sub _stage1B_chrootAndBootstrap # give packager a chance to copy required files into stage1a-folder: $self->{packager}->prepareBootstrap($self->{stage1aDir}); - chrootInto($self->{stage1aDir}); - - # chdir into slxbootstrap, as we want to drop packages into there: - chdir "/$self->{stage1bSubdir}" - or die _tr( - "unable to chdir into '%s' (%s)\n", "/$self->{stage1bSubdir}", $! - ); + $self->_callChrootedFunction({ + chrootDir => $self->{stage1aDir}, + function => sub { + # chdir into slxbootstrap, as we want to drop packages into there: + chdir "/$self->{stage1bSubdir}" + or die _tr( + "unable to chdir into '%s' (%s)\n", + "/$self->{stage1bSubdir}", $! + ); - # fetch prerequired packages and use them to bootstrap the packager: - $self->{'baseURLs'} = $self->_sortRepositoryURLs( - $self->{'distro-info'}->{repository}->{base} - ); - $self->{'baseURL-index'} = 0; - my @pkgs = string2Array($self->{'distro-info'}->{'prereq-packages'}); - my @prereqPkgs = $self->_downloadBaseFiles(\@pkgs); - $self->{packager}->bootstrap(\@prereqPkgs); - - @pkgs = string2Array($self->{'distro-info'}->{'bootstrap-prereq-packages'}); - my @bootstrapPrereqPkgs = $self->_downloadBaseFiles(\@pkgs); - $self->{'bootstrap-prereq-packages'} = \@bootstrapPrereqPkgs; - - @pkgs = string2Array($self->{'distro-info'}->{'bootstrap-packages'}); - push( - @pkgs, - string2Array( - $self->{'distro-info'}->{'metapackager-packages'} - ->{$self->{distro}->{'meta-packager-type'}} - ) - ); - my @bootstrapPkgs = $self->_downloadBaseFiles(\@pkgs); - my @allPkgs = (@prereqPkgs, @bootstrapPrereqPkgs, @bootstrapPkgs); - $self->{'bootstrap-packages'} = \@allPkgs; + # fetch prerequired packages and use them to bootstrap the packager: + $self->{'baseURLs'} = $self->_sortRepositoryURLs( + $self->{'distro-info'}->{repository}->{base} + ); + $self->{'baseURL-index'} = 0; + my @pkgs = string2Array($self->{'distro-info'}->{'prereq-packages'}); + my @prereqPkgs = $self->_downloadBaseFiles(\@pkgs); + $self->{packager}->bootstrap(\@prereqPkgs); + + @pkgs = string2Array($self->{'distro-info'}->{'bootstrap-prereq-packages'}); + my @bootstrapPrereqPkgs = $self->_downloadBaseFiles(\@pkgs); + $self->{'bootstrap-prereq-packages'} = \@bootstrapPrereqPkgs; + + @pkgs = string2Array($self->{'distro-info'}->{'bootstrap-packages'}); + push( + @pkgs, + string2Array( + $self->{'distro-info'}->{'metapackager-packages'} + ->{$self->{distro}->{'meta-packager-type'}} + ) + ); + my @bootstrapPkgs = $self->_downloadBaseFiles(\@pkgs); + my @allPkgs = (@prereqPkgs, @bootstrapPrereqPkgs, @bootstrapPkgs); + $self->{'bootstrap-packages'} = \@allPkgs; + }, + }); return; } @@ -1153,11 +1161,15 @@ sub _setupStage1D vlog(1, "setting up stage1d for $self->{'vendor-os-name'}..."); - chrootInto($self->{'vendor-os-path'}); - - $self->_stage1D_setupPackageSources(); - $self->_stage1D_updateBasicVendorOS(); - $self->_stage1D_installPackageSelection(); + $self->_callChrootedFunction({ + chrootDir => $self->{'vendor-os-path'}, + function => sub { + $self->_stage1D_setupPackageSources(); + $self->_stage1D_updateBasicVendorOS(); + $self->_stage1D_installPackageSelection(); + }, + updateConfig => 1, + }); return; } @@ -1167,9 +1179,13 @@ sub _updateStage1D vlog(1, "updating $self->{'vendor-os-name'}..."); - chrootInto($self->{'vendor-os-path'}); - - $self->_stage1D_updateBasicVendorOS(); + $self->_callChrootedFunction({ + chrootDir => $self->{'vendor-os-path'}, + function => sub { + $self->_stage1D_updateBasicVendorOS(); + }, + updateConfig => 1, + }); return; } @@ -1182,32 +1198,37 @@ sub _startChrootedShellInStage1D vlog(0, "- please type 'exit' if you are done! -"); vlog(0, "---------------------------------------"); - chrootInto($self->{'vendor-os-path'}); - - $self->{'meta-packager'}->startSession(); - - # will hang until user exits manually: - slxsystem('sh'); - - $self->{'distro'}->updateDistroConfig(); - $self->{'meta-packager'}->finishSession(); + $self->_callChrootedFunction({ + chrootDir => $self->{'vendor-os-path'}, + function => sub { + # will hang until user exits manually: + slxsystem('sh'); + }, + updateConfig => 1, + }); return; } -sub _callChrootedFunctionInStage1D +sub _callChrootedFunction { - my $self = shift; - my $function = shift; - - chrootInto($self->{'vendor-os-path'}); + my $self = shift; + my $params = shift; + + checkParams($params, { + 'chrootDir' => '!', + 'function' => '!', + 'updateConfig' => '?', + }); - $self->{'meta-packager'}->startSession(); + $self->{'distro'}->startSession($params->{chrootDir}); # invoke given function: - $function->(); + $params->{function}->(); - $self->{'distro'}->updateDistroConfig(); - $self->{'meta-packager'}->finishSession(); + if ($params->{updateConfig}) { + $self->{'distro'}->updateDistroConfig(); + } + $self->{'distro'}->finishSession(); return; } @@ -1223,7 +1244,9 @@ sub _stage1D_setupPackageSources my ($rk, $repo); while (($rk, $repo) = each %{$self->{'distro-info'}->{repository}}) { vlog(2, "setting up package source $rk..."); - $self->{'meta-packager'}->setupPackageSource($rk, $repo, $excludeList); + $self->{'meta-packager'}->setupPackageSource( + $rk, $repo, $excludeList, $self->_sortRepositoryURLs($repo) + ); } return; } @@ -1233,10 +1256,7 @@ sub _stage1D_updateBasicVendorOS my $self = shift; vlog(1, "updating basic vendor-os..."); - $self->{'meta-packager'}->startSession(); $self->{'meta-packager'}->updateBasicVendorOS(); - $self->{'distro'}->updateDistroConfig(); - $self->{'meta-packager'}->finishSession(); return; } @@ -1260,20 +1280,19 @@ sub _stage1D_installPackageSelection 1; } } @pkgs; - vlog( - 0, - _tr( - "No packages listed for selection '%s', nothing to do.", - $selectionName - ) - ); - vlog(1, "installing these packages:\n" . join("\n\t", @pkgs)); - $self->{'meta-packager'}->startSession(); - if (scalar(@pkgs) > 0) { + if (!@pkgs) { + vlog( + 0, + _tr( + "No packages listed for selection '%s', nothing to do.", + $selectionName + ) + ); + } + else { + vlog(1, "installing these packages:\n" . join("\n\t", @pkgs)); $self->{'meta-packager'}->installSelection(join " ", @pkgs); } - $self->{'distro'}->updateDistroConfig(); - $self->{'meta-packager'}->finishSession(); return; } diff --git a/installer/OpenSLX/OSSetup/MetaPackager/Base.pm b/installer/OpenSLX/OSSetup/MetaPackager/Base.pm index d5b42f20..dd552071 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/Base.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/Base.pm @@ -53,33 +53,6 @@ sub installSelection { } -sub startSession -{ - my $self = shift; - - addCleanupFunction('slxos-setup::meta-packager', - sub { $self->finishSession(); } ); - - system('mount -t proc proc /proc 2>/dev/null'); - - $self->{engine}->{distro}->startSession(); - # allow vendor specific extensions - return; -} - -sub finishSession -{ - my $self = shift; - - $self->{engine}->{distro}->finishSession(); - # allow vendor specific extensions - - system('umount /proc 2>/dev/null'); - - removeCleanupFunction('slxos-setup::meta-packager'); - return; -} - 1; ################################################################################ diff --git a/installer/OpenSLX/OSSetup/MetaPackager/smart.pm b/installer/OpenSLX/OSSetup/MetaPackager/smart.pm index 3b266ee7..5303a50a 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/smart.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/smart.pm @@ -57,16 +57,16 @@ sub initPackageSources sub setupPackageSource { - my $self = shift; - my $repoName = shift; - my $repoInfo = shift; + my $self = shift; + my $repoName = shift; + my $repoInfo = shift; my $excludeList = shift; + my $repoURLs = shift; my $repoSubdir = ''; if (length($repoInfo->{'repo-subdir'})) { $repoSubdir = "/$repoInfo->{'repo-subdir'}"; } - my $repoURLs = $self->{engine}->sortRepositoryURLs($repoInfo); my $baseURL = shift @$repoURLs; my $repoDescr = qq[$repoName name="$repoInfo->{name}" baseurl=$baseURL$repoSubdir]; diff --git a/installer/OpenSLX/OSSetup/MetaPackager/yum.pm b/installer/OpenSLX/OSSetup/MetaPackager/yum.pm index 77ac11d1..684d125b 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/yum.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/yum.pm @@ -54,16 +54,16 @@ sub initPackageSources sub setupPackageSource { - my $self = shift; - my $repoName = shift; - my $repoInfo = shift; + my $self = shift; + my $repoName = shift; + my $repoInfo = shift; my $excludeList = shift; + my $repoURLs = shift; my $repoSubdir; if (length($repoInfo->{'repo-subdir'})) { $repoSubdir = "/$repoInfo->{'repo-subdir'}"; } - my $repoURLs = $self->{engine}->sortRepositoryURLs($repoInfo); my $baseURL = shift @$repoURLs; my $repoDescr diff --git a/installer/OpenSLX/OSSetup/Packager/dpkg.pm b/installer/OpenSLX/OSSetup/Packager/dpkg.pm index cdd55e56..01867824 100644 --- a/installer/OpenSLX/OSSetup/Packager/dpkg.pm +++ b/installer/OpenSLX/OSSetup/Packager/dpkg.pm @@ -63,8 +63,12 @@ sub bootstrap if (slxsystem("ash", "-c", "rm -f debian-binary *.tar.gz")) { die _tr("unable to cleanup package '%s' (%s)", $debootstrapPkg, $!); } + my $arch = $self->{engine}->{distro}->{arch}; + my $releaseName = $self->{engine}->{distro}->{'release-name'}; + my $baseURL = $self->{engine}->{baseURLs}->[0]; my $debootstrapCmd = <<" END-OF-HERE"; - /usr/sbin/debootstrap --arch i386 edgy /slxbootstrap/slxfinal http://localhost:5080/srv/ftp/pub/ubuntu + /usr/sbin/debootstrap --verbose --arch $arch $releaseName \\ + /slxbootstrap/slxfinal $baseURL END-OF-HERE if (slxsystem("ash", "-c", "/bin/ash $debootstrapCmd")) { die _tr("unable to run debootstrap (%s)", $!); @@ -78,7 +82,7 @@ sub installPackages my $pkgs = shift; my $finalPath = shift; - return unless defined $pkgs && scalar(@$pkgs); + return unless defined $pkgs && @$pkgs; if (slxsystem("rpm", "--root=$finalPath", "-ivh", @$pkgs)) { die _tr("error during package-installation (%s)\n", $!); -- cgit v1.2.3-55-g7522