Hello community, here is the log from the commit of package perl-Bootloader checked in at Fri Jun 30 16:59:21 CEST 2006. -------- --- perl-Bootloader/perl-Bootloader.changes 2006-05-22 18:20:07.000000000 +0200 +++ perl-Bootloader/perl-Bootloader.changes 2006-06-30 16:07:30.000000000 +0200 @@ -1,0 +2,28 @@ +Wed Jun 28 19:38:31 CEST 2006 - jplack@suse.de + +- map kernel_append params to xen_append params (#188614) when + having a serial console + +------------------------------------------------------------------- +Wed Jun 28 19:32:25 CEST 2006 - jplack@suse.de + +- be nicer while handling empty paths (#177083) +- remove call to RealFileName which is called in SplitDevPath + anyway +- extended/reworked interface in Tools.pm, more generic functions + those are needed for another tool needed to enable multipathing + after install, add new entries +- check for RAID1 md arrays as all others will break on reboot + (#178802), fix mdadm call (RAID1 check) +- changed name of ReadMDArrays to ReadRAID1Array which matches its + intended functionality. +- Added FIXME notes for mskibbe + +------------------------------------------------------------------- +Tue May 30 15:04:15 CEST 2006 - jplack@suse.de + +- fixed broken parsing/handling/reassembly esp. of comments in + config files +- fixed inline documentation for MD2Members + +------------------------------------------------------------------- Old: ---- perl-Bootloader-0.2.24.tar.bz2 New: ---- perl-Bootloader-0.2.25.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Bootloader.spec ++++++ --- /var/tmp/diff_new_pack.90xdxD/_old 2006-06-30 16:59:06.000000000 +0200 +++ /var/tmp/diff_new_pack.90xdxD/_new 2006-06-30 16:59:06.000000000 +0200 @@ -1,5 +1,5 @@ # -# spec file for package perl-Bootloader (Version 0.2.24) +# spec file for package perl-Bootloader (Version 0.2.25) # # Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany. # This file and all modifications and additions to the pristine @@ -11,7 +11,7 @@ # norootforbuild Name: perl-Bootloader -Version: 0.2.24 +Version: 0.2.25 Release: 1 Requires: perl >= %{perl_version} Requires: perl-gettext @@ -56,6 +56,25 @@ /sbin/update-bootloader %changelog -n perl-Bootloader +* Wed Jun 28 2006 - jplack@suse.de +- map kernel_append params to xen_append params (#188614) when + having a serial console +* Wed Jun 28 2006 - jplack@suse.de +- be nicer while handling empty paths (#177083) +- remove call to RealFileName which is called in SplitDevPath + anyway +- extended/reworked interface in Tools.pm, more generic functions + those are needed for another tool needed to enable multipathing + after install, add new entries +- check for RAID1 md arrays as all others will break on reboot + (#178802), fix mdadm call (RAID1 check) +- changed name of ReadMDArrays to ReadRAID1Array which matches its + intended functionality. +- Added FIXME notes for mskibbe +* Tue May 30 2006 - jplack@suse.de +- fixed broken parsing/handling/reassembly esp. of comments in + config files +- fixed inline documentation for MD2Members * Mon May 22 2006 - jplack@suse.de - fix broken selection list (#167390) - bump version to 0.2.24 ++++++ perl-Bootloader-0.2.24.tar.bz2 -> perl-Bootloader-0.2.25.tar.bz2 ++++++ diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/perl-Bootloader-0.2.24/lib/Bootloader/Core/GRUB.pm new/perl-Bootloader-0.2.25/lib/Bootloader/Core/GRUB.pm --- old/perl-Bootloader-0.2.24/lib/Bootloader/Core/GRUB.pm 2006-05-15 16:10:36.000000000 +0200 +++ new/perl-Bootloader-0.2.25/lib/Bootloader/Core/GRUB.pm 2006-06-30 16:02:18.000000000 +0200 @@ -244,7 +244,7 @@ C<< $unix_path = Bootloader::Core::GRUB->GrubPath2UnixPath ($grub_path, $grub_dev_prefix); >> Translates the GRUB path (eg. '(hd0,0)/grub/device.map') to UNIX path (eg. -'/boot/grub/device.map'). If the GRUB path doesn't contain the device, the one +'/boot/grub/device.map'). If the GRUB path does not contain the device, the one specified in the argument is used instead. As arguments, the function takes the GRUB path and the device to be used if not specified in the GRUB path, and returns the UNIX path (all strings). @@ -303,7 +303,7 @@ Translates the UNIX path (eg. '/boot/grub/device.map') to GRUB path (eg. '(hd0,0)/grub/device.map'). If the device (as specified in GRUB configuration files via the 'root' option) is the same as the device in the resulting path, -the resulting path doesn't contain the device. +the resulting path does not contain the device. As arguments, the function takes the UNIX path and the device as specified via 'root' option, and returns the GRUB path (all strings). @@ -321,8 +321,7 @@ return $orig_path; } - my $link_path = $self->RealFileName ($orig_path); - (my $dev, my $path) = $self->SplitDevPath ($link_path); + (my $dev, my $path) = $self->SplitDevPath ($orig_path); $dev = $self->UnixDev2GrubDev ($dev); if ($dev eq $preset_dev) @@ -670,6 +669,19 @@ my $options = join " ", @{$grub_conf_item->{"options"} || []}; my $location = $self->UnixDev2GrubDev ($grub_conf_item->{"device"}); (my $s1dev, my $s1path) = $self->SplitDevPath ("/boot/grub/stage1"); + if( $s1dev =~ m:/dev/md\d\d?: ) + { + my $mddiscs = $self->MD2Members( $s1dev ); + foreach my $mddisc (@$mddiscs) + { + if( $mddisc =~ /$s1dev..?/o ) + { + $s1dev = $mddisc; + last; + } + } + $s1dev = $grub_conf_item->{"device"}; + } $s1dev = $self->UnixDev2GrubDev ($s1dev); my $line = "setup $options $location $s1dev"; push @grub_conf, $line; @@ -724,44 +736,56 @@ } elsif ($key eq "kernel") { - if ($val =~ /^[ \t]*([^ \t]+)([ \t]+(.*))?$/) - { - $ret{"kernel"} = $self->GrubPath2UnixPath ($1, $grub_root); - $val = $3; - $val = "" if (! defined ($val)); - } - else + # split into loader and parameter, note that the regex does + # always match + $val =~ /^\s*(\S+)(?:\s+(.*))?$/; + + $ret{"kernel"} = $self->GrubPath2UnixPath ($1, $grub_root); + $val = $2 || ""; + + if ($val =~ /^(?:(.*)\s+)?root=(\S+)(?:\s+(.*))?$/) { - $ret{"kernel"} = $self->GrubPath2UnixPath ($val, $grub_root); - $val = ""; + $ret{"root"} = $2 if $2 ne ""; + $val = $self->MergeIfDefined ($1, $3); } - if ($val =~ /^((.*)[ \t])?root=([^ \t]+)([ \t](.*))?$/) + if ($val =~ /^(?:(.*)\s+)?vga=(\S+)(?:\s+(.*))?$/) { - $ret{"root"} = $3 if ($3 ne ""); - $val = $self->MergeIfDefined ($2, $5); - } - if ($val =~ /^((.*)[ \t])?vga=([^ \t]+)([ \t](.*))?$/) - { - $ret{"vga"} = $3 if ($3 ne ""); - $val = $self->MergeIfDefined ($2, $5); + $ret{"vga"} = $2 if $2 ne ""; + $val = $self->MergeIfDefined ($1, $3); } if ($val ne "") { $ret{"append"} = $val; + if ($is_xen) { + if ($val =~ /console=ttyS(\d+),(\d+)/) { + # merge console and speed into xen_append + my $console = sprintf("com%d", $1+1); + my $speed = sprintf("%s=%d", $console, $2); + if (exists $ret{"xen_append"}) { + my $xen_append = $ret{"xen_append"}; + while ($xen_append =~ + s/(.*)console=(\S+)\s*(.*)$/$1$3/o) { + my $del_console = $2; + $xen_append =~ + s/(.*)${del_console}=\d+\s*(.*)$/$1$2/g; + } + $ret{"xen_append"} = "console=$console $speed $xen_append"; + } else { + $ret{"xen_append"} = "console=$console $speed"; + } + } + } } $ret{"type"} = "image"; } elsif ($key eq "xen") { - if ($val =~ /^[ \t]*([^ \t]+)([ \t]+(.*))?$/) - { - $ret{"xen"} = $self->GrubPath2UnixPath ($1, $grub_root); - $ret{"xen_append"} = $3 if (defined ($3)); - } - else - { - $ret{"xen"} = $self->GrubPath2UnixPath ($val, $grub_root); - } + # split into loader and parameter, note that the regex does + # always match + $val =~ /^\s*(\S+)(?:\s+(.*))?$/; + + $ret{"xen"} = $self->GrubPath2UnixPath ($1, $grub_root); + $ret{"xen_append"} = $2 if defined $2; } elsif ($key eq "initrd" || $key eq "wildcard") { @@ -1039,6 +1063,26 @@ if (exists ($sectinfo{"xen"})) { @lines = @{$self->Section2XenInfo (\@lines)}; + + if (exists($sectinfo{"append"}) and + ($sectinfo{"append"} =~ /console=ttyS(\d+),(\d+)/) ) + { + # merge console and speed into xen_append + my $console = sprintf("com%d", $1+1); + my $speed = sprintf("%s=%d", $console, $2); + if (exists $sectinfo{"xen_append"}) { + my $xen_append = $sectinfo{"xen_append"}; + while ($xen_append =~ + s/(.*)console=(\S+)\s*(.*)$/$1$3/o) { + my $del_console = $2; + $xen_append =~ + s/(.*)${del_console}=\d+\s*(.*)$/$1$2/g; + } + $sectinfo{"xen_append"} = "console=$console $speed $xen_append"; + } else { + $sectinfo{"xen_append"} = "console=$console $speed"; + } + } } @lines = map { @@ -1184,8 +1228,9 @@ if ($key eq "default") { # cast $val to integer. That means that if no valid default has - # been given, weÂll take the first section as default. - my $defindex = 0+$val; + # been given, we'll take the first section as default. + no warnings "numeric"; # this is neccessary to avoid to trigger a perl bug + my $defindex = 0+ $val; $ret{"default"} = $sections[$defindex]; } elsif ($key eq "timeout" || $key eq "password") diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/perl-Bootloader-0.2.24/lib/Bootloader/Core/ZIPL.pm new/perl-Bootloader-0.2.25/lib/Bootloader/Core/ZIPL.pm --- old/perl-Bootloader-0.2.24/lib/Bootloader/Core/ZIPL.pm 2006-04-03 17:36:14.000000000 +0200 +++ new/perl-Bootloader-0.2.25/lib/Bootloader/Core/ZIPL.pm 2006-05-29 17:24:57.000000000 +0200 @@ -817,9 +817,9 @@ =cut -# (list<map<string,string>>, string comment_before) ProcessSingleMenuFileLine +# (list<map<string,string>>, list<string> comment_before) ProcessSingleMenuFileLine # (string line, string comment_before, string separator) -sub ProcessSingleMenuFileLine { +sub ProcessSingleMenuFileLine($$$) { my $self = shift; my $line = shift; my $comment_before = shift; diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/perl-Bootloader-0.2.24/lib/Bootloader/Core.pm new/perl-Bootloader-0.2.25/lib/Bootloader/Core.pm --- old/perl-Bootloader-0.2.24/lib/Bootloader/Core.pm 2006-05-10 16:01:53.000000000 +0200 +++ new/perl-Bootloader-0.2.25/lib/Bootloader/Core.pm 2006-06-28 19:30:58.000000000 +0200 @@ -20,7 +20,7 @@ C<< $device = Bootloader::Core->MP2Dev ($mountpoint); >> -C<< $members_ref = Bootloader::Core->Md2Members ($md_device); >> +C<< $members_ref = Bootloader::Core->MD2Members ($md_device); >> C<< $md_dev = Bootloader::Core->Member2MD (string $md_member); >> @@ -266,14 +266,14 @@ } =item -C<< $members_ref = Bootloader::Core->Md2Members ($md_device); >> +C<< $members_ref = Bootloader::Core->MD2Members ($md_device); >> Gets the list of partitions building an MD software RAID array. As argument it takes a MD device (string), returns a reference to a list of its members. =cut -# list<string> Md2Members (string md_device) +# list<string> MD2Members (string md_device) sub MD2Members { my $self = shift; my $md_dev = shift; @@ -361,7 +361,7 @@ $path = $self->RealFileName ($path); - my $mp = $path; + my $mp = $path || "/"; until (exists $self->{"mountpoints"}{$mp}) { unless ($mp =~ s#/[^/]*$##) { $self->l_error ("Core::SplitDevPath: Cannot get device for $path"); @@ -479,7 +479,7 @@ $ret = $ret . " " . $arg; } } - $ret = substr ($ret, 1) if (length ($ret) > 0 && substr ($ret, 0, 1) eq " "); + $ret = substr ($ret, 1) if substr ($ret, 0, 1) eq " "; return $ret; } @@ -595,7 +595,8 @@ { if ($first && $ind ne "") { - $entry->{"comment_before"} = "\n" . ($entry->{"comment_before"} || ""); + $entry->{"comment_before"} = [] unless defined $entry->{"comment_before"}; + unshift @{$entry->{"comment_before"}}, ""; } else { @@ -625,7 +626,7 @@ my @lilo_conf_lines = @{+shift}; my $equal_sep = shift; - my $comment_before = ""; + my $comment_before = []; my @ret = (); foreach my $line (@lilo_conf_lines) @@ -681,9 +682,9 @@ =cut -# (list<map<string,string>>, string comment_before) ProcessSingleMenuFileLine +# (list<map<string,string>>, list<string> comment_before) ProcessSingleMenuFileLine # (string line, string comment_before, string separator) -sub ProcessSingleMenuFileLine { +sub ProcessSingleMenuFileLine($$$) { my $self = shift; my $line = shift; my $comment_before = shift; @@ -697,7 +698,7 @@ } elsif ($line =~ /^[ \t]*#/) { - $comment_before = $comment_before . $line . "\n"; + push @{$comment_before}, $line; } elsif ($line =~ /^[ \t]*([^:\[ \t=#]+)[ \t]*(.*)$/) { @@ -705,16 +706,16 @@ my $comment_after = ""; my $key = $1; $line = $2; - if ($line =~ /^([^#]*)(#.*)$/) + if ($line =~ /^([^#]*?)(\s*#.*)$/) { $line = $1; $comment_after = $2; } - if ($equal_sep && ($line =~ /=[ \t]*(.*)/)) + if ($equal_sep && ($line =~ /=\s*(.*)/)) { $value = $1; } - elsif (!$equal_sep && ($line !~ /^[ \t]*$/)) + elsif (!$equal_sep && ($line !~ /^\s*$/)) { $value = $line; } @@ -726,7 +727,7 @@ "comment_after" => $comment_after, ); push @ret, \%val; - $comment_before = ""; + $comment_before = []; } return ( \@ret, $comment_before ); } @@ -746,32 +747,22 @@ my @parsed_lines = @{+shift}; my $equal_sep = shift; - my $date = `date 2>&1`; + use POSIX qw(strftime); + my $date = strftime "%a %b %e %H:%M:%S %Z %Y", localtime; my @ret = ($headline . $date); foreach my $l (@parsed_lines) { - my $cb = $l->{"comment_before"} || ""; - if ($cb ne "") - { - my @cb = split "\n", $cb, -1; - foreach my $line (@cb) - { - push @ret, $line; - } - } + push @ret, @{$l->{"comment_before"}} if defined $l->{"comment_before"}; - my $ca = $l->{"comment_after"} || ""; my $ind = $l->{"indent"} || ""; - my $line = $self->CreateSingleMenuFileLine ( $l->{"key"}, - defined ($l->{"value"}) ? $l->{"value"} : "", + $l->{"value"} || "", $equal_sep); - if ($ca ne "") - { - $line = "$line $ca"; - } - $line = $ind . $line; + + $line = $l->{"indent"} . $line if defined $l->{"indent"}; + $line .= $l->{"comment_after"} if defined $l->{"comment_after"}; + push @ret, $line; } return \@ret; @@ -965,13 +956,14 @@ my $orig_name_comment="###Don't change this comment - YaST2 identifier: Original name: "; -# string Comment2OriginalName (string comment) -sub Comment2OriginalName { +# string Comment2OriginalName (list<string> comment) +sub Comment2OriginalName($) { my $self = shift; - my $comment = shift || ""; - - return $1 - if $comment =~ m/${orig_name_comment}([a-zA-Z0-9]+)###/o; + my $comment_lines_ref = shift || []; + foreach (@{$comment_lines_ref}) { + return $1 + if m/${orig_name_comment}([a-zA-Z0-9]+)###/o; + } return ""; } @@ -995,12 +987,11 @@ $line_ref->{"value"} = $name; if (defined ($original_name) && $original_name ne "") { - my $cb = $line_ref->{"comment_before"} || ""; - my @cb_lines = grep { + my @comment_before = grep { ! m/^${orig_name_comment}/o; - } split( /\n/, $cb ); - push @cb_lines, "${orig_name_comment}${original_name}###"; - $line_ref->{"comment_before"} = join "\n", @cb_lines; + } @{$line_ref->{"comment_before"} || []}; + push @comment_before, "${orig_name_comment}${original_name}###"; + $line_ref->{"comment_before"} = \@comment_before; } return $line_ref; } @@ -1784,10 +1775,7 @@ my $self = shift; my $filename = shift; - if ($filename eq "") - { - return $filename; - } + return "" unless $filename; my $ret = ""; if ($self->{"resolve_symlinks"}) diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/perl-Bootloader-0.2.24/lib/Bootloader/Library.pm new/perl-Bootloader-0.2.25/lib/Bootloader/Library.pm --- old/perl-Bootloader-0.2.24/lib/Bootloader/Library.pm 2006-04-03 17:36:14.000000000 +0200 +++ new/perl-Bootloader-0.2.25/lib/Bootloader/Library.pm 2006-06-02 14:38:57.000000000 +0200 @@ -234,6 +234,10 @@ =item C<< $status = Bootloader::Library->DefineMDArrays (\%md_arrays); >> +This interface is broken by design and its use is deprecated!! +We only need information about mirrored devices (RAID1) and only GRUB uses +that hack. + Defines the information about MD RAID arrays (what array is built by what disks). As parameter, it takes a reference to a map of all MD devices, where diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/perl-Bootloader-0.2.24/lib/Bootloader/Tools.pm new/perl-Bootloader-0.2.25/lib/Bootloader/Tools.pm --- old/perl-Bootloader-0.2.24/lib/Bootloader/Tools.pm 2006-05-16 13:05:09.000000000 +0200 +++ new/perl-Bootloader-0.2.25/lib/Bootloader/Tools.pm 2006-06-12 17:19:01.000000000 +0200 @@ -20,7 +20,7 @@ C<< $part_ref = Bootloader::Tools::ReadPartitions (); >> -C<< $md_ref = Bootloader::Tools::ReadMDArrays (); >> +C<< $md_ref = Bootloader::Tools::ReadRAID1Arrays (); >> C<< $loader = Bootloader::Tools::GetBootloader (); >> @@ -40,6 +40,17 @@ C<< Bootloader::Tools::GetDefaultInitrd (); >> +C<< Bootloader::Tools::GetGlobals(); >> + +C<< Bootloader::Tools::SetGlobals(@params); >> + +C<< Bootloader::Tools::GetSectionList(@selectors); >> + +C<< Bootloader::Tools::GetSection($name); >> + +C<< Bootloader::Tools::AddSection($name, @params); >> + +C<< Bootloader::Tools::RemoveSection($name); >> =head1 DESCRIPTION @@ -53,9 +64,12 @@ use strict; use base 'Exporter'; -our @EXPORT = qw(InitLibrary AddSection CountImageSections CountSections - RemoveImageSections RemoveSections GetDefaultImage GetDefaultInitrd - UpdateBootloader); +our @EXPORT = qw(InitLibrary CountImageSections CountSections + RemoveImageSections RemoveSections GetDefaultImage + GetDefaultInitrd UpdateBootloader + GetGlobals SetGlobals + GetSectionList GetSection AddSection RemoveSection +); use Bootloader::Library; use Bootloader::Core; @@ -195,42 +209,45 @@ } =item -C<< $md_ref = Bootloader::Tools::ReadMDArrays (); >> +C<< $md_ref = Bootloader::Tools::ReadRAID1Arrays (); >> -reads the information about disk MD RAID arrays. This data is needed +reads the information about disk MD RAID1 arrays. This data is needed to initialize the bootloader library properly. =cut # FIXME: this has to be read through yast::storage -sub ReadMDArrays { - my $index = 0; +sub ReadRAID1Arrays { my %mapping = (); - while ($index < 32) + # use '/sbin/mdadm --detail --verbose --scan' + # Assuming an output format like: + # + # ARRAY /dev/md1 level=raid5 num-devices=3 UUID=12cdd4f2:0f932f25:adb61ba6:1b34cb24 + # devices=/dev/sda3,/dev/sda4,/dev/sdb3 + # ARRAY /dev/md0 level=raid1 num-devices=2 UUID=af4346f4:eba443d2:c493326f:36a37aad + # devices=/dev/sda1,/dev/sdb1 + # + + my @members = (); + open (MD, "/sbin/mdadm --detail --verbose --scan") || + die ("Failed getting information about MD arrays"); + while (my $line = <MD>) { - my @members = (); - open (MD, "/sbin/mdadm -Q --detail /dev/md$index 2>/dev/null |") || - die ("Failed getting information about MD arrays"); - while (my $line = <MD>) - { - chomp ($line); - if ($line =~ /[-0-9]+[ \t]+[-0-9]+[ \t]+[-0-9]+[ \t]+([-0-9]+)[ \t]+.*[ \t]+([^ \t]+)$/) - { - my $dev = $2; - my $raid_dev = $1; - if ($raid_dev =~ /^[0-9]+$/ && $raid_dev >= 0) - { - push @members, $dev; - } - } - } - close (MD); - if (scalar (@members)) - { - $mapping{"/dev/md$index"} = \@members; - } - $index = $index + 1; + chomp ($line); + + if ($line =~ /ARRAY (\S+) level=(\w+) num-devices=(\d+)) + { + my ($array, $level, $num_devices) = ($1, $2, $3); + } + elsif ($level == "raid1" and $line =~ /devices=(\S+)) + { + # we could test $num_device against number of found devices to + # detect degradedmode but that does not matter here (really?) + + $mapping{$array}= split(/,/, $1) + } } + close( <MD> ); return \%mapping; } @@ -264,7 +281,7 @@ $lib_ref = Bootloader::Library->new (); my $mp = ReadMountPoints (); my $part = ReadPartitions (); - my $md = ReadMDArrays (); + my $md = ReadRAID1Arrays (); $lib_ref->Initialize (GetBootloader ()); $lib_ref->DefineMountPoints ($mp); @@ -304,71 +321,6 @@ } -# FIXME: Add documentation -sub AddSection { - my %option = @_; - - return unless exists $option{"name"}; - return unless exists $option{"type"}; - - my $default = delete $option{"default"} || 0; - - my $mp = $lib_ref->GetMountPoints (); - my @sections = @{$lib_ref->GetSections ()}; - my %new = ( - "root" => $mp->{"/"} || "/dev/null", - ); - my %def = (); - foreach my $s (@sections) - { - if (defined ($s->{"initial"}) && $s->{"initial"}) - { - %def = %{$s}; - last; - } - } - - while ((my $k, my $v) = each (%def)) - { - if (substr ($k, 0, 2) ne "__" && $k ne "original_name" - && $k ne "initrd") - { - $new{$k} = $v; - } - } - - if (exists $option{"image"}) { - if (exists $new{"kernel"}) { - $new{"kernel"} = delete $option{"image"}; - } - else { - $new{"image"} = delete $option{"image"}; - } - } - - foreach (keys %option) { - $new{"$_"} = $option{"$_"}; - } - - $new{"__modified"} = 1; - push @sections, \%new; - - $lib_ref->SetSections (\@sections); - - if ($default) { - my $glob_ref = $lib_ref->GetGlobalSettings (); - $glob_ref->{"default"} = $option{"name"}; - $glob_ref->{"__modified"} = 1; - $lib_ref->SetGlobalSettings ($glob_ref); - } - - $lib_ref->WriteSettings (1); - $lib_ref->UpdateBootloader (1); # avoid initialization but write config to - # the right place - DumpLog (); -} - - # internal: does section match with set of tags sub match_section { my ($sect_ref, $opt_ref,) = @_; @@ -429,19 +381,14 @@ } -# FIXME: add documentation -sub CountSections { - my %option = @_; - my $count = 0; +=item +C<< Bootloader::Tools::CountSections (@selections); >> - normalize_options(\%option); - my @sections = @{$lib_ref->GetSections ()}; - foreach (@sections) { - $count++ if match_section($_, \%option); - } +# FIXME: add documentation +=cut - DumpLog (); - return $count; +sub CountSections { + return scalar GetSectionList(@_); } @@ -607,10 +554,186 @@ =cut sub GetDefaultInitrd { - return GetDefaultSection()->{"initrd"}; } +=item +C<< Bootloader::Tools::GetGlobals(); >> +=cut + +sub GetGlobals() { + return $lib_ref->GetGlobals(); +} + + +=item +C<< Bootloader::Tools::SetGlobals(@params); >> + +# FIXME: Add documentation +=cut +sub SetGlobals { + my %option = @_; + my $glob_ref = $lib_ref->GetGlobalSettings(); + + # merge with current, undef values delete options + foreach (keys %option) { + if (defined $option{$_}) { + $glob_ref->{$_} = $option{$_}; + } else { + delete $glob_ref->{$_}; + } + } + $glob_ref->{"__modified"} = 1; + $lib_ref->SetGlobalSettings ($glob_ref); + $lib_ref->WriteSettings (1); + $lib_ref->UpdateBootloader (1); # avoid initialization but write config to + # the right place + DumpLog (); +} + + +=item +C<< Bootloader::Tools::GetSectionList(@selectors); >> + +# FIXME: Add documentation +=cut + +sub GetSectionsList { + my %option = @_; + + normalize_options(\%option); + my @sections = @{$lib_ref->GetSections ()}; + my @section_names = map { + $_->{"name"} if match_section($_, \%option); + } @sections; + + DumpLog (); + return @section_names; +} + + +=item +C<< Bootloader::Tools::GetSection($name); >> + +# FIXME: Add documentation +=cut + +sub GetSection($) { + my $name = shift or return undef; + + foreach (@{$lib_ref->GetSections ()}) { + return $_ if $_->{"name"} eq $name; + } + return undef; +} + + +=item +C<< Bootloader::Tools::AddSection($name, @params); >> + +# FIXME: Add documentation +=cut + +sub AddSection { + my $name = shift; + my %option = @_; + + return unless defined $name; + return unless exists $option{"type"}; + + my $default = delete $option{"default"} || 0; + + my $mp = $lib_ref->GetMountPoints (); + my @sections = @{$lib_ref->GetSections ()}; + my %new = ( + "root" => $mp->{"/"} || "/dev/null", + ); + my %def = (); + foreach my $s (@sections) + { + if (defined ($s->{"initial"}) && $s->{"initial"}) + { + %def = %{$s}; + last; + } + } + + while ((my $k, my $v) = each (%def)) + { + if (substr ($k, 0, 2) ne "__" && $k ne "original_name" + && $k ne "initrd") + { + $new{$k} = $v; + } + } + + if (exists $option{"image"}) { + if (exists $new{"kernel"}) { + $new{"kernel"} = delete $option{"image"}; + } + else { + $new{"image"} = delete $option{"image"}; + } + } + + foreach (keys %option) { + $new{"$_"} = $option{"$_"}; + } + + $new{"__modified"} = 1; + push @sections, \%new; + + $lib_ref->SetSections (\@sections); + + if ($default) { + my $glob_ref = $lib_ref->GetGlobalSettings (); + $glob_ref->{"default"} = $option{"name"}; + $glob_ref->{"__modified"} = 1; + $lib_ref->SetGlobalSettings ($glob_ref); + } + + $lib_ref->WriteSettings (1); + $lib_ref->UpdateBootloader (1); # avoid initialization but write config to + # the right place + DumpLog (); +} + + +=item +C<< Bootloader::Tools::RemoveSection($name); >> + +=cut + +sub RemoveSection { + my $name = shift or return; + + my @sections = @{$lib_ref->GetSections()}; + my $glob_ref = $lib_ref->GetGlobalSettings(); + my $default_section = $glob_ref->{"default"} || ""; + my $default_removed = 0; + + normalize_options(\%option); + @sections = grep { + my $match = $_->{"name"} eq $name; + $default_removed = 1 + if $match and $default_section eq $_->{"name"}; + !$match; + } @sections; + $lib_ref->SetSections (\@sections); + if ($default_removed) { + $glob_ref->{"default"} = $sections[0]{"name"}; + } + $glob_ref->{"__modified"} = 1; # needed because of GRUB - index of default + # may change even if not deleted + $lib_ref->SetGlobalSettings ($glob_ref); + $lib_ref->WriteSettings (1); + $lib_ref->UpdateBootloader (1); # avoid initialization but write config to + # the right place + DumpLog (); +} + + + 1; ++++++ update-bootloader ++++++ --- perl-Bootloader/update-bootloader 2006-05-22 18:20:07.000000000 +0200 +++ perl-Bootloader/update-bootloader 2006-06-30 16:07:30.000000000 +0200 @@ -247,12 +247,11 @@ pod2usage("There are already sections with image '$opt_image'"); } } else { - push @params, name => $opt_name; push @params, default => $opt_default; push @params, xen => $opt_xen_kernel if $type eq "xen"; push @params, initrd => $opt_initrd if $opt_initrd; - AddSection(@params); + AddSection($opt_name, @params); } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-commit-unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit-help@opensuse.org