line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::bclone; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
69820
|
use strict; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
57
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
457
|
use Rex::Logger; |
|
1
|
|
|
|
|
11069
|
|
|
1
|
|
|
|
|
38
|
|
13
|
1
|
|
|
1
|
|
423
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
79532
|
|
|
1
|
|
|
|
|
75
|
|
14
|
1
|
|
|
1
|
|
11
|
use Term::ANSIColor qw(colorstrip); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2282
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
17
|
0
|
|
|
0
|
0
|
|
my ( $class, %opts ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# make sure we have the required keys |
20
|
|
|
|
|
|
|
# and sane |
21
|
0
|
|
|
|
|
|
my @required_keys = ( 'old', 'new' ); |
22
|
0
|
|
|
|
|
|
foreach my $key (@required_keys) { |
23
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{$key} ) ) { |
24
|
0
|
|
|
|
|
|
die( 'Required key "' . $key . '" not defined' ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# make sure it does not contain any possible characters we don't want |
28
|
0
|
0
|
|
|
|
|
if ( $opts{$key} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) { |
29
|
|
|
|
|
|
|
die 'The value for "' |
30
|
|
|
|
|
|
|
. $key . '", "' |
31
|
0
|
|
|
|
|
|
. $opts{$key} |
32
|
|
|
|
|
|
|
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# the command to use |
37
|
0
|
|
|
|
|
|
my $command = 'cbsd bclone old=' . $opts{old} . ' new=' . $opts{new}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# make sure all the variables are sane |
40
|
|
|
|
|
|
|
# and if set and sane add it |
41
|
0
|
|
|
|
|
|
my @bool_vars = ( 'checkstate', 'promote', 'mac_reinit' ); |
42
|
0
|
|
|
|
|
|
foreach my $key (@bool_vars) { |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# make sure that the it is either 0 or 1 |
45
|
0
|
0
|
0
|
|
|
|
if ( defined( $opts{$key} ) && ( $opts{$key} !~ /^[01]$/ ) ) { |
46
|
0
|
|
|
|
|
|
die( 'Key "' . $key . '" defined and is "' . $opts{key} . '", which does not match /^[01]$/' ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# if we get here it is sane and if defined, set it |
50
|
0
|
0
|
|
|
|
|
if ( defined( $opts{key} ) ) { |
51
|
0
|
|
|
|
|
|
$command = $command . ' ' . $key . '=' . $opts{$key}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
Rex::Logger::debug( "Cloning CBSD VM via... " . $command ); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $returned = i_run( $command, fail_ok => 1 ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# the output is colorized |
61
|
0
|
|
|
|
|
|
$returned = colorstrip($returned); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# test after no such as that will also exit non-zero |
64
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
65
|
0
|
|
|
|
|
|
die( "Error running '" . $command . "' returned... " . $returned ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |