From 821cfee47c89fa40aea5a8add1c33c438f9d07ed Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 14 Jun 2007 11:40:49 +0000 Subject: * moved slxsettings from 'config-db' to 'bin', as it has nothing to do with the db (anymore) git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1163 95ad53e4-c205-0410-b2fa-d234c58c8868 --- bin/slxsettings | 366 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100755 bin/slxsettings (limited to 'bin') diff --git a/bin/slxsettings b/bin/slxsettings new file mode 100755 index 00000000..b6fd6e1e --- /dev/null +++ b/bin/slxsettings @@ -0,0 +1,366 @@ +#! /usr/bin/perl +# ----------------------------------------------------------------------------- +# 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/ +# ----------------------------------------------------------------------------- +# slxsettings +# - OpenSLX-script to show & change local settings +# ----------------------------------------------------------------------------- +use strict; + +my $abstract = q[ +slxsettings + This script can be used to show or change the local settings for OpenSLX. + + Any cmdline-argument passed to this script will change the local OpenSLX + settings file (usually /etc/opt/openslx/settings). + + If you invoke the script without any arguments, it will print the current + settings and exit. + + Please use the --man option in order to read the full manual. +]; + +use Getopt::Long qw(:config pass_through); +use Pod::Usage; + +# add the lib-folder and the folder this script lives in to perl's search +# path for modules: +use FindBin; +use lib "$FindBin::RealBin/../lib"; +use lib "$FindBin::RealBin"; + # development path to config-db stuff + +use OpenSLX::Basics; +use OpenSLX::Utils; + +my ( + $quiet, + @reset, + $helpReq, + $manReq, + $versionReq, +); + +GetOptions( + 'quiet' => \$quiet, + # will avoid printing anything + 'reset=s' => \@reset, + # resets given option to its default + + 'help|?' => \$helpReq, + 'man' => \$manReq, + 'version' => \$versionReq, +); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +pod2usage(-verbose => 2) if $manReq; +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit() or pod2usage(2); + +my %givenSettings = %cmdlineConfig; + +# if there are still arguments in the cmdline left, it must be extended +# settings: +while (scalar @ARGV) { + my $extSetting = shift; + if ($extSetting !~ m[^([-\w]+)=(.+)$]) { + die _tr("extended setting '%s' has unknown format, expected '=!'", + $extSetting); + } + $givenSettings{$1} = $2; +} + +# fetch current content of local settings file... +my $settings = slurpFile("$openslxConfig{'config-path'}/settings"); + +my $changeCount; + +# ...set new values... +foreach my $key (keys %givenSettings) { + next if $key eq 'config-path'; + # config-path can't be changed, it is used to find settings + my $value = $givenSettings{$key}; + next if !defined $value; + vlog 0, _tr("setting %s to '%s'", $key, $value) unless $quiet; + my $externalKey = externalKeyFor($key); + if (!($settings =~ s[^\s*$externalKey=.*?$][$externalKey=$value]ms)) { + $settings .= "$externalKey=$value\n"; + } + $changeCount++; +} + +# reset specified keys to fall back to default: +foreach my $key (@reset) { + my $externalKey = externalKeyFor($key); + if ($settings =~ s[^\s*?$externalKey=.*?\n][]ms) { + vlog 0, _tr("removing option '%s' from local settings", $key) unless $quiet; + } else { + vlog 0, _tr("option '%s' didn't exist in local settings!", $key) unless $quiet; + } + $changeCount++; +} + +# ... and write local settings file if necessary +if ($changeCount) { + my $f = "$openslxConfig{'config-path'}/settings"; + open(SETTINGS, "> $f") + or die _tr("Unable to write local settings file '%s' (%s)", $f, $!); + print SETTINGS $settings; + close(SETTINGS); +} + +if (!$changeCount) { + my $text + = $changeCount ? "resulting base settings:" : "current base settings:"; + print "\n"._tr($text)."\n"; + my @baseSettings = grep { exists $cmdlineConfig{$_} } keys %openslxConfig; + foreach my $key (sort @baseSettings) { + print qq[\t--$key='$openslxConfig{$key}'\n]; + } + print "extended settings:\n"; + my @extSettings = grep { !exists $cmdlineConfig{$_} } keys %openslxConfig; + foreach my $key (sort @extSettings) { + print qq[\t$key='$openslxConfig{$key}'\n]; + } +} + +sub externalKeyFor +{ + my $key = shift; + + $key =~ tr[-][_]; + return "SLX_".uc($key); +} + + + +=head1 NAME + +slxsettings - OpenSLX-script to show & change local settings + +=head1 SYNOPSIS + +slxsettings [options] [action ...] + +=head3 Script Options + + --reset= resets the given option to its default + +=head3 OpenSLX Options + + --base-path= basic path to project files + --bin-path= path to binaries and scripts + --config-path= path to configuration files + --db-basepath= basic path to openslx database + --db-datadir= data folder created under db-basepath + --db-name= name of database + --db-spec= full DBI-specification of database + --db-type= type of database to connect to + --export-path= path to root of all exported filesystems + --locale= locale to use for translations + --logfile= file to write logging output to + --private-path= path to private data + --public-path= path to public (client-accesible) data + --share-path= path to sharable data + --temp-path= path to temporary data + --tftpboot-path= path to root of tftp-server + --verbose-level= level of logging verbosity (0-3) + +=head3 General Options + + --help brief help message + --man full documentation + --quiet do not print anything + --version show version + +=head3 Actions + +=over 8 + +=item B<< --= >> + +sets the specified openslx-option to the given value + +=item B<< = >> + +sets the specified extended setting to the given value + +=item B<< --reset= [--reset=...] >> + +removes the given setting from the local settings (resets it to its default +value) + +=back + +=head1 DESCRIPTION + +B can be used to show or change the local settings for OpenSLX. + +Any cmdline-argument passed to this script will change the local OpenSLX +settings file (usually /etc/opt/openslx/settings). + +If you invoke the script without any arguments, it will print the current +settings and exit. + +=head1 OPTIONS + +=head3 OpenSLX Options + +=over 8 + +=item B<< --base-path= >> + +Sets basic path to project files. + +Default is $SLX_BASE_PATH (usually F). + +=item B<< --bin-path= >> + +Sets path to binaries and scripts. + +Default is $SLX_BASE_PATH/bin (usually F). + +=item B<< --config-path= >> + +Sets path to configuration files. + +Default is $SLX_CONFIG_PATH (usually F). + +=item B<< --db-basepath= >> + +Sets basic path to openslx database. + +Default is $SLX_DB_PATH (usually F). + +=item B<< --db-datadir= >> + +Sets data folder created under db-basepath. + +Default is $SLX_DB_DATADIR (usually empty as it depends on db-type +whether or not such a directory is required at all). + +=item B<< --db-name= >> + +Gives the name of the database to connect to. + +Default is $SLX_DB_NAME (usually C). + +=item B<< --db-spec= >> + +Gives the full DBI-specification of database to connect to. Content depends +on the db-type. + +Default is $SLX_DB_SPEC (usually empty as it will be built automatically). + +=item B<< --db-type= >> + +Sets the type of database to connect to (CSV, SQLite, mysql, ...). + +Default $SLX_DB_TYPE (usually C). + +=item B<< --export-path= >> + +Sets path to root of all exported filesystems. For each type of export (NFS, +NBD, ...) a separate folder will be created in here. + +Default is $SLX_EXPORT_PATH (usually F. + +=item B<< --locale= >> + +Sets the locale to use for translations. + +Defaults to the system's standard locale. + +=item B<< --logfile= >> + +Specifies a file where logging output will be written to. + +Default is to log to STDERR. + +=item B<< --private-path= >> + +Sets path to private data, where the config-db, vendor_oses and configurational +extensions will be stored. + +Default is $SLX_PRIVATE_PATH (usually F. + +=item B<< --public-path= >> + +Sets path to public (client-accesible) data. + +Default is $SLX_PUBLIC_PATH (usually F. + +=item B<< --share-path= >> + +Sets path to sharable data, where distro-specs and functionality templates +will be stored. + +Default is $SLX_SHARE_PATH (usually F. + +=item B<< --stage1-path= >> + +Sets path to stage1 systems, where distributor-systems will be installed. + +Default is $SLX_STAGE1_PATH (usually F. + +=item B<< --temp-path= >> + +Sets path to temporary data. + +Default is $SLX_TEMP_PATH (usually F. + +=item B<< --tftpboot-path= >> + +Sets path to root of tftp-server from which clients will access their files. + +Default is $SLX_TFTPBOOT_PATH (usually F. + +=item B<< --verbose-level= >> + +Sets the level of logging verbosity (0-3). +Prints additional output for debugging. N is a number between 0 and 3. Level +1 provides more information than the default, while 2 provides traces. With +level 3 you get extreme debug output, e.g. database commands are printed. + +Default is $SLX_VERBOSE_LEVEL (usually 0, no logging). + +=back + +=head3 General Options + +=over 8 + +=item B< --help> + +Prints a brief help message and exits. + +=item B< --man> + +Prints the manual page and exits. + +=item B< --quiet> + +Runs the script without printing anything. + +=item B< --version> + +Prints the version and exits. + +=back + +=head1 SEE ALSO + +slxos-setup, slxos-export, slxconfig, slxconfig-demuxer + +=cut \ No newline at end of file -- cgit v1.2.3-55-g7522