Bootloader/Elilo.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 82 CC 5 SCAR 21.0
CC
5
Cov
0%
boot_once
20.0
install
6.0
new
2.0
CRAP 8.2
1 package Linux::Bootloader::Elilo;
2  
3 =head1 NAME
4  
5 Linux::Bootloader::Elilo - Parse and modify ELILO configuration files.
6  
7 =head1 SYNOPSIS
8  
9 use Linux::Bootloader;
10 use Linux::Bootloader::Elilo;
11
12 my $bootloader = Linux::Bootloader::Elilo->new();
13 my $config_file='/etc/elilo.conf';
14  
15 $bootloader->read($config_file)
16  
17 # add a kernel
18 $bootloader->add(%hash)
19  
20 # remove a kernel
21 $bootloader->remove(2)
22  
23 # set new default
24 $bootloader->set_default(1)
25  
26 $bootloader->write($config_file)
27  
28  
29 =head1 DESCRIPTION
30  
31 This module provides functions for working with ELILO configuration files.
32  
33 Adding a kernel:
34 - add kernel at start, end, or any index position.
35 - kernel path and title are required.
36 - root, kernel args, initrd are optional.
37 - any options not specified are copied from default.
38 - remove any conflicting kernels if force is specified.
39
40 Removing a kernel:
41 - remove by index position
42 - or by title/label
43  
44  
45 =head1 FUNCTIONS
46  
47 Also see L<Linux::Bootloader> for functions available from the base class.
48  
49 =head2 new()
50  
51 Creates a new Linux::Bootloader::Elilo object.
52  
53 =head2 install()
54  
55 Attempts to install bootloader.
56 Takes: nothing.
57 Returns: undef on error.
58  
59 =cut
60  
61  
62 use strict;
63 use warnings;
64 use Linux::Bootloader
65  
66 @Linux::Bootloader::Elilo::ISA = qw(Linux::Bootloader);
67 use base 'Linux::Bootloader';
68  
69  
70 use vars qw( $VERSION );
71 our $VERSION = '1.2';
72  
73  
74 sub new {
75 my $this = shift;
76 my $class = ref($this) || $this;
77 my $self = bless({}, $class);
78  
79 $self->SUPER::new();
80  
81 return $self;
82 }
83  
84 sub _set_config_file {
85 my $self=shift;
86 $self->{'config_file'}='/etc/elilo.conf';
87 }
88  
89  
90 ### ELILO functions ###
91  
92  
93 # Run command to install bootloader
94  
95 sub install {
96 my $self=shift;
97  
98 system("/usr/sbin/elilo");
99 if ($? != 0) {
100 warn ("ERROR: Failed to run elilo.\n") && return undef;
101 }
102 return 1;
103 }
104  
105 # Set kernel to be booted once
106  
107 sub boot_once {
108 my $self=shift;
109 my $label = shift;
110  
111 return undef unless defined $label;
112  
113 $self->read( '/etc/elilo.conf' );
114 my @config=@{$self->{config}};
115  
116 if ( ! grep( /^checkalt/i, @config ) ) {
117 warn("ERROR: Failed to set boot-once.\n");
118 warn("Please add 'checkalt' to global config.\n");
119 return undef;
120 }
121  
122 my @sections = $self->_info();
123 my $position = $self->_lookup($label);
124 $position++;
125 my $efiroot = `grep ^EFIROOT /usr/sbin/elilo | cut -d '=' -f 2`;
126 chomp($efiroot);
127  
128 my $kernel = $efiroot . $sections[$position]{kernel};
129 my $root = $sections[$position]{root};
130 my $args = $sections[$position]{args};
131  
132 #system( "/usr/sbin/eliloalt", "-d" );
133 if ( system( "/usr/sbin/eliloalt", "-s", "$kernel root=$root $args" ) ) {
134 warn("ERROR: Failed to set boot-once.\n");
135 warn("1) Check that EFI var support is compiled into kernel.\n");
136 warn("2) Verify eliloalt works. You may need to patch it to support sysfs EFI vars.\n");
137 return undef;
138 }
139 return 1;
140 }
141  
142  
143 1;
144  
145  
146 =head1 AUTHOR
147  
148 Open Source Development Labs, Engineering Department <eng@osdl.org>
149  
150 =head1 COPYRIGHT
151  
152 Copyright (C) 2006 Open Source Development Labs
153 All Rights Reserved.
154  
155 This script is free software; you can redistribute it and/or modify it
156 under the same terms as Perl itself.
157  
158 =head1 SEE ALSO
159  
160 L<Linux::Bootloader>
161  
162 =cut
163