2
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4
# Boot manager configurator. Designed to be architecture and distribution independent.
6
# Copyright (C) 2000-2001 Ximian, Inc.
8
# Authors: Tambet Ingo <tambet@ximian.com>
9
# Arturo Espinosa <arturo@ximian.com>
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU Library General Public License as published
13
# by the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Library General Public License for more details.
21
# You should have received a copy of the GNU Library General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
26
$SCRIPTSDIR = "@scriptsdir@";
27
if ($SCRIPTSDIR =~ /^@scriptsdir[@]/)
33
require "$SCRIPTSDIR/general.pl$DOTIN";
34
require "$SCRIPTSDIR/util.pl$DOTIN";
35
require "$SCRIPTSDIR/file.pl$DOTIN";
36
require "$SCRIPTSDIR/xml.pl$DOTIN";
37
require "$SCRIPTSDIR/util.pl$DOTIN";
38
require "$SCRIPTSDIR/parse.pl$DOTIN";
39
require "$SCRIPTSDIR/replace.pl$DOTIN";
40
require "$SCRIPTSDIR/boot-grub.pl$DOTIN";
41
require "$SCRIPTSDIR/boot-lilo.pl$DOTIN";
42
require "$SCRIPTSDIR/boot-yaboot.pl$DOTIN";
44
# ----------------------------------------------------------------------------
47
# The main reason for these functions is to add default values to xml so the
48
# frontend doesn't have to know anything about lilo or its defaults.
50
sub gst_boot_fix_default
53
my ($entries, $found, $entry);
55
$entries = $$hash{"entry"};
56
return unless $entries;
59
if (exists ($$hash{"default"}))
62
foreach $entry (@$entries)
64
if ($$hash{"default"} eq $$entry{"label"})
70
delete $$hash{"default"} unless $found;
73
if (not exists ($$hash{"default"}))
75
# No 'default', let's add
76
foreach $entry (@$entries)
78
if ($$hash{"key"} == 0)
80
$$hash{"default"} = $$entry{"label"};
87
# Internal. Should be run after fix_entries.
88
sub gst_boot_fix_globals
93
&gst_boot_fix_default ($hash);
97
sub gst_boot_fix_entry
102
return unless $entry;
104
$name = $$entry{"image"} if exists $$entry{"image"};
105
$name = $$entry{"other"} if (!$name && exists $$entry{"other"});
107
# Remove entries without entry identifier 'entry' or 'other'.
113
# Add 'label' field which is optional in lilo.conf
114
unless (exists $$entry{"label"})
116
$$entry{"label"} = $1 if ($name =~ /\S+\/(\S+)$/);
121
sub gst_boot_fix_entries
124
my ($entries, $entry);
128
$entries = $$hash{"entry"};
129
return unless $entries;
131
foreach $entry (@$entries)
133
&gst_boot_fix_entry ($entry);
143
&gst_boot_fix_entries ($hash);
144
&gst_boot_fix_globals ($hash);
147
# --------------------------------------------------------
149
sub gst_boot_bootloader_list
153
if (gst_file_locate_tool ("lilo"))
155
push @list, { "name" => "LILO",
159
if (gst_file_locate_tool ("grub-install"))
161
push @list, { "name" => "Grub",
165
if (gst_file_locate_tool ("ybin"))
167
push @list, { "name" => "YaBoot",
168
"exec" => "yaboot" };
171
return (scalar @list, { "bootloaders" => { "bootloader" => \@list }});
174
sub gst_boot_bootloader_get
176
my ($current_tool, $current_date, $bootl, $date);
179
$bootl = gst_file_locate_tool ("lilo");
182
$date = (stat ($bootl)) [8];
183
if ($date > $current_date)
185
$current_date = $date;
186
$current_tool = "lilo";
190
$bootl = gst_file_locate_tool ("grub-install");
193
$date = (stat ($bootl)) [8];
194
if ($date > $current_date)
196
$current_date = $date;
197
$current_tool = "grub";
201
$bootl = gst_file_locate_tool ("ybin");
204
$date = (stat ($bootl)) [8];
205
if ($date > $current_date)
207
$current_date = $date;
208
$current_tool = "yaboot";
212
if ($current_date eq 0)
214
&gst_report ("platform_no_bootloader", $main::gst_dist);
217
return $current_tool;
221
sub gst_boot_entries_get
223
my ($partition) = @_;
224
my (%dist_attrib, @res, %fn, @entries, $entry);
225
my ($dist, $value, $file, $proc);
226
my ($entry, $j, $key, $tmp);
228
%dist_attrib = &gst_boot_get_entry_parse_table ();
229
%fn = %{$dist_attrib{"fn"}};
230
$proc = $dist_attrib{"entries_get"};
231
@entries = &$proc (\%fn);
233
&gst_boot_grub_check_device_map ();
235
${$dist_attrib{"fn"}}{"PARTITION"} = $partition;
238
foreach $entry (@entries)
240
foreach $j (keys (%fn))
242
$tmp = &gst_parse_expand ($fn{$j}, "key", $key);
243
$ {$dist_attrib{"fn"}}{$j} = &gst_parse_expand ($tmp, "label", $entry);
246
$entry = &gst_parse_from_table ($dist_attrib{"fn"},
247
$dist_attrib{"table"});
249
if (exists ($$entry {"image"}))
251
# this is filled even when it's a linux style entry, delete it
252
delete $$entry {"other"};
255
elsif (exists ($$entry {"other"}))
257
# this may be filled, but it's not necessary
258
delete $$entry {"root"};
269
sub gst_boot_conf_get
272
my $config_file = &gst_boot_grub_get_config_file ();
279
LILO_CONF => "/etc/lilo.conf"
283
[ "partitions", \&gst_partition_scan_info ],
284
# [ "pixmapsup", \&gst_parse_trivial, 0 ],
285
[ "timeout", \&gst_boot_lilo_parse_global, LILO_CONF, "delay" ],
286
[ "prompt", \&gst_boot_lilo_parse_global_kw, LILO_CONF, "prompt" ],
287
[ "default", \&gst_boot_lilo_parse_global, LILO_CONF, "default" ],
288
[ "boot", \&gst_boot_lilo_parse_global, LILO_CONF, "boot" ],
289
# [ "root", \&gst_boot_lilo_parse_global, LILO_CONF, "root" ],
290
[ "entry", \&gst_boot_lilo_parse_entries, LILO_CONF, "%partitions%" ],
298
GRUB_CONF => $config_file,
299
DEVICE_MAP => "/boot/grub/device.map",
300
# MTAB => "/etc/mtab"
304
[ "partitions", \&gst_partition_scan_info ],
305
# [ "pixmapsup", \&gst_parse_trivial, 1 ],
306
# [ "pixmap", \&gst_boot_grub_parse_pixmap, [GRUB_CONF, DEVICE_MAP, MTAB] ],
307
[ "timeout", \&gst_boot_grub_parse_timeout, GRUB_CONF ],
308
[ "prompt", \&gst_boot_grub_parse_prompt, GRUB_CONF ],
309
[ "default", \&gst_boot_grub_parse_default, GRUB_CONF ],
310
[ "entry", \&gst_boot_entries_get, "%partitions%" ],
318
YABOOT_CONF => "/etc/yaboot.conf",
322
[ "partitions", \&gst_partition_scan_info ],
323
[ "timeout", \&gst_boot_lilo_parse_global, YABOOT_CONF, "timeout" ],
324
[ "default", \&gst_boot_lilo_parse_global, YABOOT_CONF, "default" ],
325
[ "boot", \&gst_boot_lilo_parse_global, YABOOT_CONF, "boot" ],
326
[ "root", \&gst_boot_lilo_parse_global, YABOOT_CONF, "root" ],
327
[ "entry", \&gst_boot_yaboot_parse_entries, YABOOT_CONF, "%partitions%", "%root%" ]
332
return &gst_parse_from_table ($ {$tool_tables{$bootl}}{"fn"},
333
$ {$tool_tables{$bootl}}{"table"});
336
sub gst_boot_get_entry_parse_table
338
my $config_file = &gst_boot_grub_get_config_file ();
341
entries_get => \&gst_boot_grub_get_entries_fn,
346
GRUB_CONF => $config_file,
347
DEVICE_MAP => "/boot/grub/device.map",
352
["key", \&gst_parse_trivial, [KEY]],
353
["label", \&gst_parse_trivial, [LABEL]],
354
["root", \&gst_boot_grub_parse_root, [GRUB_CONF, DEVICE_MAP, KEY]],
355
["type", \&gst_boot_grub_parse_type, [GRUB_CONF, KEY, PARTITION], "%root%"],
356
["image", \&gst_boot_grub_parse_image, [GRUB_CONF, DEVICE_MAP, MTAB, KEY]],
357
["other", \&gst_boot_grub_parse_other, [GRUB_CONF, DEVICE_MAP, MTAB, KEY]],
358
["append", \&gst_boot_grub_parse_append, [GRUB_CONF, KEY]],
359
["initrd", \&gst_boot_grub_parse_initrd, [GRUB_CONF, DEVICE_MAP, MTAB, KEY]],
360
["module", \&gst_boot_grub_parse_module, [GRUB_CONF, DEVICE_MAP, MTAB, KEY]],
361
["password", \&gst_boot_grub_parse_password, [GRUB_CONF, KEY]]
367
&gst_report ("platform_no_table", $gst_dist);
371
sub gst_boot_entry_set
373
my ($dist_attrib, $values_hash) = @_;
376
%fn = %{$$dist_attrib{"fn"}};
377
foreach $j (keys (%fn))
379
$fn{$j} = &gst_parse_expand ($ {$$dist_attrib{"fn"}}{$j}, "key", $$values_hash{"key"});
382
return &gst_replace_from_table (\%fn, $$dist_attrib{"table"}, $values_hash);
385
sub gst_boot_entries_set
388
my (%dist_attrib, %fn, @old, @new, @del);
389
my ($i, $proc, $entry);
391
%dist_attrib = &gst_boot_get_entry_replace_table ();
392
%fn = %{$dist_attrib{"fn"}};
394
foreach $entry (@$entries)
396
$new[$$entry{"key"}] = $entry;
398
$proc = $dist_attrib{"entries_get"};
399
@old = &$proc (\%fn);
401
for ($i = 0; $i < &gst_max (scalar @old, scalar @$entries); $i++)
403
if ($new[$i] ne undef)
405
$tmp = &gst_boot_entry_set (\%dist_attrib, $new[$i]);
406
$res = $tmp if !$res;
414
# Delete all old entries that are not in the hash.
415
$proc = $dist_attrib{"entries_del"};
416
$tmp = &$proc (\%fn, \@del);
417
$res = $tmp if !$res;
422
sub gst_boot_conf_set
424
my $values_hash = $_[0];
425
my $config_file = &gst_boot_grub_get_config_file ();
426
$bootl = &gst_boot_bootloader_get ();
431
fn => { LILO_CONF => "/etc/lilo.conf"},
433
[ "boot", \&gst_boot_lilo_replace_global, LILO_CONF, "boot" ],
434
# [ "root", \&gst_boot_lilo_replace_global, LILO_CONF, "root" ],
435
[ "timeout", \&gst_boot_lilo_replace_global, LILO_CONF, "timeout" ],
436
[ "timeout", \&gst_boot_lilo_replace_global, LILO_CONF, "delay" ],
437
[ "prompt", \&gst_boot_lilo_replace_global_kw, LILO_CONF, "prompt" ],
438
[ "default", \&gst_boot_lilo_replace_global, LILO_CONF, "default" ],
439
[ "entry", \&gst_boot_lilo_entries_set, LILO_CONF ],
447
GRUB_CONF => $config_file,
448
DEVICE_MAP => "/boot/grub/device.map",
453
# [ "pixmap", \&gst_boot_grub_replace_pixmap, [GRUB_CONF, DEVICE_MAP, MTAB] ],
454
[ "timeout", \&gst_boot_grub_replace_timeout, GRUB_CONF ],
455
[ "prompt", \&gst_boot_grub_replace_prompt, GRUB_CONF ],
456
[ "default", \&gst_boot_grub_replace_default, GRUB_CONF , "%entry%"],
457
[ "entry", \&gst_boot_grub_entries_set, [GRUB_CONF, DEVICE_MAP, MTAB] ],
463
fn => { YABOOT_CONF => "/etc/yaboot.conf" },
466
[ "boot", \&gst_boot_lilo_replace_global, YABOOT_CONF, "boot" ],
467
[ "timeout", \&gst_boot_lilo_replace_global, YABOOT_CONF, "timeout" ],
468
[ "default", \&gst_boot_lilo_replace_global, YABOOT_CONF, "default" ],
469
[ "entry", \&gst_boot_yaboot_entries_set, YABOOT_CONF ],
474
return &gst_replace_from_table ($ {$tool_tables{$bootl}}{"fn"},
475
$ {$tool_tables{$bootl}}{"table"}, $values_hash);
478
sub gst_boot_get_entry_replace_table
480
my $config_file = &gst_boot_grub_get_config_file ();
483
entries_get => \&gst_boot_grub_get_entries_fn,
484
entries_del => \&gst_boot_grub_remove_entries,
488
GRUB_CONF => $config_file,
489
DEVICE_MAP => "/boot/grub/device.map",
494
# label has to go first, because it creates the entry if non-existent.
495
["label", \&gst_boot_grub_replace_label, [GRUB_CONF, KEY]],
496
# ["type", \&gst_boot_grub_replace_type, [GRUB_CONF, KEY]],
497
["root", \&gst_boot_grub_replace_root, [GRUB_CONF, DEVICE_MAP, KEY, "%type%"]],
498
["image", \&gst_boot_grub_replace_image, [GRUB_CONF, DEVICE_MAP, MTAB, KEY]],
499
["other", \&gst_boot_grub_replace_other, [GRUB_CONF, DEVICE_MAP, KEY]],
500
["append", \&gst_boot_grub_replace_append, [GRUB_CONF, DEVICE_MAP, KEY]],