Class: Bootloader::BootloaderFactory

Inherits:
Object
  • Object
show all
Extended by:
Yast::Logger
Defined in:
src/lib/bootloader/bootloader_factory.rb

Overview

Factory to get instance of bootloader

Constant Summary collapse

SUPPORTED_BOOTLOADERS =
[
  "none", # allows user to manage bootloader itself
  "grub2",
  "grub2-efi"
].freeze
DEFAULT_KEYWORD =

Keyword used in autoyast for default bootloader used for given system.

"default"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.currentObject


38
39
40
# File 'src/lib/bootloader/bootloader_factory.rb', line 38

def current
  @current ||= (system || proposed)
end

Class Method Details

.bootloader_by_name(name) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'src/lib/bootloader/bootloader_factory.rb', line 71

def bootloader_by_name(name)
  # needed to be able to store settings when moving between bootloaders
  @cached_bootloaders ||= {}
  case name
  when "grub2"
    @cached_bootloaders["grub2"] ||= Grub2.new
  when "grub2-efi"
    @cached_bootloaders["grub2-efi"] ||= Grub2EFI.new
  when "none"
    @cached_bootloaders["none"] ||= NoneBootloader.new
  when String
    raise UnsupportedBootloader, name
  else
    log.error "Factory receive nil name"

    nil # in other cases it means that read failed
  end
end

.clear_cacheObject


46
47
48
# File 'src/lib/bootloader/bootloader_factory.rb', line 46

def clear_cache
  @cached_bootloaders = nil
end

.current_name=(name) ⇒ Object


42
43
44
# File 'src/lib/bootloader/bootloader_factory.rb', line 42

def current_name=(name)
  @current = bootloader_by_name(name)
end

.proposedObject


30
31
32
# File 'src/lib/bootloader/bootloader_factory.rb', line 30

def proposed
  bootloader_by_name(proposed_name)
end

.supported_namesObject


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'src/lib/bootloader/bootloader_factory.rb', line 50

def supported_names
  if Yast::Mode.config
    # default means bootloader use what it think is the best
    return BootloaderFactory::SUPPORTED_BOOTLOADERS + [DEFAULT_KEYWORD]
  end

  begin
    system_bl = system.name
  # rescue exception if system one is not support
  rescue StandardError
    system_bl = nil
  end
  ret = system_bl ? [system.name] : [] # use current as first
  # grub2 everywhere except aarch64 or riscv64
  ret << "grub2" unless Systeminfo.efi_mandatory?
  ret << "grub2-efi" if Systeminfo.efi_supported?
  ret << "none"
  # avoid double entry for selected one
  ret.uniq
end

.systemObject


34
35
36
# File 'src/lib/bootloader/bootloader_factory.rb', line 34

def system
  bootloader_by_name(Sysconfig.from_system.bootloader)
end