summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOliver Tappe2007-06-17 12:29:17 +0200
committerOliver Tappe2007-06-17 12:29:17 +0200
commit9ba85d5dc63dfd1e16b9ec85d532fe89ee58fd9b (patch)
tree176dc068777af9af1119c55648ec73e78517393e /lib
parentEnabled busybox option to allow longer filenames in tar archives (see (diff)
downloadcore-9ba85d5dc63dfd1e16b9ec85d532fe89ee58fd9b.tar.gz
core-9ba85d5dc63dfd1e16b9ec85d532fe89ee58fd9b.tar.xz
core-9ba85d5dc63dfd1e16b9ec85d532fe89ee58fd9b.zip
largish change with respect to configurable paths:
* instead of supporting configurable paths at different hierarchy levels, there are now only five configurable folder: + base-path (/opt/openslx), fixed at installation time + config-path (/etc/opt/openslx), fixed at installation time + private-path (/var/opt/openslx), freely configurable by user + public-path (/srv/openslx), freely configurable by user + temp-path (/tmp), freely configurable by user this closes ticket#143 * several holes have been plugged concerning the creation of folders before they are accessed, closing ticket#142 * the functionality of generating config default folders has been moved from the Makefile into a new Perl-module (ConfigFolder.pm), in order to be available to the Perl-scripts, too * slxsettings has been changed to reflect the nature of base-path and config-path as fixed paths git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1172 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'lib')
-rw-r--r--lib/OpenSLX/Basics.pm108
-rw-r--r--lib/OpenSLX/ConfigFolder.pm110
2 files changed, 139 insertions, 79 deletions
diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm
index 285a8b4e..38da67d2 100644
--- a/lib/OpenSLX/Basics.pm
+++ b/lib/OpenSLX/Basics.pm
@@ -30,7 +30,7 @@ $VERSION = 1.01;
&addCleanupFunction &removeCleanupFunction
);
-use vars qw(%openslxConfig %cmdlineConfig);
+use vars qw(%openslxConfig %cmdlineConfig %openslxPath);
use subs qw(die);
################################################################################
@@ -52,8 +52,6 @@ my %translations;
# the initial content is based on environment variables or default values.
# Each value may be overridden from config files and/or cmdline arguments.
%openslxConfig = (
- 'croak' => '0',
- 'db-datadir' => $ENV{SLX_DB_DATADIR},
'db-name' => $ENV{SLX_DB_NAME} || 'openslx',
'db-spec' => $ENV{SLX_DB_SPEC},
'db-type' => $ENV{SLX_DB_TYPE} || 'SQLite',
@@ -67,95 +65,57 @@ my %translations;
'verbose-level' => $ENV{SLX_VERBOSE_LEVEL} || '0',
#
+ # options useful during development only:
+ #
+ 'debug-confess' => '0',
+
+ #
# extended settings follow, which are only supported by slxsettings,
# but not by any other script:
#
'ossetup-max-try-count' => '5',
);
chomp($openslxConfig{'locale-charmap'});
-$openslxConfig{'bin-path'} = $ENV{SLX_BIN_PATH}
- || "$openslxConfig{'base-path'}/bin";
-$openslxConfig{'db-basepath'} = $ENV{SLX_DB_PATH}
- || "$openslxConfig{'private-path'}/db";
-$openslxConfig{'export-path'} = $ENV{SLX_EXPORT_PATH}
- || "$openslxConfig{'public-path'}/export";
-$openslxConfig{'share-path'} = $ENV{SLX_SHARE_PATH}
- || "$openslxConfig{'base-path'}/share";
-$openslxConfig{'stage1-path'} = $ENV{SLX_STAGE1_PATH}
- || "$openslxConfig{'private-path'}/stage1";
-$openslxConfig{'tftpboot-path'} = $ENV{SLX_TFTPBOOT_PATH}
- || "$openslxConfig{'public-path'}/tftpboot";
-$openslxConfig{'vmware-path'} = $ENV{SLX_VMWARE_PATH}
- || "$openslxConfig{'base-path'}/vmware";
# specification of cmdline arguments that are shared by all openslx-scripts:
my %openslxCmdlineArgs = (
- 'base-path=s' => \$cmdlineConfig{'base-path'},
-
- # basic path to project files (binaries, functionality templates and
- # distro-specs)
- 'bin-path=s' => \$cmdlineConfig{'bin-path'},
-
- # path to binaries and scripts
- 'config-path=s' => \$cmdlineConfig{'config-path'},
-
- # path to configuration files
- 'croak' => \$cmdlineConfig{'croak'},
-
- # activates debug mode, this will show the lines where any error occured
- 'db-basepath=s' => \$cmdlineConfig{'db-basepath'},
-
- # basic path to openslx database, defaults to "${private-path}/db"
- 'db-datadir=s' => \$cmdlineConfig{'db-datadir'},
-
- # data folder created under db-basepath, default depends on db-type
- 'db-name=s' => \$cmdlineConfig{'db-name'},
-
# name of database, defaults to 'openslx'
- 'db-spec=s' => \$cmdlineConfig{'db-spec'},
+ 'db-name=s' => \$cmdlineConfig{'db-name'},
# full specification of database, a special string defining the
# precise database to connect to (the contents of this string
# depend on db-type)
- 'db-type=s' => \$cmdlineConfig{'db-type'},
+ 'db-spec=s' => \$cmdlineConfig{'db-spec'},
- # type of database to connect to (CSV, SQLite, ...), defaults to 'CSV'
- 'export-path=s' => \$cmdlineConfig{'export-path'},
+ # type of database to connect to (SQLite, mysql, ...), defaults to 'SQLite'
+ 'db-type=s' => \$cmdlineConfig{'db-type'},
- # path to root of all exports, each different export-type (e.g. nfs, nbd)
- # has a separate subfolder in here.
- 'locale=s' => \$cmdlineConfig{'locale'},
+ # activates debug mode, this will show the lines where any error occured
+ # (followed by a stacktrace):
+ 'debug-confess' => \$cmdlineConfig{'debug-confess'},
# locale to use for translations
- 'locale-charmap=s' => \$cmdlineConfig{'locale-charmap'},
+ 'locale=s' => \$cmdlineConfig{'locale'},
# locale-charmap to use for I/O (iso-8859-1, utf-8, etc.)
- 'logfile=s' => \$cmdlineConfig{'locale'},
+ 'locale-charmap=s' => \$cmdlineConfig{'locale-charmap'},
# file to write logging output to, defaults to STDERR
- 'private-path=s' => \$cmdlineConfig{'private-path'},
+ 'logfile=s' => \$cmdlineConfig{'locale'},
# path to private data (which is *not* accesible by clients and contains
# database, vendorOSes and all local extensions [system specific scripts])
- 'public-path=s' => \$cmdlineConfig{'public-path'},
+ 'private-path=s' => \$cmdlineConfig{'private-path'},
# path to public data (which is accesible by clients and contains
# PXE-configurations, kernels, initramfs and client configurations)
- 'share-path=s' => \$cmdlineConfig{'share-path'},
-
- # path to sharable data (functionality templates and distro-specs)
- 'stage1-path=s' => \$cmdlineConfig{'stage1-path'},
-
- # path to stage1 systems
- 'temp-path=s' => \$cmdlineConfig{'temp-path'},
+ 'public-path=s' => \$cmdlineConfig{'public-path'},
# path to temporary data (used during demuxing)
- 'tftpboot-path=s' => \$cmdlineConfig{'tftpboot-path'},
-
- # path to root of tftp-server, tftpable data will be stored there
- 'verbose-level=i' => \$cmdlineConfig{'verbose-level'},
+ 'temp-path=s' => \$cmdlineConfig{'temp-path'},
# level of logging verbosity (0-3)
+ 'verbose-level=i' => \$cmdlineConfig{'verbose-level'},
);
my %cleanupFunctions;
@@ -178,7 +138,6 @@ sub vlog
# ------------------------------------------------------------------------------
sub openslxInit
{
-
# evaluate cmdline arguments:
Getopt::Long::Configure('no_pass_through');
GetOptions(%openslxCmdlineArgs) or return 0;
@@ -186,8 +145,7 @@ sub openslxInit
# try to read and evaluate config files:
my $configPath = $cmdlineConfig{'config-path'}
|| $openslxConfig{'config-path'};
- my $sharePath = $cmdlineConfig{'share-path'}
- || $openslxConfig{'share-path'};
+ my $sharePath = "$openslxConfig{'base-path'}/share";
foreach my $f ("$sharePath/settings.default", "$configPath/settings",
"$ENV{HOME}/.openslx/settings")
{
@@ -265,7 +223,6 @@ sub trInit
}
if (lc($locale) ne 'posix') {
-
# parse locale and canonicalize it (e.g. to 'de_DE') and generate
# two filenames from it (language+country and language only):
if ($locale !~ m{^\s*([^_]+)(?:_(\w+))?}) {
@@ -283,7 +240,6 @@ sub trInit
foreach my $trName (@locales) {
my $trModule = "OpenSLX::Translations::$trName";
if (eval "require $trModule") {
-
# Access OpenSLX::Translations::<locale>::translations
# via a symbolic reference...
no strict 'refs';
@@ -294,14 +250,12 @@ sub trInit
$translations{$k} = $translationsRef->{$k};
}
$loadedTranslationModule = $trModule;
- vlog 1,
- _tr("translations module %s loaded successfully", $trModule);
+ vlog 1, _tr("translations module %s loaded successfully", $trModule);
last;
}
}
if (!defined $loadedTranslationModule) {
- vlog 1,
-"unable to load any translations module for locale '$locale' ($!).";
+ vlog 1, "unable to load any translations module for locale '$locale' ($!).";
}
}
}
@@ -329,7 +283,6 @@ sub callInSubprocess
my $pid = fork();
if (!$pid) {
-
# child...
# ...execute the given function and exit:
&$childFunc();
@@ -355,7 +308,6 @@ sub executeInSubprocess
my $pid = fork();
if (!$pid) {
-
# child...
# ...exec the given cmdline:
exec(@cmdlineArgs);
@@ -398,7 +350,6 @@ sub slxsystem
vlog 2, _tr("executing: %s", join ' ', @_);
my $res = system(@_);
if ($res > 0) {
-
# check if child got killed, if so we stop, too (unless the signal is
# SIGPIPE, which we ignore in order to loop over failed FTP connections
# and the like):
@@ -418,8 +369,8 @@ sub warn
my $msg = shift;
$msg =~ s[^\*\*\* ][]igms;
$msg =~ s[^][*** ]igms;
- if ($openslxConfig{'croak'}) {
- carp $msg;
+ if ($openslxConfig{'debug-confess'}) {
+ Carp::cluck $msg;
}
else {
chomp $msg;
@@ -435,8 +386,8 @@ sub die
my $msg = shift;
$msg =~ s[^\*\*\* ][]igms;
$msg =~ s[^][*** ]igms;
- if ($openslxConfig{'croak'}) {
- croak $msg;
+ if ($openslxConfig{'debug-confess'}) {
+ confess $msg;
}
else {
chomp $msg;
@@ -461,9 +412,8 @@ sub instantiateClass
if (defined $requestedVersion) {
my $classVersion = $class->VERSION;
if ($classVersion < $requestedVersion) {
- die _tr(
-'Could not load class <%s> (Version <%s> required, but <%s> found)',
- $class, $requestedVersion, $classVersion);
+ die _tr('Could not load class <%s> (Version <%s> required, but <%s> found)',
+ $class, $requestedVersion, $classVersion);
}
}
return $class->new;
diff --git a/lib/OpenSLX/ConfigFolder.pm b/lib/OpenSLX/ConfigFolder.pm
new file mode 100644
index 00000000..0c957ef5
--- /dev/null
+++ b/lib/OpenSLX/ConfigFolder.pm
@@ -0,0 +1,110 @@
+# Copyright (c) 2006, 2007 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# ConfigFolder.pm
+# - provides utility functions for generation of configuration folders
+# -----------------------------------------------------------------------------
+package OpenSLX::ConfigFolder;
+
+use strict;
+use vars qw(@ISA @EXPORT $VERSION);
+
+use Exporter;
+$VERSION = 1.01;
+@ISA = qw(Exporter);
+
+@EXPORT = qw(
+ &createConfigFolderForDefaultSystem
+ &createConfigFolderForSystem
+);
+
+################################################################################
+### Module implementation
+################################################################################
+use Carp;
+use OpenSLX::Basics;
+
+sub createConfigFolderForDefaultSystem
+{
+ my $result = 0;
+ my $defaultConfigPath = "$openslxConfig{'private-path'}/config/default";
+ if (!-e "$defaultConfigPath/initramfs") {
+ slxsystem("mkdir -p $defaultConfigPath/initramfs");
+ $result = 1;
+ }
+ if (!-e "$defaultConfigPath/rootfs") {
+ slxsystem("mkdir -p $defaultConfigPath/rootfs");
+ $result = 1;
+ }
+
+ # create default pre-/postinit scripts for us in initramfs:
+ my $preInitFile = "$defaultConfigPath/initramfs/preinit.local";
+ if (!-e $preInitFile) {
+ open(PREINIT, "> $preInitFile")
+ or die _tr("Unable to create file '%s'!", $preInitFile);
+ my $preInit = <<' END'
+ #!/bin/sh
+ #
+ # This script allows the local admin to extend the
+ # capabilities at the beginning of the initramfs (stage3).
+ # The toolset is rather limited and you have to keep in mind
+ # that stage4 rootfs has the prefix '/mnt'.
+ END
+ ;
+ $preInit =~ s[^\s+][]igms;
+ print PREINIT $preInit;
+ close(PREINIT);
+ slxsystem("chmod u+x $preInitFile");
+ $result = 1;
+ }
+
+ my $postInitFile = "$defaultConfigPath/initramfs/postinit.local";
+ if (!-e $postInitFile) {
+ open(POSTINIT, "> $postInitFile")
+ or die _tr("Unable to create file '%s'!", $postInitFile);
+ my $postInit = <<' END'
+ #!/bin/sh
+ #
+ # This script allows the local admin to extend the
+ # capabilities at the end of the initramfs (stage3).
+ # The toolset is rather limited and you have to keep in mind
+ # that stage4 rootfs has the prefix '/mnt'.
+ # But you may use some special slx-functions available via
+ # inclusion: '. /etc/functions' ...
+ END
+ ;
+ $postInit =~ s[^\s+][]igms;
+ print POSTINIT $postInit;
+ close(POSTINIT);
+ slxsystem("chmod u+x $postInitFile");
+ $result = 1;
+ }
+ return $result;
+}
+
+sub createConfigFolderForSystem
+{
+ my $systemName = shift || confess "need to pass in system-name!";
+
+ my $result = 0;
+ my $systemConfigPath
+ = "$openslxConfig{'private-path'}/config/$systemName/default";
+ if (!-e "$systemConfigPath/initramfs") {
+ slxsystem("mkdir -p $systemConfigPath/initramfs");
+ $result = 1;
+ }
+ if (!-e "$systemConfigPath/rootfs") {
+ slxsystem("mkdir -p $systemConfigPath/rootfs");
+ $result = 1;
+ }
+ return $result;
+}
+
+1;