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

- (Sections) initialize(grub_cfg = nil)

or nil if not available yet

Parameters:

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



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

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

Instance Attribute Details

- (Array<String>) all (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



13
14
15
# File 'src/lib/bootloader/sections.rb', line 13

def all
  @all
end

Instance Method Details

- (String) default

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



24
25
26
27
28
29
30
31
32
# File 'src/lib/bootloader/sections.rb', line 24

def default
  return @default if @default

  return @default = "" if Yast::Stage.initial

  default_path = read_default_path

  @default = default_path ? path_to_title(default_path) : all.first || ""
end

- (Object) default=(value)

Note:

to write it to system use #write later

Sets default section internally.

Parameters:

  • new (String)

    boot title to boot



37
38
39
40
41
42
43
44
45
46
47
# File 'src/lib/bootloader/sections.rb', line 37

def default=(value)
  log.info "set new default to '#{value.inspect}'"

  # empty value mean no default specified
  if !all.empty? && !all.include?(value) && !value.empty?
    log.warn "Invalid value #{value} trying to set as default. Fallback to default"
    value = ""
  end

  @default = value
end

- (Object) write

writes default to system making it persistent



50
51
52
53
54
# File 'src/lib/bootloader/sections.rb', line 50

def write
  return if default.empty?

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