-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathshell.pm
More file actions
74 lines (52 loc) · 1.38 KB
/
shell.pm
File metadata and controls
74 lines (52 loc) · 1.38 KB
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
#
package Shell;
use strict;
use warnings;
use Cwd;
use FileHandle;
use File::Path;
use common::utility;
###############################################################################
# Constructor
sub new
{
my $proto = shift;
my $class = ref ($proto) || $proto;
my $self = {'substitute_vars_in_options' => 1};
bless ($self, $class);
return $self;
}
##############################################################################
sub CheckRequirements ()
{
my $self = shift;
my $root = main::GetVariable ('root');
if (!defined $root) {
print STDERR __FILE__, ": Requires \"root\" variable\n";
return 0;
}
return 1;
}
##############################################################################
sub Run ($)
{
my $self = shift;
my $options = shift;
my $root = main::GetVariable ('root');
if (!-r $root || !-d $root) {
mkpath($root);
}
# chop off trailing slash
if ($root =~ m/^(.*)\/$/) {
$root = $1;
}
main::PrintStatus ('Setup', 'Shell');
my $cd = ChangeDir->new({dir => $root});
return {'failure' => 'fatal'} unless ($cd);
print "Running: ${options}\n";
my $result = {};
utility::run_command ($options, $result);
return $result;
}
##############################################################################
main::RegisterCommand ("shell", new Shell ());