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



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

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

Class Method Details

.bootloader_by_name(name) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



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

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



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

def clear_cache
  @cached_bootloaders = nil
end

.current_name=(name) ⇒ Object



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

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



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

def supported_names
  if Yast::Mode.config
    # default means bootloader use what it think is the best
    result = BootloaderFactory::SUPPORTED_BOOTLOADERS.clone
    if Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
        Yast::Arch.x86_64 # only x86_64 is supported
      result << SYSTEMDBOOT
    end
    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?
  if Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
      Yast::Arch.x86_64 # only x86_64 is supported
    ret << SYSTEMDBOOT
  end
  ret << "none"
  # avoid double entry for selected one
  ret.uniq
end

.systemObject



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

def system
  bootloader_by_name(Sysconfig.from_system.bootloader)
end