line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::DSL; |
2
|
2
|
|
|
2
|
|
6257
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
59
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
4
|
2
|
|
|
2
|
|
11
|
use parent qw(Exporter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
109
|
use Cinnamon::Config; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
7
|
2
|
|
|
2
|
|
590
|
use Cinnamon::Local; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
69
|
|
8
|
2
|
|
|
2
|
|
661
|
use Cinnamon::Remote; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
55
|
|
9
|
2
|
|
|
2
|
|
11
|
use Cinnamon::Logger; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
74
|
|
10
|
2
|
|
|
2
|
|
1106
|
use Term::ReadKey; |
|
2
|
|
|
|
|
3083
|
|
|
2
|
|
|
|
|
524
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( |
13
|
|
|
|
|
|
|
set |
14
|
|
|
|
|
|
|
get |
15
|
|
|
|
|
|
|
role |
16
|
|
|
|
|
|
|
task |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
remote |
19
|
|
|
|
|
|
|
run |
20
|
|
|
|
|
|
|
sudo |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub set ($$) { |
24
|
11
|
|
|
11
|
0
|
33
|
my ($name, $value) = @_; |
25
|
11
|
|
|
|
|
35
|
Cinnamon::Config::set $name => $value; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get ($@) { |
29
|
0
|
|
|
0
|
0
|
0
|
my ($name, @args) = @_; |
30
|
0
|
|
|
|
|
0
|
Cinnamon::Config::get $name, @args; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub role ($$;$) { |
34
|
9
|
|
|
9
|
0
|
25
|
my ($name, $hosts, $params) = @_; |
35
|
9
|
|
100
|
|
|
54
|
$params ||= {}; |
36
|
9
|
|
|
|
|
35
|
Cinnamon::Config::set_role $name => $hosts, $params; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub task ($$) { |
40
|
12
|
|
|
12
|
0
|
37
|
my ($task, $task_def) = @_; |
41
|
|
|
|
|
|
|
|
42
|
12
|
|
|
|
|
44
|
Cinnamon::Config::set_task $task => $task_def; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub remote (&$) { |
46
|
0
|
|
|
0
|
0
|
0
|
my ($code, $host) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $remote = Cinnamon::Remote->new( |
49
|
|
|
|
|
|
|
host => $host, |
50
|
|
|
|
|
|
|
user => Cinnamon::Config::user, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
2
|
|
16
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
683
|
|
54
|
0
|
|
|
0
|
|
0
|
local *_host = sub { $remote->host }; |
|
0
|
|
|
|
|
0
|
|
55
|
0
|
|
|
0
|
|
0
|
local *_execute = sub { $remote->execute(@_) }; |
|
0
|
|
|
|
|
0
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
$code->($host); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub run (@) { |
61
|
0
|
|
|
0
|
0
|
0
|
my (@cmd) = @_; |
62
|
0
|
|
|
|
|
0
|
my $opt; |
63
|
0
|
0
|
|
|
|
0
|
$opt = shift @cmd if ref $cmd[0] eq 'HASH'; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my ($stdout, $stderr); |
66
|
0
|
|
|
|
|
0
|
my $result; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
log info => sprintf "[%s :: executing] %s", _host(), join(' ', @cmd); |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
0
|
|
|
0
|
if ($opt && $opt->{sudo}) { |
71
|
0
|
|
|
|
|
0
|
my $password = Cinnamon::Config::get('password'); |
72
|
0
|
0
|
|
|
|
0
|
$password = _sudo_password() unless (defined $password); |
73
|
0
|
|
|
|
|
0
|
$opt->{password} = $password; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
$result = _execute($opt, @cmd); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
if ($result->{has_error}) { |
79
|
0
|
|
|
|
|
0
|
die sprintf "error status: %d", $result->{error}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
return ($result->{stdout}, $result->{stderr}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub sudo (@) { |
86
|
0
|
|
|
0
|
0
|
0
|
my (@cmd) = @_; |
87
|
0
|
|
|
|
|
0
|
my $tty = Cinnamon::Config::get('tty'); |
88
|
0
|
|
|
|
|
0
|
run {sudo => 1, tty => !! $tty}, @cmd; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _sudo_password { |
92
|
1
|
|
|
1
|
|
31
|
my $password; |
93
|
1
|
|
|
|
|
54
|
print "Enter sudo password: "; |
94
|
1
|
|
|
|
|
11
|
ReadMode "noecho"; |
95
|
1
|
|
|
|
|
36
|
chomp($password = ReadLine 0); |
96
|
1
|
|
|
|
|
40
|
Cinnamon::Config::set('password' => $password); |
97
|
1
|
|
|
|
|
3
|
ReadMode 0; |
98
|
1
|
|
|
|
|
160
|
print "\n"; |
99
|
1
|
|
|
|
|
10
|
return $password; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
|
|
sub _host { 'localhost' } |
103
|
0
|
|
|
0
|
|
|
sub _execute { Cinnamon::Local->execute(@_) } |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
!!1; |