line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Configure; |
2
|
1
|
|
|
1
|
|
959
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
735
|
use Expect; |
|
1
|
|
|
|
|
26524
|
|
|
1
|
|
|
|
|
52
|
|
6
|
1
|
|
|
1
|
|
7
|
use Perl::Configure::Questions; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
7
|
1
|
|
|
1
|
|
557
|
use Data::Dumper; |
|
1
|
|
|
|
|
4796
|
|
|
1
|
|
|
|
|
46
|
|
8
|
1
|
|
|
1
|
|
4
|
use YAML qw(Dump LoadFile); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
728
|
use Log::Log4perl qw(:easy); |
|
1
|
|
|
|
|
33495
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
########################################### |
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
########################################### |
16
|
2
|
|
|
2
|
0
|
266
|
my($class, @options) = @_; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
10
|
my $self = { |
19
|
|
|
|
|
|
|
exp => Expect->new(), |
20
|
|
|
|
|
|
|
yml_file => undef, |
21
|
|
|
|
|
|
|
timeout => 600, |
22
|
|
|
|
|
|
|
questions => Perl::Configure::Questions->new(), |
23
|
|
|
|
|
|
|
@options |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->{bk} = $self->{questions}->by_key(), |
27
|
|
|
|
|
|
|
$self->{bp} = $self->{questions}->by_pattern(), |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
16
|
$self->{exp}->raw_pty(1); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
53
|
bless $self, $class; |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
8
|
if(defined $self->{yml_file}) { |
34
|
0
|
|
|
|
|
0
|
my $data = LoadFile $self->{yml_file}; |
35
|
0
|
|
|
|
|
0
|
$self->define(%$data); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
5
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
########################################### |
42
|
|
|
|
|
|
|
sub define { |
43
|
|
|
|
|
|
|
########################################### |
44
|
2
|
|
|
2
|
0
|
142
|
my($self, %args) = @_; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
5
|
for my $key (keys %args) { |
47
|
3
|
100
|
|
|
|
7
|
if(! exists $self->{bk}->{$key}) { |
48
|
|
|
|
|
|
|
LOGDIE "Unknown token: '$key'. Must be one of ", |
49
|
1
|
|
|
|
|
9
|
join(", ", sort $self->{questions}->tokens()), "."; |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
6
|
$self->{define}->{$key} = $args{$key}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
########################################### |
56
|
|
|
|
|
|
|
sub run { |
57
|
|
|
|
|
|
|
########################################### |
58
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
unlink "Policy.sh"; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my @patterns = $self->{questions}->patterns(); |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
$self->{exp}->spawn("./Configure") |
65
|
|
|
|
|
|
|
or LOGDIE "Cannot spawn: $!\n"; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
{ my ($matched_pattern_position, $error, $match, |
68
|
|
|
|
|
|
|
$before_match, $after_match) = |
69
|
|
|
|
|
|
|
$self->{exp}->expect( |
70
|
|
|
|
|
|
|
$self->{timeout}, |
71
|
0
|
|
|
|
|
|
map { -re => $_ } @patterns); |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if(defined $match) { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
DEBUG "Match: [$match]"; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $token = $self->{bp}->{ |
78
|
0
|
|
|
|
|
|
$patterns[$matched_pattern_position-1]}->[0]; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if(! defined $token) { |
81
|
0
|
|
|
|
|
|
LOGDIE "Internal error: match($match) but no token: ", |
82
|
|
|
|
|
|
|
"pos=$matched_pattern_position ", |
83
|
|
|
|
|
|
|
"error=$error ", |
84
|
|
|
|
|
|
|
"before=$before_match ", |
85
|
|
|
|
|
|
|
"after=$after_match ", |
86
|
|
|
|
|
|
|
; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $response = ""; |
90
|
0
|
|
|
|
|
|
DEBUG "Entry for token '$token': ", Dumper($self->{bk}->{$token}); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Grab default answer if existent |
93
|
0
|
|
|
|
|
|
my $override = $self->{bk}->{$token}->[2]; |
94
|
0
|
0
|
|
|
|
|
$response = $override if defined $override; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if(exists $self->{define}->{$token}) { |
97
|
0
|
|
|
|
|
|
$response = $self->{define}->{$token}; |
98
|
0
|
|
|
|
|
|
INFO "Overriding with [$response]"; |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
|
|
|
|
|
INFO "Filling in [DEFAULT=$response]"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
DEBUG "Response: [$response]"; |
104
|
0
|
|
|
|
|
|
$self->{exp}->send("$response\n"); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
redo; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |