Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Nov 8, 2024
1 parent b74d95a commit 36e4ed4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 83 deletions.
25 changes: 13 additions & 12 deletions src/lib/bootloader/bls_sections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def default=(value)
# writes default to system making it persistent
def write
return if @default.empty?
write_default()

write_default
end

def read
Expand All @@ -51,42 +52,42 @@ def read
end

private
OS_RELEASE_PATH = "/etc/os-release".freeze

OS_RELEASE_PATH = "/etc/os-release"

def grubenv_path
str = Yast::Misc.CustomSysconfigRead("ID_LIKE", "openSUSE",
OS_RELEASE_PATH)
os = str.split(" ").first
return File.join("/boot/efi/EFI/", os, "/grubenv")
OS_RELEASE_PATH)
os = str.split.first
File.join("/boot/efi/EFI/", os, "/grubenv")
end

# @return [String] return default boot as string or "" if not set
# or something goes wrong
def read_default
Yast::Misc.CustomSysconfigRead("default", "",
grubenv_path)
grubenv_path)
end

# write default entry
def write_default
ret = Yast::Execute.on_target("/usr/bin/sdbootutil",
"set-default", @default,
allowed_exitstatus: [0, 1])
"set-default", @default,
allowed_exitstatus: [0, 1])
if ret != 0 # fallback directly over grub2-editenv
Yast::Execute.on_target("/usr/bin/grub2-editenv", grubenv_path,
"set", "default="+@default)
"set", "default=" + @default)
end
end

# @return [Array] return array of entries or []
# @return [Array] return array of entries or []
def read_entries
output = Yast::Execute.on_target(
"/usr/bin/bootctl", "--json=short", "list" ,stdout: :capture
"/usr/bin/bootctl", "--json=short", "list", stdout: :capture
)
return [] if output.nil?

JSON.parse(output)
end

end
end
1 change: 0 additions & 1 deletion src/lib/bootloader/bootloader_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,5 @@ def status_string(status)
_("disabled")
end
end

end
end
2 changes: 1 addition & 1 deletion src/lib/bootloader/bootloader_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def use_systemd_boot?
end

