summaryrefslogblamecommitdiffstats
path: root/installer/slxos-setup
blob: 39015cba013f46f8d140608ed34d183bda8fa97b (plain) (tree)
























                                                                              


                                         










                                                                               

                   







                              
                                     
                               









                                                                       



                                                    
                                                        


               





                                                                                          

                                                                                                                  


                     

                               
                                                                               















                                                                                                                 




                                                                                 

                                                      
                                           











                                                                                      


                                                           










                                                                               
                                            



                                                      
                                                               
                                                                     

                                           
          
                                                                  



                                                                      











                                      








                                                                       









                                                                          






                             
#! /usr/bin/perl
#
# slxos-setup -
#
# (c) 2006 - OpenSLX.com
#
# Oliver Tappe <ot@openslx.com>
#
use strict;

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 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;

if ($> != 0) {
	die _tr("Sorry, this script can only be executed by the superuser!\n");
}

my (
	$helpReq,
	$manReq,
	$listReq,
	$selection,
	$source,
	$verbose,
	$versionReq,
);

GetOptions(
	'help|?' => \$helpReq,
	'list' => \$listReq,
	'man' => \$manReq,
	'selection=s' => \$selection,
	'source=s' => \$source,
	'verbose' => \$verbose,
	'version' => \$versionReq,
) or pod2usage(2);
pod2usage(-msg => $abstract, -verbose => 0, -exitval => 1) if $helpReq;
pod2usage(-verbose => 2) if $manReq;
if ($versionReq) {
	system('slxversion');
	exit 1;
}

openslxInit();

if ($listReq) {
	print _tr("List of supported distros:\n\t");
	print join("\n\t", keys %supportedDistros)."\n";
	exit 1;
}

if (scalar(@ARGV) != 2) {
	print STDERR _tr("You need to specify exactly one action and one distro name!\n");
	pod2usage(2);
}
my $action = $ARGV[0];
my $distroName = $ARGV[1];
if ($action !~ m[^clone|import-into-db|install|update$]i) {
	print STDERR _tr("You need to specify exactly one action:\n\tinstall, update, clone or import-into-db\n");
	pod2usage(2);
}

if ($action =~ m[clone]i) {
	if (!length($source)) {
		die _tr("You need to specify a source you'd like to clone!\n");
	}
	if ($source !~ m[^.+::?.+$]) {
		die _tr("Unkown source format given, expected '<hostname>:<path>' or '<hostname>::<module>'!\n");
	}
	if (!defined $selection) {
		$selection = "cloned-from-$source";
		$selection =~ tr[:/][_];
			# mask : and /
		$selection =~ s[_+$][];
			# remove any trailing underscores, as they're ugly
	}
} else {
	$selection = 'default'		unless defined $selection;
}


# 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 ossetup-engine for given distro and start it:
my $engine = OpenSLX::OSSetup::Engine->new;
if ($action =~ m[import]i) {
	$engine->initialize($distroName, $selection, 0);
	if (!-e $engine->{'system-path'}) {
		die _tr("'%s' doesn't exist, giving up!\n", $engine->{'system-path'});
	}
	$engine->addInstalledVendorOSToConfigDB();
} elsif ($action =~ m[update]i) {
	$engine->initialize($distroName, $selection, 0);
	$engine->updateVendorOS();
} elsif ($action =~ m[install]i) {
	$engine->initialize($distroName, $selection, 1);
	$engine->installVendorOS();
} elsif ($action =~ m[clone]i) {
	$engine->initialize($distroName, $selection, 0, 1);
	$engine->cloneVendorOS($source);
}

__END__

=head1 NAME

slxos-setup - OpenSLX-script to install an operating system into a folder which
will be used as a stage1 system for OpenSLX.

=head1 SYNOPSIS

slxos-setup [options] <action> <distro-name>

  Options:
      --help                   brief help message
      --man                    show full documentation
      --selection=<string>     specific selection for vendor-OS
      --source=<string>        (rsync-)source to clone vendor-OS from
      --version                show version

  Actions:
      clone                    clones an existing system via rsync
      import-into-db           imports a vendor-OS into the openslx-db
      install                  installs a vendor-OS into a folder
      update                   updates an installed vendor-OS

=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<--selection=<string>>

Many distributions offer several different package selections for
installation. With this option you can specify which of these you
would like to use.

If you pass an unknown selection, you will see a list of the selections
that are available.

In clone-mode, the selection specifies the name by which the cloned system
will be known (exact name will be '<distro>-<selection>' instead of
'<distro>-cloned-from-<rsync-source>').

=item B<--source=<string>>

When cloning a vendor-OS, slxos-setup needs to know where to fetch
the existing OS-files from. You can specify the rsync-uri with this
option.

=item B<--version>

Prints the version and exits.

=back

=cut