From 36e4ed41dcca86ca7b4115e9e58cec1512e7237a Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Fri, 8 Nov 2024 15:26:17 +0100 Subject: [PATCH] rubocop --- src/lib/bootloader/bls_sections.rb | 25 ++++---- src/lib/bootloader/bootloader_base.rb | 1 - src/lib/bootloader/bootloader_factory.rb | 2 +- src/lib/bootloader/generic_widgets.rb | 2 - src/lib/bootloader/grub2_widgets.rb | 48 +++++++-------- src/lib/bootloader/grub2base.rb | 1 - src/lib/bootloader/grub2bls.rb | 76 +++++++++++------------- 7 files changed, 72 insertions(+), 83 deletions(-) diff --git a/src/lib/bootloader/bls_sections.rb b/src/lib/bootloader/bls_sections.rb index b6375e33e..877502a3c 100644 --- a/src/lib/bootloader/bls_sections.rb +++ b/src/lib/bootloader/bls_sections.rb @@ -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 @@ -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 diff --git a/src/lib/bootloader/bootloader_base.rb b/src/lib/bootloader/bootloader_base.rb index d91210ce2..3f03ea4d2 100644 --- a/src/lib/bootloader/bootloader_base.rb +++ b/src/lib/bootloader/bootloader_base.rb @@ -121,6 +121,5 @@ def status_string(status) _("disabled") end end - end end diff --git a/src/lib/bootloader/bootloader_factory.rb b/src/lib/bootloader/bootloader_factory.rb index 8b42c82bf..9e39df361 100644 --- a/src/lib/bootloader/bootloader_factory.rb +++ b/src/lib/bootloader/bootloader_factory.rb @@ -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? diff --git a/src/lib/bootloader/generic_widgets.rb b/src/lib/bootloader/generic_widgets.rb index 21041cccb..a6770bc2f 100644 --- a/src/lib/bootloader/generic_widgets.rb +++ b/src/lib/bootloader/generic_widgets.rb @@ -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 @@ -88,7 +87,6 @@ def handle :redraw end - # rubocop:enable Metrics/MethodLength def help _( "

Boot Loader\n" \ diff --git a/src/lib/bootloader/grub2_widgets.rb b/src/lib/bootloader/grub2_widgets.rb index a74ee47cd..d7926e673 100644 --- a/src/lib/bootloader/grub2_widgets.rb +++ b/src/lib/bootloader/grub2_widgets.rb @@ -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 @@ -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? @@ -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), @@ -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? @@ -1086,7 +1085,7 @@ 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 @@ -1094,7 +1093,7 @@ def device_map_button? # default section or password protection class BootloaderTab < CWM::Tab include Grub2Helper - + def label textdomain "bootloader" @@ -1102,10 +1101,10 @@ def label 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), @@ -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") diff --git a/src/lib/bootloader/grub2base.rb b/src/lib/bootloader/grub2base.rb index e9dabe809..83caa8419 100644 --- a/src/lib/bootloader/grub2base.rb +++ b/src/lib/bootloader/grub2base.rb @@ -435,7 +435,6 @@ def update_nvram_summary "#{_("Update NVRAM:")} #{status_string(update_nvram)} #{link}" end - end # rubocop:enable Metrics/ClassLength end diff --git a/src/lib/bootloader/grub2bls.rb b/src/lib/bootloader/grub2bls.rb index 79e549a34..7e653c46f 100644 --- a/src/lib/bootloader/grub2bls.rb +++ b/src/lib/bootloader/grub2bls.rb @@ -18,7 +18,7 @@ class Grub2Bls < Grub2Base attr_reader :sections CMDLINE = "/etc/kernel/cmdline" - + def initialize textdomain "bootloader" @@ -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 @@ -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 @@ -117,13 +115,12 @@ 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] 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 @@ -131,32 +128,32 @@ def packages 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 @@ -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