def use_grub2_bls?
(Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
(Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
end

def grub2_efi_installable?
Expand Down
2 changes: 0 additions & 2 deletions src/lib/bootloader/generic_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def localized_names(name)
names[name] or raise "Unknown supported bootloader '#{name}'"
end

# rubocop:disable Metrics/MethodLength
# It will be reduced again if systemd-boot is not anymore in beta phase.
def handle
old_bl = BootloaderFactory.current.name
Expand Down Expand Up @@ -88,7 +87,6 @@ def handle
:redraw
end

# rubocop:enable Metrics/MethodLength
def help
_(
"<p><b>Boot Loader</b>\n" \
Expand Down
48 changes: 24 additions & 24 deletions src/lib/bootloader/grub2_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ def init
end

def store
if !@hidden_menu_widget.is_a?(CWM::Empty)
if @hidden_menu_widget.checked?
grub_default.hidden_timeout = value.to_s
grub_default.timeout = "0"
else
grub_default.hidden_timeout = "0"
grub_default.timeout = value.to_s
end
if @hidden_menu_widget.is_a?(CWM::Empty)
grub_default.timeout = value.to_s
elsif @hidden_menu_widget.checked?
grub_default.hidden_timeout = value.to_s
grub_default.timeout = "0"
else
grub_default.timeout = value.to_s
grub_default.hidden_timeout = "0"
grub_default.timeout = value.to_s
end
end
end
Expand Down Expand Up @@ -355,7 +353,8 @@ def store
end

def validate
return true if Yast::Mode.config || !value || ["grub2-efi", "grub2-bls"].include?(grub2.name)
return true if Yast::Mode.config || !value || ["grub2-efi",
"grub2-bls"].include?(grub2.name)

tpm_files = Dir.glob("/sys/**/pcrs")
if !tpm_files.empty? && !File.read(tpm_files[0], 1).nil?
Expand Down Expand Up @@ -982,10 +981,10 @@ def label
end

def contents
if (Yast::Arch.s390 || grub2.name=="grub2-bls")
console_widget = CWM::Empty.new("console")
console_widget = if Yast::Arch.s390 || grub2.name == "grub2-bls"
CWM::Empty.new("console")
else
console_widget = ConsoleWidget.new
ConsoleWidget.new
end
VBox(
VSpacing(1),
Expand Down Expand Up @@ -1064,7 +1063,7 @@ def loader_location_widget?
end

def generic_mbr_widget?
(Yast::Arch.x86_64 || Yast::Arch.i386) && !(["grub2-efi", "grub2-bls"].include?(grub2.name))
(Yast::Arch.x86_64 || Yast::Arch.i386) && !["grub2-efi", "grub2-bls"].include?(grub2.name)
end

def secure_boot_widget?
Expand All @@ -1086,26 +1085,26 @@ def pmbr_widget?
end

def device_map_button?
(Yast::Arch.x86_64 || Yast::Arch.i386) && !(["grub2-efi", "grub2-bls"].include?(grub2.name))
(Yast::Arch.x86_64 || Yast::Arch.i386) && !["grub2-efi", "grub2-bls"].include?(grub2.name)
end
end

# Represents bootloader specific options like its timeout,
# default section or password protection
class BootloaderTab < CWM::Tab
include Grub2Helper

def label
textdomain "bootloader"

_("Boot&loader Options")
end

def contents
if grub2.name != "grub2-bls"
hidden_menu_widget = HiddenMenuWidget.new
hidden_menu_widget = if grub2.name == "grub2-bls"
CWM::Empty.new("hidden_menu")
else
hidden_menu_widget = CWM::Empty.new("hidden_menu")
HiddenMenuWidget.new
end
VBox(
VSpacing(2),
Expand All @@ -1121,24 +1120,25 @@ def contents
HSpacing(1)
),
VSpacing(1),
MarginBox(1, 1, MinWidth(1,DefaultSectionWidget.new)),
MarginBox(1, 1, MinWidth(1, DefaultSectionWidget.new)),
MarginBox(1, 1, grub_password_widget),
VStretch()
)
end

private

def grub_password_widget
if grub2.name != "grub2-bls"
GrubPasswordWidget.new
else
if grub2.name == "grub2-bls"
CWM::Empty.new("password_widget")
else
GrubPasswordWidget.new
end
end

def os_prober_widget
if OsProber.available? && # Checks !Arch.s390 and if package is available
grub2.name != "grub2-bls"
grub2.name != "grub2-bls"
Left(OSProberWidget.new)
else
CWM::Empty.new("os_prober")
Expand Down
1 change: 0 additions & 1 deletion src/lib/bootloader/grub2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ def update_nvram_summary

"#{_("Update NVRAM:")} #{status_string(update_nvram)} #{link}"
end

end
# rubocop:enable Metrics/ClassLength
end
76 changes: 34 additions & 42 deletions src/lib/bootloader/grub2bls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Grub2Bls < Grub2Base
attr_reader :sections

CMDLINE = "/etc/kernel/cmdline"

def initialize
textdomain "bootloader"

Expand All @@ -31,14 +31,12 @@ def initialize
# Display bootloader summary
# @return a list of summary lines
def summary(*)
result = [
[
Yast::Builtins.sformat(
_("Boot Loader Type: %1"),
"GRUB2 BLS"
)
]

result
end

# @return bootloader name
Expand All @@ -61,7 +59,7 @@ def read
log.info "kernel params: #{grub_default.kernel_params}"
log.info "bls sections: #{@sections.all}"
log.info "bls default: #{@sections.default}"
@is_read = true #flag that settings has been read
@is_read = true # flag that settings has been read
end

# @return true if configuration is already read
Expand Down Expand Up @@ -117,46 +115,45 @@ def merge(other)
log.info "merging result: timeout: #{grub_default.timeout}"
log.info " mitigations: #{cpu_mitigations.to_human_string}"
log.info " kernel_params: #{grub_default.kernel_params.serialize}"

end

# @return [Array<String>] packages required to configure given bootloader
def packages
res = super
res << "grub2-" + Yast::Arch.architecture + "-efi-bls"
res << ("grub2-" + Yast::Arch.architecture + "-efi-bls")
res << "sdbootutil"
res << "grub2"
res
end

private

SDBOOTUTIL = "/usr/bin/sdbootutil".freeze
OS_RELEASE_PATH = "/etc/os-release".freeze
SDBOOTUTIL = "/usr/bin/sdbootutil"
OS_RELEASE_PATH = "/etc/os-release"

def grubenv_path
str = Yast::Misc.CustomSysconfigRead("ID_LIKE", "openSUSE",
OS_RELEASE_PATH)
os = str.split(" ").first
return File.join("/boot/efi/EFI/", os, "/grubenv")
OS_RELEASE_PATH)
os = str.split.first
File.join("/boot/efi/EFI/", os, "/grubenv")
end

# @return [String] return default boot as string or "" if not set
# or something goes wrong
def read_menu_timeout
grub_default.timeout = Yast::Misc.CustomSysconfigRead("timeout", "",
grubenv_path)
grubenv_path)
log.info "Boot timeout: #{grub_default.timeout}"
end

def write_menu_timeout
ret = Yast::Execute.on_target("/usr/bin/sdbootutil",
"set-timeout",
grub_default.timeout,
allowed_exitstatus: [0, 1])
"set-timeout",
grub_default.timeout,
allowed_exitstatus: [0, 1])
if ret != 0 # fallback directly over grub2-editenv
Yast::Execute.on_target("/usr/bin/grub2-editenv", grubenv_path,
"set", "timeout=#{grub_default.timeout}")
"set", "timeout=#{grub_default.timeout}")
end
end

Expand All @@ -167,33 +164,28 @@ def merge_sections(other)
end

def create_menu_entries
begin
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", "add-all-kernels")
rescue Cheetah::ExecutionFailed => e
Yast::Report.Error(
format(_(
"Cannot create systemd-boot menu entry:\n" \
"Command `%{command}`.\n" \
"Error output: %{stderr}"
), command: e.commands.inspect, stderr: e.stderr)
)
end
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", "add-all-kernels")
rescue Cheetah::ExecutionFailed => e
Yast::Report.Error(
format(_(
"Cannot create systemd-boot menu entry:\n" \
"Command `%{command}`.\n" \
"Error output: %{stderr}"
), command: e.commands.inspect, stderr: e.stderr)
)
end

def install_bootloader
begin
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose",
"install")
rescue Cheetah::ExecutionFailed => e
Yast::Report.Error(
format(_(
"Cannot install systemd bootloader:\n" \
"Command `%{command}`.\n" \
"Error output: %{stderr}"
), command: e.commands.inspect, stderr: e.stderr)
)
end
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose",
"install")
rescue Cheetah::ExecutionFailed => e
Yast::Report.Error(
format(_(
"Cannot install systemd bootloader:\n" \
"Command `%{command}`.\n" \
"Error output: %{stderr}"
), command: e.commands.inspect, stderr: e.stderr)
)
end

end
end

0 comments on commit 36e4ed4

Please sign in to comment.