Class: Bootloader::Sections

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/bootloader/sections.rb

Overview

Represents available sections and handling of default boot entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grub_cfg = nil) ⇒ Sections

or nil if not available yet

Parameters:

  • grub_cfg (CFA::Grub2::GrubCfg, nil) (defaults to: nil)
    • loaded parsed grub cfg tree


23
24
25
26
27
# File 'src/lib/bootloader/sections.rb', line 23

def initialize(grub_cfg = nil)
  @data = grub_cfg ? grub_cfg.boot_entries : []
  @all = @data.map { |e| e[:title] }
  @default = grub_cfg ? read_default : ""
end

Instance Attribute Details

#allArray<String> (readonly)

Returns list of all available boot titles if initialized with grub_cfg otherwise it is empty array.

Returns:

  • (Array<String>)

    list of all available boot titles if initialized with grub_cfg otherwise it is empty array



15
16
17
# File 'src/lib/bootloader/sections.rb', line 15

def all
  @all
end

#defaultString

Returns title of default boot section. It is not full path, so it should be reasonable short.

Returns:

  • (String)

    title of default boot section. It is not full path, so it should be reasonable short



19
20
21
# File 'src/lib/bootloader/sections.rb', line 19

def default
  @default
end

Instance Method Details

#writeObject

writes default to system making it persistent



45
46
47
48
49
# File 'src/lib/bootloader/sections.rb', line 45

def write
  return if default.empty?

  Yast::Execute.on_target("/usr/sbin/grub2-set-default", title_to_path(default))
end