#! /usr/bin/perl
# -----------------------------------------------------------------------------
# Copyright (c) 2006..2009 - 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-setup
This script installs an operating system into a folder that can be used as
a stage1 system for OpenSLX.
];
use Encode;
use Getopt::Long qw(:config pass_through);
use Pod::Usage;
# 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 OpenSLX::Basics;
use OpenSLX::OSSetup::Engine;
use OpenSLX::Utils;
my %option;
GetOptions(
'help|?' => \$option{helpReq},
'man' => \$option{manReq},
'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_ALL} = 'POSIX';
pod2usage(-verbose => 2)
}
if ($option{versionReq}) {
system('slxversion');
exit 1;
}
if ($> != 0) {
die _tr("Sorry, this script can only be executed by the superuser!\n");
}
openslxInit();
my $action = shift @ARGV || '';
# create ossetup-engine for given distro and start it:
my $engine = OpenSLX::OSSetup::Engine->new;
if ($action =~ m[^import]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to give the name of the vendor-os you'd like to import!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'import');
if (!-e $engine->{'vendor-os-path'}) {
die _tr("'%s' doesn't exist, giving up!\n", $engine->{'vendor-os-path'});
}
$engine->addInstalledVendorOSToConfigDB();
createConfigFolderForDefaultVendorOS();
createConfigFolderForVendorOS($vendorOSName);
} elsif ($action =~ m[^update]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to give the name of the vendor-os you'd like to update!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'update');
$engine->updateVendorOS();
} elsif ($action =~ m[^shell]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to give the name of the vendor-os you'd like to start of shell for!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'shell');
$engine->startChrootedShellForVendorOS();
} elsif ($action =~ m[^install]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to give the name of the vendor-os you'd like to install!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'install');
$engine->installVendorOS();
} elsif ($action =~ m[^clone]i) {
my $source = shift @ARGV;
my $vendorOSName = shift @ARGV;
if (!defined $source || !defined $vendorOSName) {
print STDERR _tr("You need to specify exactly one source and one vendor-OS-name!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'clone');
$engine->cloneVendorOS($source);
} elsif ($action =~ m[^remove]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to specify exactly one vendor-OS-name!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'remove');
$engine->removeVendorOS();
} elsif ($action =~ m[^list-se]i) {
my $vendorOSName = shift @ARGV;
if (!defined $vendorOSName) {
print STDERR _tr("You need to specify exactly one vendor-OS-name!\n");
pod2usage(2);
}
# 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, $!);
$engine->initialize($vendorOSName, 'install');
print _tr("List of supported selections for '%s':\n", $vendorOSName);
print join('', map { "\t$_\n" }
sort keys %{$engine->{'distro-info'}->{selection}});
} elsif ($action =~ m[^list-su]i) {
print _tr("List of supported distros:\n");
print join('', map {
"\t$_"
.(' 'x(20-length($_)))
."\t($supportedDistros{$_})\n"
}
sort keys %supportedDistros);
} elsif ($action =~ m[^list-in]i) {
print _tr("List of installed vendor-OSes:\n");
print join(
'',
map {
my $vendorOS = decode('utf8', $_);
$vendorOS =~ s[^.+/][];
"\t$vendorOS\n";
}
grep { -d $_ }
sort glob("$openslxConfig{'private-path'}/stage1/*")
);
} else {
vlog(0, _tr(unshiftHereDoc(<<' END-OF-HERE'), $0));
You need to specify exactly one action:
clone
import-into-db
install
list-installed
list-selections
list-supported
remove
shell
update
Try '%s --help' for more info.
END-OF-HERE
}
=head1 NAME
slxos-setup - OpenSLX-script to install a vendor-OS.
=head1 SYNOPSIS
slxos-setup [options] <action> <action-params> ...
=head3 Options
--help brief help message
--log-level=<int> level of logging verbosity (0-3)
--man show full documentation
--version show version
=head3 Actions
=over 8
=item B<< clone <rsync-source-uri> <vendor-os-name> >>
clones an existing operating system via rsync
=item B<< import-into-db <vendor-os-name> >>
imports a vendor-OS into the openslx-db
=item B<< install <vendor-os-name> >>
installs a vendor-OS into a folder
=item B<< list-installed >>
show installed vendor-OSes
=item B<< list-selections <vendor-os-name> >>
show available selections for given vendor-OS
=item B<< list-supported >>
show supported distros
=item B<< remove <vendor-os-name> >>
removes an installed vendor-OS
=item B<< shell <vendor-os-name> >>
starts a chrooted shell for an installed vendor-OS
=item B<< update <vendor-os-name> >>
updates an installed vendor-OS
=back
=head1 DESCRIPTION
B<slxos-setup> installs an operating system into a folder which
will be used as a OpenSLX-stage1-system (a.k.a. a I<vendor-OS>).
You can either install a vendor-OS from scratch (causing the required
packages to be downloaded or copied from a local source). Installing
is supported for several different LINUX distributions, but not for all
of them.
Alternatively, a locally installed operating system can be cloned
into a vendor-OS.
When invoking slxos-setup, you have to pass it the name of the vendor-OS
you wish to create.
=head1 OPTIONS
=over 8
=item B<--help>
Prints a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=item B<--version>
Prints the version and exits.
=item B<vendor-os-name>
The vendor-os-name is the name of the vendor-OS that shall be installed,
cloned, imported or updated. It corresponds to a folder in the OpenSLX-
stage1-path (usually /var/opt/openslx/stage1).
The general format of a vendor-os-name is:
<distro-name>-<release-version>
or
<distro-name>-<release-version>-<selection>
The distro-name is something like 'suse' or 'fedora', and the release-version
is a numerical version, e.g. '10.1' or '6'.
If you specify a selection, too, you state that you want all the packages
that are provided by the specific selection (many distributions offer several
different package selections for installation, like 'kde' or 'gnome').
If you do not specify any selection, you will get the default selection of
that distribution.
If you pass an unknown selection, you will see a list of the selections
that are available. The available selections for any vendor-OS can be requested
via the 'list-selections' action.
In clone-mode, it is a good idea to specify some unique string as the selection
part of the vendor-os-name, such that you will easily recognize the vendor-OS
at a later stage. We recommend something like '-cloned-from-<name-of-rsync-source>'.
=item B<rsync-source-uri>
When cloning a vendor-OS, slxos-setup needs to know where to fetch
the existing OS-files from. Please check the 'rsync' docs for what
format an rsync-uri has.
=back
=head1 EXAMPLES
=head3 Installing a Vendor-OS
=over 8
=item B<< slxos-setup install suse-11.1 >>
Installs the distro suse-11.1 as a new vendor-OS.
=item B<< slxos-setup install suse-11.1-gnome >>
Installs the 'gnome'-selection of distro suse-11.1 as a new
vendor-OS.
=back
=head3 Cloning an Operating System to Make a New Vendor-OS
=over 8
=item B<< slxos-setup clone my_server:/ suse-11.1-clone-my_server >>
Clones the suse-11.1 system from server 'my_server' as a new
vendor-OS, which will be named 'suse-11.1-clone-my_server'.
=back
=head3 Updating a Vendor-OS
=over 8
=item B<< slxos-setup update suse-11.1 >>
Updates the (existing) vendor-OS 'suse-11.1'.
=back
=head3 Importing an Existing Vendor-OS into the Config-DB
=over 8
=item B<< slxos-setup import-into-db suse-11.1 >>
Imports the (existing) vendor-OS 'suse-11.1' into the config-DB.
=back
=head3 Removing a Vendor-OS
=over 8
=item B<< slxos-setup remove suse-11.1 >>
Wipes the (existing) vendor-OS 'suse-11.1' from disk and removes it
from the config-DB, too.
=back
=head1 SEE ALSO
slxsettings, slxos-export, 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
--log-level=<int> level of logging verbosity (0-3)
--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
Please refer to the C<slxsettings>-manpage for a more detailed description
of these options.
=cut