| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | Linux::Bootloader - Base class interacting with Linux bootloaders | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | use Linux::Bootloader; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | my $bootloader = new Linux::Bootloader(); | ||||||||||||||||||||||||||||||||||||||||||
| 10 | my $config_file='/boot/grub/menu.lst'; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | $bootloader->read($config_file); | ||||||||||||||||||||||||||||||||||||||||||
| 13 | $bootloader->print_info('all'); | ||||||||||||||||||||||||||||||||||||||||||
| 14 | $bootloader->add(%hash); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | $bootloader->update(%hash); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | $bootloader->remove(2); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | $bootloader->get_default(); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | $bootloader->set_default(2); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | %hash = $bootloader->read_entry(0); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | $bootloader->write($config_file); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | This module provides base functions for working with bootloader configuration files. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | Creates a new Linux::Bootloader object. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head2 read() | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | Reads configuration file into an array. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | Takes: string. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 write() | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | Writes configuration file. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | Takes: string. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =head2 print_info() | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | Prints information from config. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | Takes: string. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =head2 _info() | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | Parse config into array of hashes. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | Takes: nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | Returns: array of hashes. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =head2 get_default() | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Determine current default kernel. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | Takes: nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | Returns: integer, undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =head2 set_default() | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | Set new default kernel. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | Takes: integer. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head2 add() | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | Add new kernel to config. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | Takes: hash. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =head2 update() | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | Update args of an existing kernel entry. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | Takes: hash. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =head2 remove() | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | Remove kernel from config. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | Takes: string. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Returns: undef on error. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =head2 read_entry() | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | Read an existing entry into a hash suitable to add or update from. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | Takes: integer or title | ||||||||||||||||||||||||||||||||||||||||||
| 91 | Returns: undef or hash | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head2 debug($level) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | Sets or gets the current debug level, 0-5. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | Returns: Debug level | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head2 _check_config() | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | Conducts a basic check for kernel validity | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Returns: true if checks out okay, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | false if not okay, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | undef on error | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =head2 _lookup() | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | Converts title into position. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | Takes: string. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | Returns: integer, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | undef on error | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | package Linux::Bootloader; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | use Linux::Bootloader::Detect; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | our $VERSION = '1.2'; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ( defined $class and $class eq 'Linux::Bootloader' ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and $class eq "Linux::Bootloader"
MC/DC0%0/2
defined $class and $class eq "Linux::Bootloader"
defined $class
$class eq "Linux::Bootloader"
Truth table33%1/3
A and B
A= defined $classB= $class eq "Linux::Bootloader"
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $detected_bootloader = Linux::Bootloader::Detect::detect_bootloader(); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | unless (defined $detected_bootloader) { return undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $class = "Linux::Bootloader::" . "\u$detected_bootloader"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | eval" require $class; "; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my $self = bless ({}, $class); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $self->{config_file} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | unless (defined $self->{'config_file'}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | $self->_set_config_file(); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $self->{config} = []; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->{debug} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $self->{'entry'} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | ### Generic Functions ### | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # Read config file into array | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=7 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | my $config_file=shift || $self->{config_file}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'config_file'}
MC/DC0%0/2
shift() || $self->{'config_file'}
shift()
$self->{'config_file'}
Truth table33%1/3
A || B
A= shift()B= $self->{'config_file'}
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | ▶ | print ("Reading $config_file.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | ▶ | open(CONFIG, "$config_file") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
open(CONFIG, "$config_file") || warn("ERROR: Can't open $config_file.\n") && (return undef)
warn "ERROR: Can't open $config_file.\n" and return undef
MC/DC0%0/2
open(CONFIG, "$config_file") || warn("ERROR: Can't open $config_file.\n") && (return undef)
open(CONFIG, "$config_file")
warn "ERROR: Can't open $config_file.\n"
Truth table66%2/3
A || B
A= open(CONFIG, "$config_file")B= warn "ERROR: Can't open $config_file.\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | || warn ("ERROR: Can't open $config_file.\n") && return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | @{$self->{config}}=<CONFIG>; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | close(CONFIG); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | print ("Current config:\n @{$self->{config}}") if $self->debug()>4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | print ("Closed $config_file.\n") if $self->debug()>2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # Write new config | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=10 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | ▶ | my $config_file=shift || $self->{config_file}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'config_file'}
MC/DC0%0/2
shift() || $self->{'config_file'}
shift()
$self->{'config_file'}
Truth table33%1/3
A || B
A= shift()B= $self->{'config_file'}
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | my @config=@{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | print ("Writing $config_file.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | print join("",@config) if $self->debug() > 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | if (-w $config_file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | system("cp","$config_file","$config_file.bak.boottool"); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | if ($? != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | warn "ERROR: Cannot backup $config_file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | print "Backed up config to $config_file.bak.boottool.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | ▶ | open(CONFIG, ">$config_file") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
open(CONFIG, ">$config_file") || warn("ERROR: Can't open config file.\n") && (return undef)
warn "ERROR: Can't open config file.\n" and return undef
MC/DC0%0/2
open(CONFIG, ">$config_file") || warn("ERROR: Can't open config file.\n") && (return undef)
open(CONFIG, ">$config_file")
warn "ERROR: Can't open config file.\n"
Truth table33%1/3
A || B
A= open(CONFIG, ">$config_file")B= warn "ERROR: Can't open config file.\n"
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | || warn ("ERROR: Can't open config file.\n") && return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | print CONFIG join("",@config); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | close(CONFIG); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | print join("",@config) if $self->debug() > 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | warn "WARNING: You do not have write access to $config_file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | # Parse config into array of hashes | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_info: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my @config=@{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # remove garbarge - comments, blank lines | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | @config=grep(!/^#|^\n/, @config); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my %matches = ( default => '^\s*default[\s+\=]+(\S+)', | |||||||||||||||||||||||||||||||||||||||||
| 214 | timeout => '^\s*timeout[\s+\=]+(\S+)', | ||||||||||||||||||||||||||||||||||||||||||
| 215 | title => '^\s*label[\s+\=]+(\S+)', | ||||||||||||||||||||||||||||||||||||||||||
| 216 | root => '^\s*root[\s+\=]+(\S+)', | ||||||||||||||||||||||||||||||||||||||||||
| 217 | args => '^\s*append[\s+\=]+(.*)', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | initrd => '^\s*initrd[\s+\=]+(\S+)', | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my @sections; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $index=0; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | foreach (@config) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($_ =~ /^\s*(image|other)[\s+\=]+(\S+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $sections[$index]{'kernel'} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | foreach my $key (keys %matches) { | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($_ =~ /$matches{$key}/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $sections[$index]{$key} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $sections[$index]{$key} =~ s/\"|\'//g if ($key eq 'args'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # sometimes config doesn't have a default, so goes to first | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (!(defined $sections[0]{'default'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $sections[0]{'default'} = '0'; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # if default is label name, we need position | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } elsif ($sections[0]{'default'} !~ m/^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | foreach my $index (1..$#sections) { | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($sections[$index]{'title'} eq $sections[0]{'default'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $sections[0]{'default'} = $index-1; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # if still no valid default, set to first | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ( $sections[0]{'default'} !~ m/^\d+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $sections[0]{'default'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # return array of hashes | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return @sections; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Determine current default kernel | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | ▶ | sub get_default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_default: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | ▶ | print ("Getting default.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my @sections = $self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | my $default = $sections[0]{'default'}; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | if ($default =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | return 0+$default; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # Set new default kernel | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub set_default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_default: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $newdefault=shift; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | print ("Setting default.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | return undef unless defined $newdefault; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my @config=@{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # if not a number, do title lookup | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ($newdefault !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $newdefault = $self->_lookup($newdefault); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $kcount = $#sections-1; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ((!defined $newdefault) || ($newdefault < 0) || ($newdefault > $kcount)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $newdefault or $newdefault < 0 or $newdefault > $kcount
not defined $newdefault or $newdefault < 0
MC/DC0%0/3
not defined $newdefault or $newdefault < 0 or $newdefault > $kcount
not defined $newdefault
$newdefault < 0
$newdefault > $kcount
Truth table0%0/4
not(A) or B or C
A= not defined $newdefaultB= $newdefault < 0C= $newdefault > $kcount
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | warn "ERROR: Enter a default between 0 and $kcount.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | # convert position to title | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $newdefault = $sections[++$newdefault]{title}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | foreach my $index (0..$#config) { | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($config[$index] =~ /^\s*default/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $config[$index] = "default=$newdefault # set by $0\n"; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | @{$self->{config}} = @config; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | # Add new kernel to config | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=29 SCAR=67.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my %param=@_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | print ("Adding kernel.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if (!defined $param{'add-kernel'} && defined $param{'kernel'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
not defined $param{"add-kernel"} and defined $param{"kernel"}
MC/DC0%0/2
not defined $param{"add-kernel"} and defined $param{"kernel"}
not defined $param{"add-kernel"}
defined $param{"kernel"}
Truth table0%0/3
not(A) and B
A= not defined $param{"add-kernel"}B= defined $param{"kernel"}
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $param{'add-kernel'} = $param{'kernel'}; | |||||||||||||||||||||||||||||||||||||||||
| 325 | ▶ | } elsif (!defined $param{'add-kernel'} || !defined $param{'title'}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $param{'add-kernel'} && defined $param{'title'}
MC/DC0%0/2
defined $param{'add-kernel'} && defined $param{'title'}
defined $param{'add-kernel'}
defined $param{'title'}
Truth table0%0/3
A && B
A= defined $param{'add-kernel'}B= defined $param{'title'}
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | warn "ERROR: kernel path (--add-kernel), title (--title) required.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } elsif (!(-f "$param{'add-kernel'}")) { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | warn "ERROR: kernel $param{'add-kernel'} not found!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 331 | ▶ | } elsif (defined $param{'initrd'} && !(-f "$param{'initrd'}")) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $param{"initrd"} and not -f qq[$param{"initrd"}]
MC/DC0%0/2
defined $param{"initrd"} and not -f qq[$param{"initrd"}]
defined $param{"initrd"}
not -f qq[$param{"initrd"}]
Truth table0%0/3
A and not(B)
A= defined $param{"initrd"}B= not -f qq[$param{"initrd"}]
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | warn "ERROR: initrd $param{'initrd'} not found!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # remove title spaces and truncate if more than 15 chars | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $param{title} =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $param{title} = substr($param{title}, 0, 15) if length($param{title}) > 15; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # check if title already exists | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if (defined $self->_lookup($param{title})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | warn ("WARNING: Title already exists.\n"); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (defined $param{force}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $self->remove($param{title}); | |||||||||||||||||||||||||||||||||||||||||
| 349 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my @config = @{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | # Use default kernel to fill in missing info | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $default=$self->get_default(); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $default++; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | foreach my $p ('args', 'root') { | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (! defined $param{$p}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $param{$p} = $sections[$default]{$p}; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # use default entry to determine if path (/boot) should be removed | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ($sections[$default]{'kernel'} !~ /^\/boot/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $param{'add-kernel'} =~ s/^\/boot//; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $param{'initrd'} =~ s/^\/boot// unless (!defined $param{'initrd'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my @newkernel; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | push (@newkernel, "image=$param{'add-kernel'}\n", "\tlabel=$param{title}\n"); | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | push (@newkernel, "\tappend=\"$param{args}\"\n") if defined $param{args}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | push (@newkernel, "\tinitrd=$param{initrd}\n") if defined $param{initrd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | push (@newkernel, "\troot=$param{root}\n") if defined $param{root}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | push (@newkernel, "\tread-only\n\n"); | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if (!defined $param{position} || $param{position} !~ /end|\d+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $param{"position"} and $param{"position"} =~ /end|\d+/
MC/DC0%0/2
defined $param{"position"} and $param{"position"} =~ /end|\d+/
defined $param{"position"}
$param{"position"} =~ /end|\d+/
Truth table0%0/3
A and B
A= defined $param{"position"}B= $param{"position"} =~ /end|\d+/
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $param{position}=0; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my @newconfig; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ($param{position}=~/end/ || $param{position} >= $#sections) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$param{"position"} =~ /end/ or $param{"position"} >= $#sections
MC/DC0%0/2
$param{"position"} =~ /end/ or $param{"position"} >= $#sections
$param{"position"} =~ /end/
$param{"position"} >= $#sections
Truth table0%0/3
A or B
A= $param{"position"} =~ /end/B= $param{"position"} >= $#sections
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $param{position}=$#sections; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | push (@newconfig,@config); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ($newconfig[$#newconfig] =~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | push (@newconfig, "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | push (@newconfig,@newkernel); | |||||||||||||||||||||||||||||||||||||||||
| 392 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $index=0; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | foreach (@config) { | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ($_ =~ /^\s*(image|other)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($index==$param{position}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | push (@newconfig, @newkernel); | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | push (@newconfig, $_); | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | @{$self->{config}} = @newconfig; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if (defined $param{'make-default'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $self->set_default($param{position}); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | # Update kernel args | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my %params=@_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | print ("Updating kernel.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if (!defined $params{'update-kernel'} || (!defined $params{'args'} && !defined $params{'remove-args'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $params{"update-kernel"} and defined $params{"args"} || defined $params{"remove-args"}
defined $params{"args"} or defined $params{"remove-args"}
MC/DC0%0/3
defined $params{"update-kernel"} and defined $params{"args"} || defined $params{"remove-args"}
defined $params{"update-kernel"}
defined $params{"args"}
defined $params{"remove-args"}
Truth table0%0/4
A and B or C
A= defined $params{"update-kernel"}B= defined $params{"args"}C= defined $params{"remove-args"}
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | warn "ERROR: kernel position or title (--update-kernel) and args (--args or --remove-args) required.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my @config = @{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | # if not a number, do title lookup | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ($params{'update-kernel'} !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $params{'update-kernel'} = $self->_lookup($params{'update-kernel'}); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $kcount = $#sections-1; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if ($params{'update-kernel'} !~ /^\d+$/ || $params{'update-kernel'} < 0 || $params{'update-kernel'} > $kcount) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $params{"update-kernel"} =~ /^\d+$/ or $params{"update-kernel"} < 0 or $params{"update-kernel"} > $kcount
not $params{"update-kernel"} =~ /^\d+$/ or $params{"update-kernel"} < 0
MC/DC0%0/3
not $params{"update-kernel"} =~ /^\d+$/ or $params{"update-kernel"} < 0 or $params{"update-kernel"} > $kcount
not $params{"update-kernel"} =~ /^\d+$/
$params{"update-kernel"} < 0
$params{"update-kernel"} > $kcount
Truth table0%0/4
not(A) or B or C
A= not $params{"update-kernel"} =~ /^\d+$/B= $params{"update-kernel"} < 0C= $params{"update-kernel"} > $kcount
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | warn "ERROR: Enter a default between 0 and $kcount.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $index=-1; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | foreach (@config) { | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ($_ =~ /^\s*(image|other)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | if ($index==$params{'update-kernel'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if ($_ =~ /(^\s*append[\s\=]+)(.*)\n/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $append = $1; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $args = $2; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $args =~ s/\"|\'//g; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | $args =~ s/\s*$params{'remove-args'}\=*\S*//ig if defined $params{'remove-args'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $args = $args . " ". $params{'args'} if defined $params{'args'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | if ($_ eq "$append\"$args\"\n") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | warn "WARNING: No change made to args.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $_ = "$append\"$args\"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | @{$self->{config}} = @config; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | # Remove kernel from config | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=20 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 3 | my $position=shift; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 3 | my @newconfig; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | return undef unless defined $position; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 3 | my @config=@{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 3 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | ▶ | if ($position=~/^end$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $position=$#sections-1; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } elsif ($position=~/^start$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $position=0; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | print ("Removing kernel $position.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | # remove based on title | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | ▶ | if ($position !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | my $removed=0; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | for (my $index=$#sections; $index > 0; $index--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | ▶ | if (defined $sections[$index]{title} && $position eq $sections[$index]{title}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $sections[$index]{"title"} and $position eq $sections[$index]{"title"}
MC/DC0%0/2
defined $sections[$index]{"title"} and $position eq $sections[$index]{"title"}
defined $sections[$index]{"title"}
$position eq $sections[$index]{"title"}
Truth table33%1/3
A and B
A= defined $sections[$index]{"title"}B= $position eq $sections[$index]{"title"}
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | $removed++ if $self->remove($index-1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | if (! $removed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | warn "ERROR: No kernel with specified title.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | # remove based on position | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } elsif ($position =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | ▶ | if ($position < 0 || $position > $#sections) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$position < 0 or $position > $#sections
MC/DC50%1/2
$position < 0 or $position > $#sections
$position < 0
$position > $#sections
Truth table66%2/3
A or B
A= $position < 0B= $position > $#sections
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | warn "ERROR: Enter a position between 0 and $#sections.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | my $index=-1; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | foreach (@config) { | |||||||||||||||||||||||||||||||||||||||||
| 512 | 19 | ▶ | if ($_ =~ /^\s*(image|other|title)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 3 | $index++ | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # add everything to newconfig, except removed kernel (keep comments) | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 19 | ▶ | if ($index != $position || $_ =~ /^#/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$index != $position or $_ =~ /^#/
MC/DC50%1/2
$index != $position or $_ =~ /^#/
$index != $position
$_ =~ /^#/
Truth table66%2/3
A or B
A= $index != $positionB= $_ =~ /^#/
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 15 | push (@newconfig, $_) | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | @{$self->{config}} = @newconfig; | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # if we removed the default, set new default to first | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | ▶ | $self->set_default(0) if $position == $sections[0]{'default'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 1 | print "Removed kernel $position.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | warn "WARNING: problem removing entered position.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | # Print info from config | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 3 | ▶ | sub print_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_info: called CC=11 SCAR=35.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 3 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 3 | my $info=shift; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 3 | ▶ | return undef unless defined $info; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 3 | ▶ | return undef unless $self->_check_config(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 3 | ▶ | print ("Printing config info.\n") if $self->debug()>1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 3 | my @config=@{$self->{config}}; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 3 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | my ($start,$end); | |||||||||||||||||||||||||||||||||||||||||
| 552 | 3 | ▶ | if ($info =~ /default/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $start=$end=$self->get_default() | |||||||||||||||||||||||||||||||||||||||||
| 554 | } elsif ($info =~ /all/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $start=0; $end=$#sections-1 | |||||||||||||||||||||||||||||||||||||||||
| 556 | } elsif ($info =~ /^\d+/) { | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $start=$end=$info | |||||||||||||||||||||||||||||||||||||||||
| 558 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 3 | warn "ERROR: input should be: #, default, or all.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if ($start < 0 || $end > $#sections-1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$start < 0 or $end > $#sections - 1
MC/DC0%0/2
$start < 0 or $end > $#sections - 1
$start < 0
$end > $#sections - 1
Truth table0%0/3
A or B
A= $start < 0B= $end > $#sections - 1
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | warn "ERROR: No kernels with that index.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | for my $index ($start..$end) { | |||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | print "\nindex\t: $index\n"; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | foreach ( sort keys(%{$sections[$index]}) ) { | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | print "$_\t: $sections[$index]{$_}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | # Set/get debug level | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 69 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 69 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 69 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->{debug} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 69 | ▶ | return $self->{debug} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'debug'} || 0
MC/DC0%0/1
$self->{'debug'} || 0
$self->{'debug'}
Truth table50%1/2
A
A= $self->{'debug'}
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | # Get a bootloader entry as a hash to edit or update. | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | sub read_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_entry: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my $entry=shift; | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | if ($entry !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $entry = $self->_lookup($entry); | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my $index = $entry + 1; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | if ((defined $sections[$index]{'title'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | $self->{'entry'}->{'index'} = $index; | |||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | foreach my $key ( keys %{$sections[$index]} ){ | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $self->{'entry'}->{'data'}->{ $key } = $sections[$index]{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | return $self->{'entry'}->{'data'}; | |||||||||||||||||||||||||||||||||||||||||
| 605 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | # Basic check for valid config | ||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | 41 | ▶ | sub _check_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_config: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 41 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 41 | ▶ | print ("Verifying config.\n") if $self->debug()>3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 41 | ▶ | if ($#{$self->{config}} < 5) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | warn "ERROR: you must read a valid config file first.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 41 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | # lookup position using title | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 4 | ▶ | sub _lookup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lookup: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 4 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 629 | 4 | my $title=shift; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | unless ( defined $title ){ return undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 4 | my @sections=$self->_info(); | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 4 | for my $index (1..$#sections) { | |||||||||||||||||||||||||||||||||||||||||
| 636 | 10 | my $tmp = $sections[$index]{title}; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 10 | ▶ | if (defined $tmp and $title eq $tmp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $tmp and $title eq $tmp
MC/DC50%1/2
defined $tmp and $title eq $tmp
defined $tmp
$title eq $tmp
Truth table66%2/3
A and B
A= defined $tmpB= $title eq $tmp
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | return $index-1; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | Jason N., Open Source Development Labs, Engineering Department <eng@osdl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | Copyright (C) 2006 Open Source Development Labs | ||||||||||||||||||||||||||||||||||||||||||
| 652 | All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | This script is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 655 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | L<boottool>, L<Linux::Bootloader::Grub>, L<Linux::Bootloader::Lilo>, | ||||||||||||||||||||||||||||||||||||||||||
| 660 | L<Linux::Bootloader::Elilo>, L<Linux::Bootloader::Yaboot> | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||