From 16a076e283a8879bdd6033071c112804298cee05 Mon Sep 17 00:00:00 2001 From: freesource Date: Wed, 12 Dec 2001 17:59:03 +0000 Subject: [PATCH] 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. --- gbootroot | 268 +++++++++++++++++++++++++++++------------------------- 1 file changed, 146 insertions(+), 122 deletions(-) diff --git a/gbootroot b/gbootroot index cfb385d..bb32cb8 100755 --- a/gbootroot +++ b/gbootroot @@ -3777,131 +3777,155 @@ sub initrd { } # end sub initrd # This was submitted by Cristian "cretzu." -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 = ''; - my $ret_root_dev = ''; - my $ret_append = ''; - - if (-e $lilo_conf and !-d $lilo_conf) - { - - my @lilo_lines; - open(LIL, $lilo_conf) or warn "*** $lilo_conf not found, perhaps because you are not root?"; - @lilo_lines = ; - close(LIL); - chomp(@lilo_lines); - - my $default_label = ''; - my %image_blocks; - my $image_block_name_prefix = 'ImageBlock'; - my $image_block_no = 1; - my $image_block_name = ''; - my $root_dev = ''; - - for (@lilo_lines) - { - # ignore comment lines - next if m/^\s*[#]/; - - # cleanup whitespace - s/\s*//; - s/\s*$//; - s/\s*=\s*/=/; - - # 'default=whatever' returns just a label - if (m/default=(.+)\s*/) - { - $default_label = $1; - } - # start of a new 'image=' 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=' - 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 - } - } +sub gdkbirdaao { - # 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; - } - } - } - } + # 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 = ''; + my $ret_root_dev = ''; + my $ret_append = ''; + + + # enough of the annoying "perhaps you are not root" + # ofcourse this test is always ran assuming lilo is used. + if ( $> == 0 ) { + + if ( !$container[METHOD] || + $container[METHOD] eq "2 disk compression" ) { + + if (-e $lilo_conf and !-d $lilo_conf) { + + my @lilo_lines; + open(LIL, $lilo_conf) or + warn "*** $lilo_conf not found\n"; + @lilo_lines = ; + close(LIL); + chomp(@lilo_lines); + + my $default_label = ''; + my %image_blocks; + my $image_block_name_prefix = 'ImageBlock'; + my $image_block_no = 1; + my $image_block_name = ''; + my $root_dev = ''; + + for (@lilo_lines) { + # ignore comment lines + next if m/^\s*[#]/; + + # cleanup whitespace + s/\s*//; + s/\s*$//; + s/\s*=\s*/=/; + + # 'default=whatever' returns just a label + if (m/default=(.+)\s*/) { + $default_label = $1; + } + # start of a new 'image=' + # 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=' + 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 - $ret_root_dev = 'hda1' if !$ret_root_dev; + # and some a small portion of paranoia + $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