summaryrefslogtreecommitdiffstats
path: root/os-plugins/slxos-plugin
blob: 6797b25ee0c51ef1a6286fff5727c637039a73c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#! /usr/bin/perl -CLADS
# -----------------------------------------------------------------------------
# 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;
use OpenSLX::Utils;

my %option;

GetOptions(
	'help|?'  => \$option{helpReq},
	'man'     => \$option{manReq},
	'verbose' => \$option{verbose},
	'version' => \$option{versionReq},
  )
  or pod2usage(2);
pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $option{helpReq};
if ($option{manReq}) {
	# avoid dubious problem with perldoc in combination with UTF-8 that
	# leads to strange dashes and single-quotes being used
	$ENV{LC_MESSAGES} = 'POSIX';
	pod2usage(-verbose => 2);
}
if ($option{versionReq}) {
	system('slxversion');
	exit 1;
}

openslxInit();

my $action = shift @ARGV || '';

if ($action =~ m[^list]i) {
	my @pluginFolders = glob("$openslxConfig{'base-path'}/lib/plugins/*");
	print _tr("List of available plugins:\n");
	require OpenSLX::OSPlugin::Roster;
	my $pluginInfo = OpenSLX::OSPlugin::Roster->getAvailablePlugins();
	print join(
		'', 
		map {
			if ($option{verbose}) {
				my $description = $pluginInfo->{$_}->{description};
				$description 
					.= "\t    " 
						. _tr("The following attributes are suppported:")
						. "\n\t        ";
				my $pluginAttrs 
					= OpenSLX::OSPlugin::Roster->getPluginAttrInfo($_);
				$description .= join("\n\t        ", sort keys %$pluginAttrs);
				"\n\t$_\n\t    $description\n";
			}
			else {
				"\t$_\n";
			}
		} 
		sort keys %$pluginInfo
	);
} 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 {
	vlog(0, _tr(unshiftHereDoc(<<'	END-OF-HERE'), $0));
		You need to specify exactly one action:
			list-available
			install <plugin-name> <vendor-OS-name>
			remove <plugin-name> <vendor-OS-name>
		Try '%s --help' for more info.
	END-OF-HERE
}

=head1 NAME

slxos-plugin - OpenSLX-script to install/remove an OS-plugin into/from an 
installed vendor-OS.

=head1 SYNOPSIS

slxos-plugin [options] <action>

=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 <plugin-name> <vendor-OS-name> >>

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 <plugin-name> <vendor-OS-name> >>

removes the OS-plugin with the given name from the specified vendor-OS

=back

=head1 DESCRIPTION

B<slxos-plugin> 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/<plugin-name>/). 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=<string>         name of database
    --db-spec=<string>         full DBI-specification of database
    --db-type=<string>         type of database to connect to
    --locale=<string>          locale to use for translations
    --logfile=<string>         file to write logging output to
    --private-path=<string>    path to private data
    --public-path=<string>     path to public (client-accesible) data
    --temp-path=<string>       path to temporary data
    --verbose-level=<int>      level of logging verbosity (0-3)

Please refer to the C<slxsettings>-manpage for a more detailed description
of these options.

=cut