From 041f05422528bad639db5c2668bf3313643be244 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 2 Jul 2007 23:48:23 +0000 Subject: * added the 'os-plugins'-folder I missed with last commit git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1221 95ad53e4-c205-0410-b2fa-d234c58c8868 --- os-plugins/OpenSLX/OSPlugin/Engine.pm | 124 +++++++++++ .../plugins/Example/OpenSLX/OSPlugin/Example.pm | 122 ++++++++++ os-plugins/plugins/Example/XX_Example.sh | 38 ++++ os-plugins/slxos-plugin | 246 +++++++++++++++++++++ 4 files changed, 530 insertions(+) create mode 100644 os-plugins/OpenSLX/OSPlugin/Engine.pm create mode 100644 os-plugins/plugins/Example/OpenSLX/OSPlugin/Example.pm create mode 100644 os-plugins/plugins/Example/XX_Example.sh create mode 100644 os-plugins/slxos-plugin (limited to 'os-plugins') diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm new file mode 100644 index 00000000..57850229 --- /dev/null +++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm @@ -0,0 +1,124 @@ +# Copyright (c) 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/ +# ----------------------------------------------------------------------------- +# Engine.pm +# - provides driver engine for the OSPlugin API. +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::Engine; + +use strict; +use warnings; + +our $VERSION = 1.01; # API-version . implementation-version + +use File::Basename; + +use OpenSLX::Basics; +use OpenSLX::OSSetup::Engine; +use OpenSLX::Utils; + +################################################################################ +### interface methods +################################################################################ +sub new +{ + my $class = shift; + + my $self = {}; + + return bless $self, $class; +} + +sub getAvailablePlugins +{ # Class-method! + my $class = shift; + + return + map { basename($_); } + sort + glob("$openslxConfig{'base-path'}/lib/plugins/*"); +} + +sub initialize +{ + my $self = shift; + my $pluginName = shift; + my $vendorOSName = shift; + + $self->{'plugin-name'} = $pluginName; + $self->{'vendor-os-name'} = $vendorOSName; + + $self->{'vendor-os-path'} + = "$openslxConfig{'private-path'}/stage1/$vendorOSName"; + vlog(1, "vendor-OS path is '$self->{'vendor-os-path'}'"); + + $self->{'plugin-path'} + = "$openslxConfig{'base-path'}/lib/plugins/$pluginName"; + vlog(1, "plugin path is '$self->{'plugin-path'}'"); + + $self->{'plugin'} = $self->_loadPlugin(); +} + +sub installPlugin +{ + my $self = shift; + + # create ossetup-engine for given vendor-OS: + my $osSetupEngine = OpenSLX::OSSetup::Engine->new; + $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); + $self->{'os-setup-engine'} = $osSetupEngine; + $self->{'distro-name'} = $osSetupEngine->{'distro-name'}; + + my $chrootedPluginRepoPath + = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; + my $pluginRepoPath = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; + my $chrootedPluginTempPath = "/tmp/slx-plugin/$self->{'plugin-name'}"; + my $pluginTempPath = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; + foreach my $path ($pluginRepoPath, $pluginTempPath) { + if (slxsystem("mkdir -p $path")) { + croak(_tr("unable to create path '%s'! (%s)", $path, $!)); + } + } + + $self->{plugin}->preInstallationPhase($pluginRepoPath, $pluginTempPath); + + $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( + sub { + $self->{plugin}->installationPhase( + $chrootedPluginRepoPath, $chrootedPluginTempPath + ); + } + ); + + $self->{plugin}->postInstallationPhase($pluginRepoPath, $pluginTempPath); +} + +sub getPlugin +{ + my $self = shift; + + return $self->{plugin}; +} + +sub removePlugin +{ +} + +sub _loadPlugin +{ + my $self = shift; + + my $pluginModule = "OpenSLX::OSPlugin::$self->{'plugin-name'}"; + my $plugin = instantiateClass( + $pluginModule, { pathToClass => $self->{'plugin-path'} } + ); + $plugin->initialize($self); + return $plugin; +} diff --git a/os-plugins/plugins/Example/OpenSLX/OSPlugin/Example.pm b/os-plugins/plugins/Example/OpenSLX/OSPlugin/Example.pm new file mode 100644 index 00000000..bd90d306 --- /dev/null +++ b/os-plugins/plugins/Example/OpenSLX/OSPlugin/Example.pm @@ -0,0 +1,122 @@ +# Copyright (c) 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/ +# ----------------------------------------------------------------------------- +# Example.pm +# - an example implementation of the OSPlugin API (i.e. an os-plugin) +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::Example; + +use strict; +use warnings; + +our $VERSION = 1.01; # API-version . implementation-version + +use OpenSLX::Basics; +use OpenSLX::Utils; + +################################################################################ +# if you have any questions regarding the concept of OS-plugins and their +# implementation, please drop a mail to: ot@openslx.com, or join the IRC-channel +# '#openslx' (on freenode). +################################################################################ +### interface methods +################################################################################ +sub new +{ + my $class = shift; + + my $self = {}; + + return bless $self, $class; +} + +sub initialize +{ + my $self = shift; + + # The os-plugin-engine drives us, it provides some useful services relevant + # to installing stuff into the vendor-OS, like downloading functionality, + # access to meta-packager, ... + $self->{'os-plugin-engine'} = shift; + + # Any other static initialization necessary for a plugin should be done + # here, more often than not, this will involve a configurational hash + # representing the default settings for this plugin. + # At a later stage, the user will be able to change plugin-specific settings + # (on a per-system/client basis) via slxconfig, such that the actual + # configuration will be stored in the DB. + # Currently, though, you have to change the settings here: + $self->{config} = { + 'active' => 1, # set to 0 in order to deactivate + 'precedence' => 10, # runlevel precedence + 'preferred_side' => 'left', # just a silly example + } +} + +sub preInstallationPhase +{ # called before chrooting into vendor-OS root, should be used if any files + # have to be downloaded outside of the chroot (which might be necessary + # if the required files can't be installed via the meta-packager) + my $self = shift; + my $pluginRepositoryPath = shift; + # the folder where the stage1-plugin should store all files + # required by the corresponding stage3 runlevel script + my $pluginTempPath = shift; + # a temporary playground that will be cleaned up automatically + + # in this example plugin, there's no need to do anything here ... +} + +sub installationPhase +{ # called while chrooted to the vendor-OS root, most plugins will do all + # their installation work here + my $self = shift; + my $pluginRepositoryPath = shift; + # the repository folder, this time from inside the chroot + my $pluginTempPath = shift; + # the temporary folder, this time from inside the chroot + + # for this example plugin, we simply create two files: + spitFile("$pluginRepositoryPath/left", "(-;\n"); + spitFile("$pluginRepositoryPath/right", ";-)\n"); +} + +sub postInstallationPhase +{ # called after having returned from chrooted environment, should be used + # to cleanup any leftovers, if any such thing is necessary + my $self = shift; + my $pluginRepositoryPath = shift; + my $pluginTempPath = shift; + + # in this example plugin, there's no need to do anything here ... +} + +sub getConfig +{ # called from the config-demuxer in order ot access the configurational + # hash, which will then be written to a file (in this case: + # /opt/openslx/plugin-conf/Example.conf), that will be transported to each + # client as part of the conf-TGZ. + my $self = shift; + + return $self->{config}; +} + +sub preRemovalPhase +{ +} + +sub removalPhase +{ +} + +sub postRemovalPhase +{ +} + diff --git a/os-plugins/plugins/Example/XX_Example.sh b/os-plugins/plugins/Example/XX_Example.sh new file mode 100644 index 00000000..88c991e8 --- /dev/null +++ b/os-plugins/plugins/Example/XX_Example.sh @@ -0,0 +1,38 @@ +#! /bin/sh +# +# stage3 part of 'Example' plugin - the runlevel script +# +# This basically is a runlevel script (just like you know them from 'init'), +# whose purpose is to activate the plugin in stage3. The 'XX' at the beginning +# of the filename will be replaced with a runlevel precedence number taken +# from the configuration of the respective plugin. All plugin runlevel scripts +# will be executed in the order of those precedence numbers. +# +# In order to activate the corresponding plugin, each runlevel script should: +# +# a) read the corresponding configuration file (in this case: +# /initramfs/plugin-conf/Example.conf) +# +# b) analyse the client (look at the available hardware) and decide what +# needs to be done, taking into account the settings given in the config +# file +# +# c) activate the plugin by copying/linking appropriate plugin-specific files +# (in this case: from /mnt/opt/openslx/plugins/Example/), load required kernel +# modules and whatever else might be necessary. +# +# if you have any questions regarding the use of this file, please drop a mail +# to: ot@openslx.com, or join the IRC-channel '#openslx' (on freenode). + +if ! [ -e /initramfs/plugin-conf/Example.conf ]; then + exit 1 +fi + +echo "executing the 'Example' os-plugin ..."; +# for this example plugin, we simply take a filename from the configuration ... +. /initramfs/plugin-conf/Example.conf + +# ... and cat that file: +cat /mnt/opt/openslx/plugin-repo/Example/$preferred_side + +echo "done with 'Example' os-plugin ..."; diff --git a/os-plugins/slxos-plugin b/os-plugins/slxos-plugin new file mode 100644 index 00000000..e72b9b72 --- /dev/null +++ b/os-plugins/slxos-plugin @@ -0,0 +1,246 @@ +#! /usr/bin/perl +# ----------------------------------------------------------------------------- +# Copyright (c) 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/ +# ----------------------------------------------------------------------------- +use strict; +use warnings; + +my $abstract = q[ +slxos-plugin + OpenSLX-script to install/remove plugin modules into/from a vendor-OS. +]; + +# add the folder this script lives in and the lib-folder to perl's +# search path for modules: +use FindBin; +use lib "$FindBin::RealBin"; +use lib "$FindBin::RealBin/../lib"; + +use lib "$FindBin::RealBin/../config-db"; +# development path to config-db + +use Getopt::Long qw(:config pass_through); +use Pod::Usage; + +use OpenSLX::Basics; +use OpenSLX::OSPlugin::Engine; + +my ($helpReq, $manReq, $verbose, $versionReq,); + +GetOptions( + 'help|?' => \$helpReq, + 'man' => \$manReq, + 'verbose' => \$verbose, + 'version' => \$versionReq, + ) + or pod2usage(2); +pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq; +if ($manReq) { + $ENV{LANG} = 'en_EN'; + # avoid dubious problem with perldoc in combination with UTF-8 that + # leads to strange dashes and single-quotes being used + pod2usage(-verbose => 2); +} +if ($versionReq) { + system('slxversion'); + exit 1; +} + +openslxInit(); + +my $action = shift @ARGV; + +if ($action =~ m[^list-av]i) { + my @pluginFolders = glob("$openslxConfig{'base-path'}/lib/plugins/*"); + print _tr("List of available plugins:\n"); + print join( + '', + map { "\t$_\n" } OpenSLX::OSPlugin::Engine->getAvailablePlugins() + ); +} elsif ($action =~ m[^install]i) { + if (scalar(@ARGV) != 2) { + print STDERR _tr( + "You need to specify exactly one plugin-name and one vendor-os!\n" + ); + pod2usage(2); + } + my $pluginName = shift @ARGV; + my $vendorOSName = shift @ARGV; + + # we chdir into the script's folder such that all relative paths have + # a known starting point: + chdir($FindBin::RealBin) + or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); + + # create OSPlugin-engine for given plugin and vendor-OS and start it: + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize($pluginName, $vendorOSName); + if (!-e $engine->{'plugin-path'}) { + die _tr("plugin '%s' doesn't exist, giving up!\n", + $engine->{'plugin-path'}); + } + if (!-e $engine->{'vendor-os-path'}) { + die _tr("vendor-OS '%s' doesn't exist, giving up!\n", + $engine->{'vendor-os-path'}); + } + $engine->installPlugin(); +} elsif ($action =~ m[^remove]i) { + if (scalar(@ARGV) != 2) { + print STDERR _tr( + "You need to specify exactly one plugin-name and one vendor-os!\n" + ); + pod2usage(2); + } + my $pluginName = shift @ARGV; + my $vendorOSName = shift @ARGV; + + # we chdir into the script's folder such that all relative paths have + # a known starting point: + chdir($FindBin::RealBin) + or die _tr("can't chdir to script-path <%> (%s)", $FindBin::RealBin, $!); + + # create OSPlugin-engine for given plugin and vendor-OS and start it: + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize($pluginName, $vendorOSName); + if (!-e $engine->{'plugin-path'}) { + die _tr("plugin '%s' doesn't exist, giving up!\n", + $engine->{'plugin-path'}); + } + if (!-e $engine->{'vendor-os-path'}) { + die _tr("vendor-OS '%s' doesn't exist, giving up!\n", + $engine->{'vendor-os-path'}); + } + $engine->removePlugin(); +} else { + print STDERR _tr( + "You need to specify exactly one action: + install + list-available + remove +Try '%s --help' for more info.\n", $0 + ); +} + +=head1 NAME + +slxos-plugin - OpenSLX-script to install/remove an OS-plugin into/from an +installed vendor-OS. + +=head1 SYNOPSIS + +slxos-plugin [options] + +=head3 Options + + --help brief help message + --man show full documentation + --verbose show more information during execution + --version show version + +=head3 Actions + +=over 8 + +=item B<< install >> + +installs the OS-plugin with the given name into the specified vendor-OS + +=item B<< list-available >> + +list all available OS-plugins + +=item B<< remove >> + +removes the OS-plugin with the given name from the specified vendor-OS + +=back + +=head1 DESCRIPTION + +B installs or removes specific functionality extensions into/from +an installed vendor-OS. That extension can be something rather simple (like +a boot-splash) or something rather complicated (e.g. the automatic detection, +installation and activation of the graphics driver most appropriate for the +booting client). + +Installation of any plugin will result in some files being added to the +vendor-OS (they will live in /opt/openslx/plugins//). These files +can be accessed by the booting client.in order to integrate the required +functionality into the system. + +=head1 OPTIONS + +=over 4 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=item B<--verbose> + +Prints more information during execution of any action. + +=item B<--version> + +Prints the version and exits. + +=back + +=head1 EXAMPLES + +=over 8 + +=head3 Installing a Plugin + +=item B<< slxos-plugin install Example suse-10.2 >> + +installs the plugin named 'Example' into the installed vendor-OS 'suse-10.2'. + +=back + +=head3 Removing a Plugin + +=over 8 + +=item B<< slxos-plugin remove Example suse-10.2 >> + +removes the plugin named 'Example' from the installed vendor-OS 'suse-10.2'. + +=back + +=head1 SEE ALSO + +slxsettings, slxos-setup, slxconfig, slxconfig-demuxer + +=head1 GENERAL OPENSLX OPTIONS + +Being a part of OpenSLX, this script supports several other options +which can be used to overrule the OpenSLX settings: + + --db-name= name of database + --db-spec= full DBI-specification of database + --db-type= type of database to connect to + --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 + --temp-path= path to temporary data + --verbose-level= level of logging verbosity (0-3) + +Please refer to the C-manpage for a more detailed description +of these options. + +=cut + -- cgit v1.2.3-55-g7522