Class: Bootloader::BootloaderBase

Inherits:
Object
  • Object
show all
Defined in:
src/lib/bootloader/bootloader_base.rb

Overview

Represents base for all kinds of bootloaders

Direct Known Subclasses

Grub2Base, NoneBootloader, SystemdBoot

Instance Method Summary collapse

Constructor Details

#initializeBootloaderBase

Returns a new instance of BootloaderBase.



14
15
16
17
18
# File 'src/lib/bootloader/bootloader_base.rb', line 14

def initialize
  @read = false
  @proposed = false
  @initial_sysconfig = Sysconfig.from_system
end

Instance Method Details

#merge(other) ⇒ Object

merges other bootloader configuration into this one. It have to be same bootloader type.



93
94
95
96
97
98
# File 'src/lib/bootloader/bootloader_base.rb', line 93

def merge(other)
  raise "Invalid merge argument #{other.name} for #{name}" if name != other.name

  @read ||= other.read?
  @proposed ||= other.proposed? # rubocop:disable Naming/MemoizedInstanceVariableName
end

#packagesArray<String>

Returns packages required to configure given bootloader.

Returns:

  • (Array<String>)

    packages required to configure given bootloader



75
76
77
78
79
80
81
82
# File 'src/lib/bootloader/bootloader_base.rb', line 75

def packages
  res = []

  # added kexec-tools fate#303395
  res << "kexec-tools" if include_kexec_tools_package?

  res
end

#prepareBoolean

Prepares the system to (before write the configuration)

Writes the new sysconfig and, when the Mode.normal is set, tries to install the required packages. If user decides to cancel the installation, it restores the previous sysconfig.

Returns:

  • (Boolean)

    true whether the system could be prepared as expected; false when user cancel the installation of needed packages



27
28
29
30
31
32
33
34
35
36
# File 'src/lib/bootloader/bootloader_base.rb', line 27

def prepare
  write_sysconfig

  return true unless Yast::Mode.normal
  return true if Yast::Package.InstallAll(packages)

  restore_initial_sysconfig

  false
end

#proposeObject

Proposes new configuration



55
56
57
# File 'src/lib/bootloader/bootloader_base.rb', line 55

def propose
  @proposed = true
end

#proposed?Boolean

Returns true if configuration is already proposed.

Returns:

  • (Boolean)

    true if configuration is already proposed



70
71
72
# File 'src/lib/bootloader/bootloader_base.rb', line 70

def proposed?
  @proposed
end

#readObject

reads configuration from target disk



50
51
52
# File 'src/lib/bootloader/bootloader_base.rb', line 50

def read
  @read = true
end

#read?Boolean

Returns true if configuration is already read.

Returns:

  • (Boolean)

    true if configuration is already read



65
66
67
# File 'src/lib/bootloader/bootloader_base.rb', line 65

def read?
  @read
end

#summaryArray<String>

Returns description for proposal summary page for given bootloader.

Returns:

  • (Array<String>)

    description for proposal summary page for given bootloader



60
61
62
# File 'src/lib/bootloader/bootloader_base.rb', line 60

def summary
  []
end

#write(etc_only: false) ⇒ Object

writes configuration to target disk

Parameters:

  • etc_only (Boolean) (defaults to: false)

    true on transactional systems because /boot is read-only there



41
42
43
44
45
46
47
# File 'src/lib/bootloader/bootloader_base.rb', line 41

def write(etc_only: false)
  return if etc_only

  # reset eventl. already installed systemd bootloader
  systemd_boot = BootloaderFactory.bootloader_by_name("systemd-boot")
  systemd_boot&.delete
end

#write_sysconfig(prewrite: false) ⇒ Object

done in common write but also in installation pre write as kernel update need it

Parameters:

  • prewrite (Boolean) (defaults to: false)

    true only in installation when scr is not yet switched



86
87
88
89
# File 'src/lib/bootloader/bootloader_base.rb', line 86

def write_sysconfig(prewrite: false)
  sysconfig = Bootloader::Sysconfig.new(bootloader: name)
  prewrite ? sysconfig.pre_write : sysconfig.write
end