Class: Bootloader::Sysconfig

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/bootloader/sysconfig.rb

Overview

Represents sysconfig file for bootloader usually located in /etc/sysconfig/bootloader

Constant Summary collapse

AGENT_PATH =
Yast::Path.new(".sysconfig.bootloader")
ATTR_VALUE_MAPPING =
{
  bootloader:   "LOADER_TYPE",
  secure_boot:  "SECURE_BOOT",
  trusted_boot: "TRUSTED_BOOT",
  update_nvram: "UPDATE_NVRAM"
}.freeze
PROPOSED_COMMENTS =
{
  bootloader:   "\n" \
                "## Path:\tSystem/Bootloader\n" \
                "## Description:\tBootloader configuration\n" \
                "## Type:\tlist(grub,grub2,grub2-efi,none)\n" \
                "## Default:\tgrub2\n" \
                "#\n" \
                "# Type of bootloader in use.\n" \
                "# For making the change effect run bootloader configuration tool\n" \
                "# and configure newly selected bootloader\n" \
                "#\n" \
                "#\n",

  secure_boot:  "\n" \
                "## Path:\tSystem/Bootloader\n" \
                "## Description:\tBootloader configuration\n" \
                "## Type:\tyesno\n" \
                "## Default:\t\"no\"\n" \
                "#\n" \
                "# Enable Secure Boot support\n" \
                "# Only available on UEFI systems and IBM z15+.\n" \
                "#\n" \
                "#\n",

  trusted_boot: "\n" \
                "## Path:\tSystem/Bootloader\n" \
                "## Description:\tBootloader configuration\n" \
                "## Type:\tyesno\n" \
                "## Default:\t\"no\"\n" \
                "#\n" \
                "# Enable Trusted Boot support\n" \
                "# Only available on hardware with a Trusted Platform Module.\n" \
                "#\n",

  update_nvram: "\n" \
                "## Path:\tSystem/Bootloader\n" \
                "## Description:\tBootloader configuration\n" \
                "## Type:\tyesno\n" \
                "## Default:\t\"yes\"\n" \
                "#\n" \
                "# Update nvram boot settings (UEFI, OF)\n" \
                "# Unset to preserve specific settings or workaround firmware issues.\n" \
                "#\n"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bootloader: nil, secure_boot: false, trusted_boot: false, update_nvram: true) ⇒ Sysconfig

Returns a new instance of Sysconfig.


29
30
31
32
33
34
35
# File 'src/lib/bootloader/sysconfig.rb', line 29

def initialize(bootloader: nil, secure_boot: false, trusted_boot: false, update_nvram: true)
  @sys_agent = AGENT_PATH
  @bootloader = bootloader
  @secure_boot = secure_boot
  @trusted_boot = trusted_boot
  @update_nvram = update_nvram
end

Instance Attribute Details

#bootloaderObject

specifies bootloader in sysconfig


21
22
23
# File 'src/lib/bootloader/sysconfig.rb', line 21

def bootloader
  @bootloader
end

#secure_bootBoolean

Returns if secure boot should be used.

Returns:

  • (Boolean)

    if secure boot should be used


23
24
25
# File 'src/lib/bootloader/sysconfig.rb', line 23

def secure_boot
  @secure_boot
end

#trusted_bootBoolean

Returns if trusted boot should be used.

Returns:

  • (Boolean)

    if trusted boot should be used


25
26
27
# File 'src/lib/bootloader/sysconfig.rb', line 25

def trusted_boot
  @trusted_boot
end

#update_nvramBoolean

Returns if nvram should be updated.

Returns:

  • (Boolean)

    if nvram should be updated


27
28
29
# File 'src/lib/bootloader/sysconfig.rb', line 27

def update_nvram
  @update_nvram
end

Class Method Details

.from_systemObject


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

def self.from_system
  bootloader = Yast::SCR.Read(AGENT_PATH + "LOADER_TYPE")
  # propose secure boot always to true (bnc#872054), otherwise respect user choice
  # but only on architectures that support it
  secure_boot = Yast::SCR.Read(AGENT_PATH + "SECURE_BOOT") != "no"

  trusted_boot = Yast::SCR.Read(AGENT_PATH + "TRUSTED_BOOT") == "yes"

  update_nvram = Yast::SCR.Read(AGENT_PATH + "UPDATE_NVRAM") != "no"

  new(bootloader: bootloader, secure_boot: secure_boot, trusted_boot: trusted_boot,
    update_nvram: update_nvram)
end

Instance Method Details

#pre_writeObject

Specialized write before rpm install, that do not have switched SCR and work on blank system


53
54
55
56
57
58
# File 'src/lib/bootloader/sysconfig.rb', line 53

def pre_write
  ensure_file_exists_in_target
  temporary_target_agent do
    write
  end
end

#writeObject


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'src/lib/bootloader/sysconfig.rb', line 105

def write
  log.info "Saving /etc/sysconfig/bootloader for #{bootloader}"

  write_option(:bootloader, bootloader)

  sb = secure_boot ? "yes" : "no"
  write_option(:secure_boot, sb)

  tb = trusted_boot ? "yes" : "no"
  write_option(:trusted_boot, tb)

  un = update_nvram ? "yes" : "no"
  write_option(:update_nvram, un)

  # flush write
  Yast::SCR.Write(sys_agent, nil)

  nil
end