mirror of
https://github.com/fspc/gbootroot.git
synced 2025-02-23 17:13:22 -05:00
This gets rid of the annoying perhaps you are not root for gdkbirdaao,
and only tests if root and using a method which has lilo .. default if method hasn't been chosen.
This commit is contained in:
parent
ec56fa40d1
commit
16a076e283
252
gbootroot
252
gbootroot
@ -3777,131 +3777,155 @@ sub initrd {
|
|||||||
} # end sub initrd
|
} # end sub initrd
|
||||||
|
|
||||||
# This was submitted by Cristian "cretzu."
|
# This was submitted by Cristian "cretzu."
|
||||||
sub gdkbirdaao
|
sub gdkbirdaao {
|
||||||
{
|
|
||||||
# Guess Default Kernel Boot Image Root Device And Append Options (gdbirdaao)
|
|
||||||
#
|
|
||||||
# We return a list with 3 elements:
|
|
||||||
#
|
|
||||||
# root device, kernel boot image path and append options
|
|
||||||
#
|
|
||||||
# The last list element (append options) could be returned as a list
|
|
||||||
# of options, but it probably might be cleaner if the caller splitted it.
|
|
||||||
#
|
|
||||||
# this should cover the following cases:
|
|
||||||
#
|
|
||||||
# 1. we have a 'root=...' somewhere above the 'image=...' block(s), and
|
|
||||||
# the image block may or may not have a root specified
|
|
||||||
#
|
|
||||||
# 2. there is no default label, in which case, we take the first one
|
|
||||||
#
|
|
||||||
# 3. there is a default label, and that's what we pick up
|
|
||||||
#
|
|
||||||
|
|
||||||
my $ret_image_path = '';
|
# Guess Default Kernel Boot Image Root Device And Append Options
|
||||||
my $ret_root_dev = '';
|
#(gdbirdaao)
|
||||||
my $ret_append = '';
|
#
|
||||||
|
# We return a list with 3 elements:
|
||||||
|
#
|
||||||
|
# root device, kernel boot image path and append options
|
||||||
|
#
|
||||||
|
# The last list element (append options) could be returned as a list
|
||||||
|
# of options, but it probably might be cleaner if the caller splitted it.
|
||||||
|
#
|
||||||
|
# this should cover the following cases:
|
||||||
|
#
|
||||||
|
# 1. we have a 'root=...' somewhere above the 'image=...' block(s), and
|
||||||
|
# the image block may or may not have a root specified
|
||||||
|
#
|
||||||
|
# 2. there is no default label, in which case, we take the first one
|
||||||
|
#
|
||||||
|
# 3. there is a default label, and that's what we pick up
|
||||||
|
#
|
||||||
|
|
||||||
if (-e $lilo_conf and !-d $lilo_conf)
|
my $ret_image_path = '';
|
||||||
{
|
my $ret_root_dev = '';
|
||||||
|
my $ret_append = '';
|
||||||
|
|
||||||
my @lilo_lines;
|
|
||||||
open(LIL, $lilo_conf) or warn "*** $lilo_conf not found, perhaps because you are not root?";
|
|
||||||
@lilo_lines = <LIL>;
|
|
||||||
close(LIL);
|
|
||||||
chomp(@lilo_lines);
|
|
||||||
|
|
||||||
my $default_label = '';
|
# enough of the annoying "perhaps you are not root"
|
||||||
my %image_blocks;
|
# ofcourse this test is always ran assuming lilo is used.
|
||||||
my $image_block_name_prefix = 'ImageBlock';
|
if ( $> == 0 ) {
|
||||||
my $image_block_no = 1;
|
|
||||||
my $image_block_name = '';
|
|
||||||
my $root_dev = '';
|
|
||||||
|
|
||||||
for (@lilo_lines)
|
if ( !$container[METHOD] ||
|
||||||
{
|
$container[METHOD] eq "2 disk compression" ) {
|
||||||
# ignore comment lines
|
|
||||||
next if m/^\s*[#]/;
|
|
||||||
|
|
||||||
# cleanup whitespace
|
if (-e $lilo_conf and !-d $lilo_conf) {
|
||||||
s/\s*//;
|
|
||||||
s/\s*$//;
|
|
||||||
s/\s*=\s*/=/;
|
|
||||||
|
|
||||||
# 'default=whatever' returns just a label
|
my @lilo_lines;
|
||||||
if (m/default=(.+)\s*/)
|
open(LIL, $lilo_conf) or
|
||||||
{
|
warn "*** $lilo_conf not found\n";
|
||||||
$default_label = $1;
|
@lilo_lines = <LIL>;
|
||||||
}
|
close(LIL);
|
||||||
# start of a new 'image=<kernel path>' image block or similar
|
chomp(@lilo_lines);
|
||||||
elsif (m/(image|other)=(.+)\s*/)
|
|
||||||
{
|
|
||||||
$image_block_name = sprintf("%s%02d",
|
|
||||||
$image_block_name_prefix,
|
|
||||||
$image_block_no);
|
|
||||||
$image_blocks{$image_block_name}{'kernel_image_path'} = $2;
|
|
||||||
$image_blocks{$image_block_name}{'root_device'} = $root_dev;
|
|
||||||
$image_block_no += 1;
|
|
||||||
}
|
|
||||||
# image block label
|
|
||||||
elsif (m/label=(.+)\s*/)
|
|
||||||
{
|
|
||||||
$image_blocks{$image_block_name}{'block_label'} = $1;
|
|
||||||
}
|
|
||||||
# 'root=<root device>'
|
|
||||||
elsif (m#root=/dev/(.+)\s*#)
|
|
||||||
{
|
|
||||||
# inside an image block
|
|
||||||
if ($image_block_name and
|
|
||||||
defined($image_blocks{$image_block_name}{'root_device'}))
|
|
||||||
{
|
|
||||||
$image_blocks{$image_block_name}{'root_device'} = $1;
|
|
||||||
}
|
|
||||||
# loose
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$root_dev = $1 if !$root_dev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elsif (m#append=\"(.+)\"#)
|
|
||||||
{
|
|
||||||
$image_blocks{$image_block_name}{'append'} = $1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
# Ignore everything else
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# we'll now find the kernel image and root device
|
my $default_label = '';
|
||||||
foreach $image_block_name (sort keys %image_blocks)
|
my %image_blocks;
|
||||||
{
|
my $image_block_name_prefix = 'ImageBlock';
|
||||||
# Assume there's no specified default label; take the first
|
my $image_block_no = 1;
|
||||||
$ret_root_dev = $image_blocks{$image_block_name}{'root_device'}
|
my $image_block_name = '';
|
||||||
if !$ret_root_dev;
|
my $root_dev = '';
|
||||||
$ret_image_path = $image_blocks{$image_block_name}{'kernel_image_path'}
|
|
||||||
if !$ret_image_path;
|
|
||||||
$ret_append = $image_blocks{$image_block_name}{'append'}
|
|
||||||
if !$ret_append;
|
|
||||||
|
|
||||||
# do we have a default kernel?
|
for (@lilo_lines) {
|
||||||
if (defined $image_blocks{$image_block_name}{'block_label'}) {
|
# ignore comment lines
|
||||||
if ($image_blocks{$image_block_name}{'block_label'} eq $default_label)
|
next if m/^\s*[#]/;
|
||||||
{
|
|
||||||
# Found the block match for the default label
|
# cleanup whitespace
|
||||||
$ret_root_dev = $image_blocks{$image_block_name}{'root_device'};
|
s/\s*//;
|
||||||
$ret_image_path = $image_blocks{$image_block_name}{'kernel_image_path'};
|
s/\s*$//;
|
||||||
$ret_append = $image_blocks{$image_block_name}{'append'};
|
s/\s*=\s*/=/;
|
||||||
last;
|
|
||||||
}
|
# 'default=whatever' returns just a label
|
||||||
}
|
if (m/default=(.+)\s*/) {
|
||||||
}
|
$default_label = $1;
|
||||||
}
|
}
|
||||||
|
# start of a new 'image=<kernel path>'
|
||||||
|
# image block or similar
|
||||||
|
elsif (m/(image|other)=(.+)\s*/) {
|
||||||
|
$image_block_name =
|
||||||
|
sprintf("%s%02d",
|
||||||
|
$image_block_name_prefix,
|
||||||
|
$image_block_no);
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'kernel_image_path'} = $2;
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'root_device'} = $root_dev;
|
||||||
|
$image_block_no += 1;
|
||||||
|
}
|
||||||
|
# image block label
|
||||||
|
elsif (m/label=(.+)\s*/) {
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'block_label'} = $1;
|
||||||
|
}
|
||||||
|
# 'root=<root device>'
|
||||||
|
elsif (m#root=/dev/(.+)\s*#) {
|
||||||
|
# inside an image block
|
||||||
|
if ($image_block_name and
|
||||||
|
defined($image_blocks
|
||||||
|
{$image_block_name}
|
||||||
|
{'root_device'})) {
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'root_device'} = $1;
|
||||||
|
}
|
||||||
|
# loose
|
||||||
|
else {
|
||||||
|
$root_dev = $1 if !$root_dev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif (m#append=\"(.+)\"#) {
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'append'} = $1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Ignore everything else
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# we'll now find the kernel image and root device
|
||||||
|
foreach $image_block_name (sort keys %image_blocks) {
|
||||||
|
# Assume there's no specified default label;
|
||||||
|
# take the first
|
||||||
|
$ret_root_dev =
|
||||||
|
$image_blocks{$image_block_name}{'root_device'}
|
||||||
|
if !$ret_root_dev;
|
||||||
|
$ret_image_path =
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'kernel_image_path'}
|
||||||
|
if !$ret_image_path;
|
||||||
|
$ret_append =
|
||||||
|
$image_blocks{$image_block_name}{'append'}
|
||||||
|
if !$ret_append;
|
||||||
|
|
||||||
|
# do we have a default kernel?
|
||||||
|
if (defined $image_blocks{$image_block_name}
|
||||||
|
{'block_label'}) {
|
||||||
|
if ($image_blocks{$image_block_name}
|
||||||
|
{'block_label'} eq $default_label) {
|
||||||
|
# Found the block match for the default label
|
||||||
|
$ret_root_dev =
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'root_device'};
|
||||||
|
$ret_image_path =
|
||||||
|
$image_blocks{$image_block_name}
|
||||||
|
{'kernel_image_path'};
|
||||||
|
$ret_append = $image_blocks
|
||||||
|
{$image_block_name}{'append'};
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} # if METHOD eq 2 disk compression
|
||||||
|
|
||||||
|
} # if not root
|
||||||
|
|
||||||
# and some a small portion of paranoia
|
# and some a small portion of paranoia
|
||||||
$ret_root_dev = 'hda1' if !$ret_root_dev;
|
$ret_root_dev = 'hda1' if !$ret_root_dev;
|
||||||
|
|
||||||
return ($ret_root_dev, $ret_image_path, $ret_append);
|
return ($ret_root_dev, $ret_image_path, $ret_append);
|
||||||
|
|
||||||
} # end sub gdkbirdaao
|
} # end sub gdkbirdaao
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user