summaryrefslogtreecommitdiffstats
path: root/installer/slxos-export
blob: 80f1a872e46ffab87786ba819c32dd87f045c537 (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
#! /usr/bin/perl
# -----------------------------------------------------------------------------
# Copyright (c) 2006, 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;

my $abstract = q[
slxos-export
    This script exports an OpenSLX-stage1-system (a.k.a. vendor-OS) into
    an OpenSLX-stage2-system (a.k.a. export), which can be an NFS-export,
	an NBD-image containing a squash-fs.
];

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::OSExport::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;
pod2usage(-verbose => 2) if $manReq;
if ($versionReq) {
	system('slxversion');
	exit 1;
}

openslxInit();

my $action = shift @ARGV;

if ($action =~ m[^list-ex]i) {
	print _tr("List of exported vendor-OSes:\n");
	foreach my $type (sort keys %supportedExportTypes) {
		print join('', map {
						s[^.+/][];
						"\t$type/$_\n";
					   }
					   sort <$openslxConfig{'export-path'}/$type/*>);
	}
} elsif ($action =~ m[^list-in]i) {
	print _tr("List of installed vendor-OSes:\n");
	print join('', map {
					s[^.+/][];
					"\t$_\n";
				   }
				   sort <$openslxConfig{'stage1-path'}/*>);
} elsif ($action =~ m[^list-ty]i) {
	print _tr("List of supported export types:\n\t");
	print join("\n\t", sort keys %supportedExportTypes)."\n";
} elsif ($action =~ m[^export]i) {
	if (scalar(@ARGV) != 2) {
		print STDERR _tr("You need to specify exactly one vendor-os-name and one export-type!\n");
		pod2usage(2);
	}
	my $vendorOSName = shift @ARGV;
	my $exportType = 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 OSExport-engine for given export type and start it:
	my $engine = OpenSLX::OSExport::Engine->new;
	$engine->initialize($vendorOSName, $exportType);
	if (!-e $engine->{'vendor-os-path'}) {
		die _tr("vendor-OS '%s' doesn't exist, giving up!\n",
				$engine->{'vendor-os-path'});
	}
	$engine->exportVendorOS();
} else {
	print STDERR _tr("You need to specify exactly one action:
	export
	list-exported
	list-installed
	list-types
Try '%s --help' for more info.\n", $0);
}

__END__

=head1 NAME

slxos-export - OpenSLX-script to export a stage1-system (a.k.a. vendor-OS) into
a stage2-system (a.k.a. export).
The export itself can be done via several different types, e.g. via NFS or
via a squashfs inside of a network block device.

=head1 SYNOPSIS

slxos-export [options] <action>

  Options:
      --help                   brief help message
      --man                    show full documentation
      --verbose                show more information during execution
      --version                show version

  Actions:
      export <vendor-OS-name> <export-type>
                               exports the vendor-OS with the given name via
                               the given export type
      list-exported
                               list all exported vendor-OSes
      list-installed
                               list all installed vendor-OSes
      list-types
                               list all supported export types

=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<--verbose>

Prints more information during execution of any action.

=item B<--version>

Prints the version and exits.

=back

=head1 EXAMPLES

=head2 Exporting a Vendor-OS

  slxos-export export suse-10.2 nfs

      exports the installed vendor-OS suse-10.2 via nfs, the resulting
      NFS-export will live in '/srv/openslx/export/nfs/suse-10.2'

=cut