summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--installer/OpenSLX/OSSetup/Engine.pm80
-rwxr-xr-xinstaller/slxos-setup43
2 files changed, 105 insertions, 18 deletions
diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm
index abab54c7..0f421e72 100644
--- a/installer/OpenSLX/OSSetup/Engine.pm
+++ b/installer/OpenSLX/OSSetup/Engine.pm
@@ -58,6 +58,7 @@ sub initialize
my $distroName = shift;
my $selectionName = shift;
my $protectSystemPath = shift;
+ my $cloneMode = shift;
if (!exists $supportedDistros{lc($distroName)}) {
print _tr("Sorry, distro '%s' is unsupported.\n", $distroName);
@@ -92,6 +93,7 @@ sub initialize
$vendorOSName .= "-$selectionName";
}
$self->{'vendor-os-name'} = $vendorOSName;
+ $self->{'clone-mode'} = $cloneMode;
# setup path to distribution-specific info:
my $distroInfoDir = "../lib/distro-info/$distro->{'base-name'}";
@@ -101,7 +103,8 @@ sub initialize
$self->{'distro-info-dir'} = $distroInfoDir;
$self->readDistroInfo();
- if (!exists $self->{'distro-info'}->{'selection'}->{$selectionName}) {
+ if (!$self->{'clone-mode'}
+ && !exists $self->{'distro-info'}->{'selection'}->{$selectionName}) {
die _tr("selection '%s' is unknown to system '%s'\n",
$selectionName, $distro->{'base-name'})
."These selections are available:\n\t"
@@ -125,7 +128,7 @@ sub installVendorOS
{
my $self = shift;
- $self->createSystemPaths();
+ $self->createSystemPath();
$self->setupStage1A();
my $pid = fork();
@@ -149,6 +152,20 @@ sub installVendorOS
$self->addInstalledVendorOSToConfigDB();
}
+sub cloneVendorOS
+{
+ my $self = shift;
+ my $source = shift;
+
+ $self->createSystemPath();
+
+ $self->clone_fetchSource($source);
+ vlog 0, _tr("Vendor-OS <%s> cloned succesfully.\n",
+ $self->{'vendor-os-name'});
+
+ $self->addInstalledVendorOSToConfigDB();
+}
+
sub updateVendorOS
{
my $self = shift;
@@ -184,7 +201,7 @@ sub addInstalledVendorOSToConfigDB
{ 'name' => $vendorOSName },
'id');
if (defined $vendorOS) {
- vlog 0, _tr("Vendor-OS <%s> already exists in OpenSLX-database!\n",
+ vlog 0, _tr("Vendor-OS <%s> already exists in OpenSLX-database.\n",
$vendorOSName);
} else {
my $id = addVendorOS($openslxDB, {
@@ -252,21 +269,13 @@ sub readDistroInfo
}
}
-sub createSystemPaths
+sub createSystemPath
{
my $self = shift;
- # specify individual paths for the respective substages:
- $self->{stage1aDir} = "$self->{'system-path'}/stage1a";
- $self->{stage1bSubdir} = 'slxbootstrap';
- $self->{stage1cSubdir} = 'slxfinal';
-
- # we create *all* of the above folders by creating stage1cDir:
- my $stage1cDir
- = "$self->{'stage1aDir'}/$self->{'stage1bSubdir'}/$self->{'stage1cSubdir'}";
- if (system("mkdir -p $stage1cDir")) {
+ if (system("mkdir -p $self->{'system-path'}")) {
die _tr("unable to create directory '%s', giving up! (%s)",
- $stage1cDir, $!);
+ $self->{'system-path'}, $!);
}
}
@@ -337,6 +346,20 @@ sub setupStage1A
my $self = shift;
vlog 1, "setting up stage1a for $self->{'vendor-os-name'}...";
+
+ # specify individual paths for the respective substages:
+ $self->{stage1aDir} = "$self->{'system-path'}/stage1a";
+ $self->{stage1bSubdir} = 'slxbootstrap';
+ $self->{stage1cSubdir} = 'slxfinal';
+
+ # we create *all* of the above folders by creating stage1cDir:
+ my $stage1cDir
+ = "$self->{'stage1aDir'}/$self->{'stage1bSubdir'}/$self->{'stage1cSubdir'}";
+ if (system("mkdir -p $stage1cDir")) {
+ die _tr("unable to create directory '%s', giving up! (%s)",
+ $stage1cDir, $!);
+ }
+
$self->stage1A_createBusyboxEnvironment();
$self->stage1A_setupResolver();
$self->stage1A_copyPrerequiredFiles();
@@ -634,6 +657,35 @@ sub stage1D_installPackageSelection
}
}
+sub clone_fetchSource
+{
+ my $self = shift;
+ my $source = shift;
+
+ vlog 0, _tr("Cloning vendor-OS from <%s>...\n", $source);
+ my (@includeList, @excludeList);
+ foreach my $filterFile ("../lib/distro-info/clone-filter-common",
+ "$self->{'distro-info-dir'}/clone-filter") {
+ if (open(FILTER, "< $filterFile")) {
+ while(<FILTER>) {
+ push @includeList, $_ if /^\+\s+/;
+ push @excludeList, $_ if /^\-\s+/;
+ }
+ close(FILTER);
+ }
+ }
+ my $excludeIncludeList = join("", @includeList, @excludeList);
+ vlog 1, "using exclude-include-filter:\n$excludeIncludeList\n";
+ open(RSYNC, "| rsync -av --delete --exclude-from=- $source $self->{'system-path'}")
+ or die _tr("unable to start rsync for source '%s', giving up! (%s)",
+ $source, $!);
+ print RSYNC $excludeIncludeList;
+ if (!close(RSYNC)) {
+ die _tr("unable to clone from source '%s', giving up! (%s)",
+ $source, $!);
+ }
+}
+
################################################################################
### utility functions
################################################################################
diff --git a/installer/slxos-setup b/installer/slxos-setup
index 6e829894..1d67d5ae 100755
--- a/installer/slxos-setup
+++ b/installer/slxos-setup
@@ -37,17 +37,18 @@ my (
$helpReq,
$manReq,
$listReq,
+ $selection,
+ $source,
$verbose,
$versionReq,
);
-my $selection = 'default';
-
GetOptions(
'help|?' => \$helpReq,
'list' => \$listReq,
'man' => \$manReq,
'selection=s' => \$selection,
+ 'source=s' => \$source,
'verbose' => \$verbose,
'version' => \$versionReq,
) or pod2usage(2);
@@ -72,11 +73,30 @@ if (scalar(@ARGV) != 2) {
}
my $action = $ARGV[0];
my $distroName = $ARGV[1];
-if ($action !~ m[^import-into-db|install|update$]i) {
- print STDERR _tr("You need to specify exactly one action:\n\tinstall, update or import-into-db\n");
+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 specifiy 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)
@@ -97,6 +117,9 @@ if ($action =~ m[import]i) {
} 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__
@@ -114,9 +137,11 @@ slxos-setup [options] <action> <distro-name>
--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
@@ -142,6 +167,16 @@ 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.