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"
SYSTEMDBOOT =
"systemd-boot"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.currentObject



44
45
46
# File 'src/lib/bootloader/bootloader_factory.rb', line 44

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

Class Method Details

.bootloader_by_name(name) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'src/lib/bootloader/bootloader_factory.rb', line 82

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 "systemd-boot"
    @cached_bootloaders["systemd-boot"] ||= SystemdBoot.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



52
53
54
# File 'src/lib/bootloader/bootloader_factory.rb', line 52

def clear_cache
  @cached_bootloaders = nil
end

.current_name=(name) ⇒ Object



48
49
50
# File 'src/lib/bootloader/bootloader_factory.rb', line 48

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

.proposedObject



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

def proposed
  bootloader_by_name(proposed_name)
end

.supported_namesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'src/lib/bootloader/bootloader_factory.rb', line 56

def supported_names
  if Yast::Mode.config
    # default means bootloader use what it think is the best
    result = BootloaderFactory::SUPPORTED_BOOTLOADERS.clone
    result << SYSTEMDBOOT if use_systemd_boot?
    result << DEFAULT_KEYWORD
    return result
  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 << SYSTEMDBOOT if use_systemd_boot?
  ret << "none"
  # avoid double entry for selected one
  ret.uniq
end

.systemObject



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

def system
  sysconfig_name = Sysconfig.from_system.bootloader
  return nil unless sysconfig_name

  bootloader_by_name(sysconfig_name)
end