• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-bootloader / 8568600428

05 Apr 2024 10:45AM UTC coverage: 87.915% (-0.2%) from 88.092%
8568600428

Pull #698

github

jreidinger
Add note for translators
Pull Request #698: Secure boot update sp6

2990 of 3401 relevant lines covered (87.92%)

13.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.68
/src/lib/bootloader/bootloader_factory.rb
1
# frozen_string_literal: true
2

3
require "yast"
1✔
4
require "bootloader/sysconfig"
1✔
5
require "bootloader/none_bootloader"
1✔
6
require "bootloader/grub2"
1✔
7
require "bootloader/grub2efi"
1✔
8
require "bootloader/exceptions"
1✔
9

10
Yast.import "Arch"
1✔
11
Yast.import "Mode"
1✔
12

13
module Bootloader
1✔
14
  # Factory to get instance of bootloader
15
  class BootloaderFactory
1✔
16
    SUPPORTED_BOOTLOADERS = [
1✔
17
      "none", # allows user to manage bootloader itself
18
      "grub2",
19
      "grub2-efi"
20
    ].freeze
21

22
    # Keyword used in autoyast for default bootloader used for given system.
23
    DEFAULT_KEYWORD = "default"
1✔
24

25
    class << self
1✔
26
      include Yast::Logger
1✔
27

28
      attr_writer :current
1✔
29

30
      def proposed
1✔
31
        bootloader_by_name(proposed_name)
×
32
      end
33

34
      def system
1✔
35
        sysconfig_name = Sysconfig.from_system.bootloader
16✔
36
        return nil unless sysconfig_name
16✔
37

38
        bootloader_by_name(sysconfig_name)
2✔
39
      end
40

41
      def current
1✔
42
        @current ||= (system || proposed)
429✔
43
      end
44

45
      def current_name=(name)
1✔
46
        @current = bootloader_by_name(name)
200✔
47
      end
48

49
      def clear_cache
1✔
50
        @cached_bootloaders = nil
178✔
51
      end
52

53
      def supported_names
1✔
54
        if Yast::Mode.config
13✔
55
          # default means bootloader use what it think is the best
56
          return BootloaderFactory::SUPPORTED_BOOTLOADERS + [DEFAULT_KEYWORD]
×
57
        end
58

59
        begin
13✔
60
          system_bl = system.name
13✔
61
        # rescue exception if system one is not support
62
        rescue StandardError
63
          system_bl = nil
13✔
64
        end
65
        ret = system_bl ? [system.name] : [] # use current as first
13✔
66
        # grub2 everywhere except aarch64 or riscv64
67
        ret << "grub2" unless Systeminfo.efi_mandatory?
13✔
68
        ret << "grub2-efi" if Systeminfo.efi_supported?
13✔
69
        ret << "none"
13✔
70
        # avoid double entry for selected one
71
        ret.uniq
13✔
72
      end
73

74
      def bootloader_by_name(name)
1✔
75
        # needed to be able to store settings when moving between bootloaders
76
        @cached_bootloaders ||= {}
204✔
77
        case name
204✔
78
        when "grub2"
79
          @cached_bootloaders["grub2"] ||= Grub2.new
184✔
80
        when "grub2-efi"
81
          @cached_bootloaders["grub2-efi"] ||= Grub2EFI.new
12✔
82
        when "none"
83
          @cached_bootloaders["none"] ||= NoneBootloader.new
6✔
84
        when String
85
          raise UnsupportedBootloader, name
1✔
86
        else
87
          log.error "Factory receive nil name"
1✔
88

89
          nil # in other cases it means that read failed
90
        end
91
      end
92

93
    private
1✔
94

95
      def boot_efi?
1✔
96
        Systeminfo.efi?
×
97
      end
98

99
      def proposed_name
1✔
100
        return "grub2-efi" if Systeminfo.efi_mandatory?
×
101

102
        return "grub2-efi" if (Yast::Arch.x86_64 || Yast::Arch.i386) && boot_efi?
×
103

104
        "grub2" # grub2 works(c) everywhere
×
105
      end
106
    end
107
  end
108
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc