diff options
author | Oliver Tappe | 2006-09-29 15:21:13 +0200 |
---|---|---|
committer | Oliver Tappe | 2006-09-29 15:21:13 +0200 |
commit | cc5584b2bf8955b6e3a28f877369b3be266f0e88 (patch) | |
tree | e37acf4880cce2c973a0a80631f85191dc6d8af3 /config-db | |
parent | * added SLX_TFTPBOOT_PATH and SLX_TEMP_PATH as these two are used, too. (diff) | |
download | core-cc5584b2bf8955b6e3a28f877369b3be266f0e88.tar.gz core-cc5584b2bf8955b6e3a28f877369b3be266f0e88.tar.xz core-cc5584b2bf8955b6e3a28f877369b3be266f0e88.zip |
* changed syntax of config-files to be shell-compatible
* all settings can now be overridden by environment variable, too
(very handy for SLX_CONFIG_PATH in order to tell the script
where to look for its config files).
* in verbose-level of 2 or higher we now log the config-file names as
they are read
* added auto-conversion from the shell-style naming used in the config
files to our own internal style.
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@404 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db')
-rw-r--r-- | config-db/OpenSLX/Basics.pm | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/config-db/OpenSLX/Basics.pm b/config-db/OpenSLX/Basics.pm index 9fecd10a..784e45dd 100644 --- a/config-db/OpenSLX/Basics.pm +++ b/config-db/OpenSLX/Basics.pm @@ -32,52 +32,56 @@ my $loadedTranslationModule; 'db-type' => 'CSV', 'locale' => $ENV{LANG}, # TODO: may need to be improved in order to be portable - 'config-path' => '/etc/opt/openslx', - 'openslx-basepath' => '/opt/openslx', - 'private-path' => '/var/opt/openslx', - 'public-path' => '/srv/openslx', - 'temp-basepath' => '/tmp', + 'base-path' => $ENV{SLX_BASE_PATH} || '/opt/openslx', + 'config-path' => $ENV{SLX_CONFIG_PATH} || '/etc/opt/openslx', + 'private-path' => $ENV{SLX_PRIVATE_PATH} || '/var/opt/openslx', + 'public-path' => $ENV{SLX_PUBLIC_PATH} || '/srv/openslx', + 'temp-path' => $ENV{SLX_TEMP_BASE_PATH} || '/tmp', ); +$openslxConfig{'bin-path'} = "$openslxConfig{'base-path'}/bin", $openslxConfig{'db-basepath'} = "$openslxConfig{'private-path'}/db", -$openslxConfig{'bin-path'} = "$openslxConfig{'openslx-basepath'}/bin", -$openslxConfig{'share-path'} = "$openslxConfig{'openslx-basepath'}/share", +$openslxConfig{'share-path'} = "$openslxConfig{'base-path'}/share", +$openslxConfig{'tftpboot-path'} = "$openslxConfig{'public-path'}/tftpboot", # specification of cmdline arguments that are shared by all openslx-scripts: +my %cmdlineConfig; my %openslxCmdlineArgs = ( - 'db-basepath=s' => \$openslxConfig{'db-basepath'}, - # basic path to openslx database, defaults to "$private-basepath/db" - 'db-datadir=s' => \$openslxConfig{'db-datadir'}, + '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-spec=s' => \$openslxConfig{'db-spec'}, + 'db-spec=s' => \$cmdlineConfig{'db-spec'}, # full specification of database, a special string defining the # precise database to connect to (the contents of this string # depend on db-type) - 'db-name=s' => \$openslxConfig{'db-name'}, + 'db-name=s' => \$cmdlineConfig{'db-name'}, # name of database, defaults to 'openslx' - 'db-type=s' => \$openslxConfig{'db-type'}, + 'db-type=s' => \$cmdlineConfig{'db-type'}, # type of database to connect to (CSV, SQLite, ...), defaults to 'CSV' - 'locale=s' => \$openslxConfig{'locale'}, + 'locale=s' => \$cmdlineConfig{'locale'}, # locale to use for translations - 'logfile=s' => \$openslxConfig{'locale'}, + 'logfile=s' => \$cmdlineConfig{'locale'}, # file to write logging output to, defaults to STDERR - 'bin-path=s' => \$openslxConfig{'bin-path'}, + 'bin-path=s' => \$cmdlineConfig{'bin-path'}, # path to binaries and scripts - 'config-path=s' => \$openslxConfig{'config-path'}, + 'config-path=s' => \$cmdlineConfig{'config-path'}, # path to configuration files - 'openslx-basepath=s' => \$openslxConfig{'openslx-basepath'}, + 'base-path=s' => \$cmdlineConfig{'base-path'}, # basic path to project files (binaries, functionality templates and # distro-specs) - 'private-path=s' => \$openslxConfig{'private-path'}, + 'private-path=s' => \$cmdlineConfig{'private-path'}, # path to private data (which is accessible for clients and # contains all data required for booting the clients) - 'public-path=s' => \$openslxConfig{'public-path'}, + 'public-path=s' => \$cmdlineConfig{'public-path'}, # path to public data (which contains database, vendorOSes # and all local extensions [system specific scripts]) - 'share-path=s' => \$openslxConfig{'share-path'}, + 'share-path=s' => \$cmdlineConfig{'share-path'}, # path to sharable data (functionality templates and distro-specs) - 'temp-basepath=s' => \$openslxConfig{'temp-basepath'}, + 'temp-basepath=s' => \$cmdlineConfig{'temp-basepath'}, # basic path to temporary data (used during demuxing) - 'verbose-level=i' => \$openslxConfig{'verbose-level'}, + 'tftpboot-path=s' => \$cmdlineConfig{'tftpboot-path'}, + # path to root of tftp-server, tftpable data will be stored there + 'verbose-level=i' => \$cmdlineConfig{'verbose-level'}, # level of logging verbosity (0-3) ); @@ -95,25 +99,49 @@ sub vlog # ------------------------------------------------------------------------------ sub openslxInit { + # evaluate cmdline arguments: + GetOptions(%openslxCmdlineArgs); + # try to read and evaluate config files: - foreach my $f ("$openslxConfig{'config-path'}/settings.default", - "$openslxConfig{'config-path'}/settings.local", + my $configPath = $cmdlineConfig{'config-path'} + || $openslxConfig{'config-path'}; + foreach my $f ("$configPath/settings.default", + "$configPath/settings.local", "$ENV{HOME}/.openslx/settings") { next unless open(CONFIG, "<$f"); + if ($cmdlineConfig{'verbose-level'} >= 2) { + vlog 0, "reading config-file $f..."; + } while(<CONFIG>) { chomp; s/#.*//; s/^\s+//; s/\s+$//; next unless length; - my ($key, $value) = split(/\s*=\s*/, $_, 2); + if (! /^(\w+)=(.*)$/) { + die _tr("config-file <%s> has incorrect syntax here:\n\t%s\n", + $f, $_); + } + my ($key, $value) = ($1, $2); + # N.B.: the config files are used by shell-scripts, too, so in + # order to comply with shell-style, the config files use shell + # syntax and an uppercase, underline-as-separator format. + # Internally, we use lowercase, minus-as-separator format, so we + # need to convert the environment variable names to our own + # internal style here (e.g. 'SLX_BASE_PATH' to 'base-path'): + $key =~ s[^SLX_][]; + $key =~ tr/[A-Z]_/[a-z]-/; $openslxConfig{$key} = $value; } close CONFIG; } - # push any cmdline argument directly into our config hash: - GetOptions(%openslxCmdlineArgs); + # push any cmdline argument into our config hash, possibly overriding any + # setting from the config files: + while(my ($key, $val) = each(%cmdlineConfig)) { + next unless defined $val; + $openslxConfig{$key} = $val; + } if (defined $openslxConfig{'logfile'} && open(LOG, ">>$openslxConfig{'logfile'}")) { |