diff options
author | Oliver Tappe | 2007-07-25 21:30:02 +0200 |
---|---|---|
committer | Oliver Tappe | 2007-07-25 21:30:02 +0200 |
commit | cedf72c7559e96d07fefdf55dc007aeb6bca1ca0 (patch) | |
tree | 3b2cc5a1b0817b52001f30a0ee31ddd65b8732dd /lib/OpenSLX/Utils.pm | |
parent | * fixed bug in check for required kernel modules for distros that do not (diff) | |
download | core-cedf72c7559e96d07fefdf55dc007aeb6bca1ca0.tar.gz core-cedf72c7559e96d07fefdf55dc007aeb6bca1ca0.tar.xz core-cedf72c7559e96d07fefdf55dc007aeb6bca1ca0.zip |
* reworked OpenSLX::OSSetup::Distro structure to incorporate
a distro specific hierarchy level in addition to the
distro & version specific files. The latter will be converted
to config-files soon.
* moved string2Array() and chrootInto() from
OpenSLX::OSSetup::Engine to OpenSLX::Utils to make them
available to other callers
* started work on ubuntu & debian installation (not done yet)
* cleaned interface of OpenSLX::OSSetup::Engine (separated
public from private methods)
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1275 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib/OpenSLX/Utils.pm')
-rw-r--r-- | lib/OpenSLX/Utils.pm | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/lib/OpenSLX/Utils.pm b/lib/OpenSLX/Utils.pm index d23eb6e8..fdb1192c 100644 --- a/lib/OpenSLX/Utils.pm +++ b/lib/OpenSLX/Utils.pm @@ -23,7 +23,13 @@ $VERSION = 1.01; @ISA = qw(Exporter); @EXPORT = qw( - copyFile fakeFile linkFile slurpFile spitFile followLink unshiftHereDoc + copyFile fakeFile linkFile + copyBinaryWithRequiredLibs + slurpFile spitFile + followLink + unshiftHereDoc + string2Array + chrootInto ); ################################################################################ @@ -88,7 +94,7 @@ sub slurpFile my $fileName = shift || confess 'need to pass in fileName!'; my $flags = shift || {}; - checkFlags($flags, ['failIfMissing']); + checkParams($flags, { 'failIfMissing' => '?' }); my $failIfMissing = exists $flags->{failIfMissing} ? $flags->{failIfMissing} : 1; @@ -137,6 +143,39 @@ sub followLink return $path; } +sub copyBinaryWithRequiredLibs { + my $params = shift; + + checkParams($params, { + 'binary' => '!', # file to copy + 'targetFolder' => '!', # where file shall be copied to + 'libTargetFolder' => '!', # base target folder for libs + 'targetName' => '?', # name of binary in target folder + }); + copyFile($params->{binary}, $params->{targetFolder}, $params->{targetName}); + + # determine all required libraries and copy those, too: + vlog(1, _tr("calling slxldd for $params->{binary}")); + my $slxlddCmd = "slxldd $params->{binary}"; + vlog(2, "executing: $slxlddCmd"); + my $requiredLibsStr = qx{$slxlddCmd}; + if ($?) { + die _tr( + "slxldd couldn't determine the libs required by '%s'! (%s)", + $params->{binary}, $? + ); + } + chomp $requiredLibsStr; + vlog(2, "slxldd results:\n$requiredLibsStr"); + + foreach my $lib (split "\n", $requiredLibsStr) { + vlog(3, "copying lib '$lib'"); + my $libDir = dirname($lib); + copyFile($lib, "$params->{libTargetFolder}$libDir"); + } + return $requiredLibsStr; +} + sub unshiftHereDoc { my $content = shift; @@ -148,4 +187,34 @@ sub unshiftHereDoc split m{\n}, $content; } +sub string2Array +{ + my $string = shift || ''; + + my @lines = split m[\n], $string; + for my $line (@lines) { + # remove leading and trailing whitespace: + $line =~ s{^\s*(.*?)\s*$}{$1}; + } + + # drop empty lines and comments: + return grep { length($_) > 0 && $_ !~ m[^\s*#]; } @lines; +} + +sub chrootInto +{ + my $osDir = shift; + + vlog(2, "chrooting into $osDir..."); + chdir $osDir + or die _tr("unable to chdir into '%s' (%s)\n", $osDir, $!); + + # ...do chroot + chroot "." + or die _tr("unable to chroot into '%s' (%s)\n", $osDir, $!); + + $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin"; + return; +} + 1; |