line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Revision History: |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# 27-Nov-2002 Dick Munroe (munroe@csworks.com) |
6
|
|
|
|
|
|
|
# Initial Version Created. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# 18-May-2003 Dick Munroe (munroe@csworks.com) |
9
|
|
|
|
|
|
|
# Make sure package variables can't leak. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# 19-May-2003 Dick Munroe (munroe@csworks.com) |
12
|
|
|
|
|
|
|
# Use Carp. |
13
|
|
|
|
|
|
|
# Isolate kif related classes in a KIF namespace |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package KIF::Bootloader::lilo; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
859
|
use vars qw($VERSION @ISA) ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = "1.03" ; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use strict ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
6
|
use Carp ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
25
|
1
|
|
|
1
|
|
5
|
use File::Basename ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
26
|
1
|
|
|
1
|
|
6
|
use File::Copy ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
27
|
1
|
|
|
1
|
|
5
|
use FileHandle ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
28
|
1
|
|
|
1
|
|
375
|
use KIF::Bootloader ; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
29
|
1
|
|
|
1
|
|
678
|
use StanzaFile::Lilo ; |
|
1
|
|
|
|
|
472
|
|
|
1
|
|
|
|
|
787
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @ISA = qw(KIF::Bootloader) ; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
0
|
|
my $thePackage = shift ; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $theObject = $thePackage->_new() ; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if (-e "/etc/lilo.conf") |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
|
|
|
$theObject->filename("/etc/lilo.conf") ; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
|
|
|
croak "No lilo.conf file found" ; |
46
|
|
|
|
|
|
|
} ; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $theObject ; |
49
|
|
|
|
|
|
|
} ; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub initrdFile |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my $theObject = shift ; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $theLiloFile = new StanzaFile::Lilo(file_name=>$theObject->filename()) ; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $theDefaultLabel = $theLiloFile->header()->item('default') ; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
foreach ($theLiloFile->order()) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
0
|
|
|
|
|
if ($theLiloFile->stanza($_)->item('label') eq $theDefaultLabel) |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
0
|
|
|
|
|
croak "No initrd item in stanza: $theDefaultLabel" |
64
|
|
|
|
|
|
|
if (!defined($theLiloFile->stanza($_)->item('initrd'))) ; |
65
|
0
|
|
|
|
|
|
return basename($theLiloFile->stanza($_)->item('initrd')) ; |
66
|
|
|
|
|
|
|
} ; |
67
|
|
|
|
|
|
|
} ; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
croak "Can't find a stanza with label: $theDefaultLabel" ; |
70
|
|
|
|
|
|
|
} ; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub modify |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
0
|
|
my $theObject = shift ; |
75
|
0
|
|
|
|
|
|
my $theBuildObject = shift ; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# Modify the lilo.conf file only if we're not just rebuilding the |
79
|
|
|
|
|
|
|
# current default kernel. |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $theReleaseTag = $theBuildObject->releaseTag() ; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $theCurrentKernel = readlink "/boot/vmlinuz" ; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$theCurrentKernel =~ s,.*/,, ; |
87
|
0
|
|
|
|
|
|
$theCurrentKernel =~ s,.*?-,, ; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
return if ($theCurrentKernel eq $theReleaseTag); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $theLiloFile = new StanzaFile::Lilo(file_name=>$theObject->filename()) ; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
foreach ($theLiloFile->order()) |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# The current kernel is already in the lilo.conf file, so |
97
|
|
|
|
|
|
|
# we can safely not modify the file. |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
return if (m,-$theReleaseTag( |$),) ; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# |
104
|
|
|
|
|
|
|
# At this point we know we have to modify the lilo.conf file |
105
|
|
|
|
|
|
|
# |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $theNewStanza = $theLiloFile->header()->item('default') ; # Extract the label of the default stanza. |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach ($theLiloFile->order()) |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
0
|
|
|
|
|
if ($theLiloFile->stanza($_)->item('label') eq $theNewStanza) |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
|
$theNewStanza = $theLiloFile->stanza($_)->new() ; |
114
|
|
|
|
|
|
|
# Extract a clone of the default lilo entry. |
115
|
0
|
|
|
|
|
|
last ; # Done looking. |
116
|
|
|
|
|
|
|
} ; |
117
|
|
|
|
|
|
|
} ; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# |
120
|
|
|
|
|
|
|
# New Stanza is a clone of the default entry, modify it so that |
121
|
|
|
|
|
|
|
# everything will point to the new kernel. |
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $theCurrentRelease = $theNewStanza->name() ; |
125
|
0
|
|
|
|
|
|
$theCurrentRelease =~ s/.*?vmlinuz-(.*?)( |$).*/$1/ ; |
126
|
0
|
|
|
|
|
|
my $theString ; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
($theString = $theNewStanza->name()) =~ s/$theCurrentRelease/$theReleaseTag/ ; |
129
|
0
|
|
|
|
|
|
$theNewStanza->name($theString) ; # Change the name of the new kernel image. |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
foreach ($theNewStanza->order()) |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
|
|
|
($theString = $theNewStanza->item($_)) =~ s/$theCurrentRelease/$theReleaseTag/ ; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$theNewStanza->item($_, $theString) ; |
136
|
|
|
|
|
|
|
} ; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$theNewStanza->item('label', "KIF-$theReleaseTag"); |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$theLiloFile->add($theNewStanza) ; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$theLiloFile->header()->item('default', $theNewStanza->item('label')) ; |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
if (!$theBuildObject->testFlag()) |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
|
|
|
move($theObject->filename(), $theObject->filename() . ".old") ; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$theBuildObject->_print("Moving " . $theObject->filename() . " => " . $theObject->filename() . ".old\n",1) ; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$theString = $theLiloFile->write(file_name=>$theObject->filename()) ; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$theBuildObject->_print($theString, 3) ; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
else |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
|
|
|
$theBuildObject->_print($theLiloFile->asString(), 3) ; |
157
|
|
|
|
|
|
|
} ; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# LILO requires that the new bootloader information be linked to |
161
|
|
|
|
|
|
|
# the boot block. The following does this and ups the verbosity |
162
|
|
|
|
|
|
|
# to match. |
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$theString = 'lilo' ; |
166
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
$theString = $theString . (' -v' x $theBuildObject->verboseFlag()) if $theBuildObject->verboseFlag() ; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$theBuildObject->run($theString) ; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $theObject ; |
172
|
|
|
|
|
|
|
} ; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub validate |
175
|
|
|
|
|
|
|
{ |
176
|
|
|
|
|
|
|
# |
177
|
|
|
|
|
|
|
# A valid lilo.conf has a default entry and a valid stanza |
178
|
|
|
|
|
|
|
# at that entry. |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
0
|
0
|
|
my $theObject = shift ; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $theBuildObject = shift ; |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$theObject->SUPER::validate($theBuildObject) ; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
my $theFileName = $theObject->filename() ; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my $theLiloFile = new StanzaFile::Lilo(file_name=>$theFileName) ; |
190
|
0
|
|
|
|
|
|
my $theIndex ; |
191
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
if (!(defined($theIndex = $theLiloFile->header()->item('default')))) |
193
|
|
|
|
|
|
|
{ |
194
|
0
|
|
|
|
|
|
print STDERR <<"EOT" ; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$theFileName must be in a standard form for kif to work properly. |
197
|
|
|
|
|
|
|
There must be a default entry in the header portion of the file |
198
|
|
|
|
|
|
|
of the form: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
default=label |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
where label is the value of the label item in the stanza to be |
203
|
|
|
|
|
|
|
booted by default. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Please add an appropriate line to $theFileName and rerun kif. |
206
|
|
|
|
|
|
|
EOT |
207
|
0
|
|
|
|
|
|
croak "$theFileName is invalid." ; |
208
|
|
|
|
|
|
|
} ; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# |
211
|
|
|
|
|
|
|
# Now make sure that the particular configuration is actually |
212
|
|
|
|
|
|
|
# in the configuration file. |
213
|
|
|
|
|
|
|
# |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $theDefaultStanza ; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
foreach ($theLiloFile->order()) |
218
|
|
|
|
|
|
|
{ |
219
|
0
|
0
|
|
|
|
|
if ($theLiloFile->stanza($_)->item('label') eq $theLiloFile->header()->item('default')) |
220
|
|
|
|
|
|
|
{ |
221
|
0
|
|
|
|
|
|
$theDefaultStanza = $theLiloFile->stanza($_) ; |
222
|
0
|
|
|
|
|
|
last ; |
223
|
|
|
|
|
|
|
} ; |
224
|
|
|
|
|
|
|
} ; |
225
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
if (!(defined($theDefaultStanza))) |
227
|
|
|
|
|
|
|
{ |
228
|
0
|
|
|
|
|
|
print STDERR << "EOT" ; |
229
|
|
|
|
|
|
|
The stanza indicated by the default header item in $theFileName does |
230
|
|
|
|
|
|
|
not exist. You must correct the default value and rerun kif. |
231
|
|
|
|
|
|
|
EOT |
232
|
0
|
|
|
|
|
|
croak "Invalid default configuration header in $theFileName" ; |
233
|
|
|
|
|
|
|
} ; |
234
|
|
|
|
|
|
|
} ; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |