Class: Bootloader::Sections
- Inherits:
-
Object
- Object
- Bootloader::Sections
- Includes:
- Yast::Logger
- Defined in:
- src/lib/bootloader/sections.rb
Overview
Represents available sections and handling of default boot entry
Instance Attribute Summary (collapse)
-
- (Object) all
readonly
Returns the value of attribute all.
Instance Method Summary (collapse)
-
- (String) default
Name of default section.
-
- (Object) default=(value)
Sets default section internally.
-
- (Sections) initialize(grub_cfg = nil)
constructor
or nil if not available yet.
-
- (Object) write
writes default to system making it persistent.
Constructor Details
- (Sections) initialize(grub_cfg = nil)
or nil if not available yet
15 16 17 |
# File 'src/lib/bootloader/sections.rb', line 15 def initialize(grub_cfg = nil) @all = grub_cfg ? grub_cfg.sections : [] end |
Instance Attribute Details
- (Object) all (readonly)
Returns the value of attribute all
11 12 13 |
# File 'src/lib/bootloader/sections.rb', line 11 def all @all end |
Instance Method Details
- (String) default
Returns name of default section
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'src/lib/bootloader/sections.rb', line 20 def default return @default if @default return @default = "" if Yast::Stage.initial # Execute.on_target can return nil if call failed. It shows users error popup, but bootloader # can continue with empty default section saved = Yast::Execute.on_target("/usr/bin/grub2-editenv", "list", stdout: :capture) || "" saved_line = saved.lines.grep(/saved_entry=/).first @default = saved_line ? saved_line[/saved_entry=(\S*)/, 1] : all.first end |
- (Object) default=(value)
Note:
to write it to system use #write later
Sets default section internally
35 36 37 38 39 40 41 42 |
# File 'src/lib/bootloader/sections.rb', line 35 def default=(value) log.info "set new default to '#{value.inspect}'" # empty value mean no default specified raise "Unknown value #{value.inspect}" if !all.include?(value) && !value.empty? @default = value end |
- (Object) write
writes default to system making it persistent
45 46 47 48 |
# File 'src/lib/bootloader/sections.rb', line 45 def write return if default.empty? Yast::Execute.on_target("/usr/sbin/grub2-set-default", default) end |