| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::PkgConf::Debian; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Rex::Helper::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Rex::PkgConf::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use base qw(Rex::PkgConf::Base); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $self = $proto->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub get_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_options: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ( $self, $pkg, $option ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | die "Package name required to configure" unless $pkg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $conf_cmd = "debconf-show $pkg"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | Rex::Logger::debug("Running command $conf_cmd"); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my @lines = i_run $conf_cmd; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my %config; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Example line: | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # * keyboard-configuration/optionscode: grp:caps_toggle,grp_led:scroll | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | Rex::Logger::debug("Parsing line $line"); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $line =~ m!^(\*?)\s+([^:]+):\s*(.*)! ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my ( $already_set, $question, $value ) = ( $1, $2, $3, $4 ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | Rex::Logger::debug( | |||||||||||||||||||||||||||||||||||||||||
| 44 | "Found configuration question $question with value $value"); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | next if $option && $option ne $question; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$option and $option ne $question
MC/DC0%0/2
$option and $option ne $question
$option
$option ne $question
Truth table0%0/3
A and B
A= $optionB= $option ne $question
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $already_set = $already_set ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $config{$question} = { | |||||||||||||||||||||||||||||||||||||||||
| 48 | question => $question, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | value => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | already_set => $already_set, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | %config; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub set_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_options: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ( $self, $pkg, $values, %options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | die "set_option usage: set_option package, values, options" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pkg and $values
MC/DC0%0/2
$pkg and $values
$pkg
$values
Truth table0%0/3
A and B
A= $pkgB= $values
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | unless $pkg && $values; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Get existing options first, to see if they need setting | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my %existing = $self->get_options($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my @updated; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | for my $line (@$values) { | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | my ( $question, $value, $type ) = | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ( $line->{question}, $line->{value}, $line->{type} ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | die "Question and type required for each package configuration option" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$question and $type
MC/DC0%0/2
$question and $type
$question
$type
Truth table0%0/3
A and B
A= $questionB= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | unless $question && $type; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $existing{$question} && $existing{$question}->{value} eq $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$existing{$question} and $existing{$question}{"value"} eq $value
MC/DC0%0/2
$existing{$question} and $existing{$question}{"value"} eq $value
$existing{$question}
$existing{$question}{"value"} eq $value
Truth table0%0/3
A and B
A= $existing{$question}B= $existing{$question}{"value"} eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | Rex::Logger::debug("Option $question already set to $value, ignoring"); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( $options{no_update} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$options{"no_update"} and $existing{$question} and $existing{$question}{"already_set"}
$options{"no_update"} and $existing{$question}
MC/DC0%0/3
$options{"no_update"} and $existing{$question} and $existing{$question}{"already_set"}
$options{"no_update"}
$existing{$question}
$existing{$question}{"already_set"}
Truth table0%0/4
A and B and C
A= $options{"no_update"}B= $existing{$question}C= $existing{$question}{"already_set"}
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | && $existing{$question} | ||||||||||||||||||||||||||||||||||||||||||
| 82 | && $existing{$question}->{already_set} ) | ||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | Rex::Logger::debug("Option $question already set, not updating"); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | Rex::Logger::debug("Will set option $question: $value (type $type)"); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | push @updated, "$pkg $question $type $value"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (@updated) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $settings = join '\n', @updated; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $conf_cmd = qq(echo -e "$settings"|debconf-set-selections); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | i_run $conf_cmd; | |||||||||||||||||||||||||||||||||||||||||
| 96 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | changed => 1, | |||||||||||||||||||||||||||||||||||||||||
| 98 | names => \@updated, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return { changed => 0, }; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||