Skip to content

Commit

Permalink
make rubocop happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 6, 2016
1 parent 495efc6 commit a9b8720
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/include/bootloader/grub/helps.rb
Expand Up @@ -91,7 +91,7 @@ def initialize_bootloader_grub_helps(_include_target)
"the <b>Up</b> and <b>Down</b> buttons to reorder the disks.\n" \
"To add a disk, push <b>Add</b>.\n" \
"To remove a disk, push <b>Remove</b>.</p>"
)
)
}

@grub_descriptions = {
Expand Down
3 changes: 2 additions & 1 deletion src/include/bootloader/grub/options.rb
Expand Up @@ -100,7 +100,7 @@ def InitBootLoaderLocationWidget(_widget)
if BootCommon.VerifyMDArray
UI.ChangeWidget(Id("enable_redundancy"), :Value,
BootCommon.enable_md_array_redundancy
)
)

value = BootCommon.globals["boot_mbr"] == "true"
UI.ChangeWidget(Id("boot_mbr"), :Value, value)
Expand Down Expand Up @@ -135,6 +135,7 @@ def InitBootLoaderLocationWidget(_widget)

nil
end

# handle function of a widget
# @param [String] widget string widget key
# @param [Hash] event map event that caused the operation
Expand Down
4 changes: 2 additions & 2 deletions src/include/bootloader/grub2/dialogs.rb
Expand Up @@ -89,7 +89,7 @@ def kernel_tab
MarginBox(1, 0.5, "append"),
MarginBox(1, 0.5, "console"),
VStretch()
)
)
}
end

Expand Down Expand Up @@ -119,7 +119,7 @@ def bootloader_tab
MarginBox(1, 1, "default"),
MarginBox(1, 1, "password"),
VStretch()
)
)
}
end

Expand Down
2 changes: 1 addition & 1 deletion src/include/bootloader/grub2/misc.rb
Expand Up @@ -140,7 +140,7 @@ def grub_LocationProposal
log.info "(2) globals: #{BootCommon.globals}"

# refresh device map
if BootStorage.device_map.empty? ||
if BootStorage.device_map.empty? ||
BootCommon.cached_settings_base_data_change_time !=
Storage.GetTargetChangeTime &&
# bnc#585824 - Bootloader doesn't use defined device map from autoyast
Expand Down
2 changes: 1 addition & 1 deletion src/include/bootloader/routines/autoinstall.rb
Expand Up @@ -208,7 +208,7 @@ def AI2Export(ai)
end

if Ops.greater_than(Builtins.size(modlist), 0)
Ops.set(exp, "initrd", "list" => modlist, "settings" => modsett)
Ops.set(exp, "initrd", "list" => modlist, "settings" => modsett)
end

old_format = false
Expand Down
1 change: 1 addition & 0 deletions src/include/bootloader/routines/common_options.rb
Expand Up @@ -197,6 +197,7 @@ def TimeoutWidget
"help" => Ops.get(@common_help_messages, "timeout", "")
}
end

# Common widgets of global settings
# @return [Hash{String => map<String,Object>}] CWS widgets
def CommonOptions
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/boot_record_backup.rb
Expand Up @@ -131,7 +131,7 @@ def rotate
BASH_PATH,
format("/bin/mv %{path} %{path}-%{date}",
path: device_file_path, date: change_date
)
)
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bootloader/bootloader_base.rb
@@ -1,6 +1,7 @@
require "bootloader/sysconfig"

module Bootloader
# Represents base for all kinds of bootloaders
class BootloaderBase
def write
write_sysconfig
Expand All @@ -10,6 +11,7 @@ def read
end

protected

def write_sysconfig
sysconfig = Bootloader::Sysconfig.new(bootloader: name)
sysconfig.write
Expand Down
20 changes: 10 additions & 10 deletions src/lib/bootloader/bootloader_factory.rb
Expand Up @@ -33,9 +33,12 @@ def supported_names
return SUPPORTED_BOOTLOADERS + ["default"]
end

ret = []
system_bl = system.name rescue nil # rescue exception if system one is not support
system_bl = system_bl ? [system.name] : [] # use current as first
system_bl = begin
system.name
rescue
nil
end # rescue exception if system one is not support
ret = system_bl ? [system.name] : [] # use current as first
ret << "grub2" unless Yast::Arch.aarch64 # grub2 everywhere except aarch64
ret << "grub2-efi" if Yast::Arch.x86_64 || Yast::Arch.aarch64
ret << "none"
Expand All @@ -52,16 +55,15 @@ def bootloader_by_name(name)
@cached_bootloaders["grub2-efi"] ||= Grub2EFI.new
when "none"
@cached_bootloaders["none"] ||= NoneBootloader.new
else
# TODO exception for unsupported bootloader
end
end

private

def boot_efi?
if Yast::Mode.live_installation
Yast::Execute.locally("modprobe", "efivars")
::File.exist?("/sys/firmware/efi/systab")
Yast::Execute.locally("modprobe", "efivars")
::File.exist?("/sys/firmware/efi/systab")
else
Yast::Linuxrc.InstallInf("EFI") == "1"
end
Expand All @@ -70,9 +72,7 @@ def boot_efi?
def proposed_name
return "grub2-efi" if Yast::Arch.aarch64

if Yast::Arch.x86_64 && boot_efi?
return "grub2-efi"
end
return "grub2-efi" if Yast::Arch.x86_64 && boot_efi?

"grub2" # grub2 works(c) everywhere
end
Expand Down
18 changes: 9 additions & 9 deletions src/lib/bootloader/device_map.rb
Expand Up @@ -123,15 +123,15 @@ def fill_mapping
next if bios_id.empty?

index = case Yast::Arch.architecture
when /ppc/
# on ppc it looks like "vdevice/v-scsi@71000002/@0"
bios_id[/\d+\z/].to_i
when "i386", "x86_64"
# it looks like 0x81. It is boot drive unit see http://en.wikipedia.org/wiki/Master_boot_record
bios_id[2..-1].to_i(16) - 0x80
else
raise "no support for bios id '#{bios_id}' on #{Yast::Arch.architecture}"
end
when /ppc/
# on ppc it looks like "vdevice/v-scsi@71000002/@0"
bios_id[/\d+\z/].to_i
when "i386", "x86_64"
# it looks like 0x81. It is boot drive unit see http://en.wikipedia.org/wiki/Master_boot_record
bios_id[2..-1].to_i(16) - 0x80
else
raise "no support for bios id '#{bios_id}' on #{Yast::Arch.architecture}"
end
# FATE #303548 - doesn't add disk with same bios_id with different name (multipath machine)
if !ids[index]
@mapping[target_dev] = "hd#{index}"
Expand Down
7 changes: 3 additions & 4 deletions src/lib/bootloader/grub2.rb
Expand Up @@ -12,7 +12,6 @@
Yast.import "BootCommon"
Yast.import "HTML"


module Bootloader
# Represents non-EFI variant of GRUB2
class Grub2 < GRUB2Base
Expand Down Expand Up @@ -61,7 +60,7 @@ def propose
# FATE#303643 Enable one-click changes in bootloader proposal
#
#
def urlLocationSummary
def url_location_summary
# TODO: convert to using grub_devices info
Builtins.y2milestone("Prepare url summary for GRUB2")
line = "<ul>\n<li>"
Expand Down Expand Up @@ -121,7 +120,7 @@ def urlLocationSummary

# Display bootloader summary
# @return a list of summary lines
def Summary
def summary
# TODO: convert to using grub_devices info
result = [
Builtins.sformat(
Expand Down Expand Up @@ -160,7 +159,7 @@ def Summary
# other mode than autoyast on running system
# both ppc and s390 have special devices for stage1 so it do not make sense
# allow change of location to MBR or boot partition (bnc#879107)
result << urlLocationSummary if !Arch.ppc && !Arch.s390 && !Mode.config
result << url_location_summary if !Arch.ppc && !Arch.s390 && !Mode.config

order_sum = BootCommon.DiskOrderSummary
result << order_sum if order_sum
Expand Down
9 changes: 4 additions & 5 deletions src/lib/bootloader/grub2base.rb
Expand Up @@ -24,7 +24,6 @@
Yast.import "Storage"
Yast.import "StorageDevices"


module Bootloader
# Common base for GRUB2 specialized classes
class GRUB2Base < BootloaderBase
Expand All @@ -51,10 +50,10 @@ def initialize
# TODO: move it to own place
def pmbr_setup(action, *devices)
action_parted = case action
when :add then "on"
when :remove then "off"
else raise "invalid action #{action}"
end
when :add then "on"
when :remove then "off"
else raise "invalid action #{action}"
end
devices.each do |dev|
res = WFM.Execute(path(".local.bash_output"),
"parted -s '#{dev}' disk_set pmbr_boot #{action_parted}")
Expand Down
9 changes: 4 additions & 5 deletions src/lib/bootloader/grub2efi.rb
Expand Up @@ -5,6 +5,7 @@
require "bootloader/sysconfig"

module Bootloader
# Represents grub2 bootloader with efi target
class Grub2EFI < GRUB2Base
attr_accessor :secure_boot

Expand Down Expand Up @@ -62,12 +63,10 @@ def summary
)
]

result += Yast::Builtins.sformat(
_("Enable Secure Boot: %1"),
@secure_boot ? _("yes") : _("no")
)
result + Yast::Builtins.sformat(
_("Enable Secure Boot: %1"),
@secure_boot ? _("yes") : _("no")
)
deep_copy(result)
end

def name
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/grub2pwd.rb
Expand Up @@ -124,7 +124,7 @@ def encrypt(password)
quoted_password = Yast::String.Quote(password)
result = Yast::WFM.Execute(YAST_BASH_PATH,
"echo '#{quoted_password}\n#{quoted_password}\n' | LANG=C grub2-mkpasswd-pbkdf2"
)
)

if result["exit"] != 0
raise "Failed to create encrypted password for grub2. Command output: #{result["stderr"]}"
Expand Down
49 changes: 25 additions & 24 deletions src/lib/bootloader/grub_install.rb
Expand Up @@ -4,6 +4,7 @@
Yast.import "Arch"

module Bootloader
# Wraps grub install script for easier usage.
class GrubInstall
def initialize(efi: false, secure_boot: false)
@efi = efi
Expand Down Expand Up @@ -36,30 +37,30 @@ def execute(devices: nil)

def target
@target ||= case Yast::Arch.architecture
when "i386"
if @efi
"i386-efi"
else
"i386-pc"
end
when "x86_64"
if @efi
"x86_64-efi"
else
"i386-pc"
end
when "ppc", "ppc64"
raise "EFI on ppc not supported" if @efi
"powerpc-ieee1275"
when "s390_32", "s390_64"
raise "EFI on s390 not supported" if @efi
"s390x-emu"
when "aarch64"
raise "Only EFI supported on aarch64" unless @efi
"arm64-efi"
else
raise "unsupported architecture '#{Yast::Arch.architecture}'"
end
when "i386"
if @efi
"i386-efi"
else
"i386-pc"
end
when "x86_64"
if @efi
"x86_64-efi"
else
"i386-pc"
end
when "ppc", "ppc64"
raise "EFI on ppc not supported" if @efi
"powerpc-ieee1275"
when "s390_32", "s390_64"
raise "EFI on s390 not supported" if @efi
"s390x-emu"
when "aarch64"
raise "Only EFI supported on aarch64" unless @efi
"arm64-efi"
else
raise "unsupported architecture '#{Yast::Arch.architecture}'"
end
end
end
end
2 changes: 1 addition & 1 deletion src/lib/bootloader/sections.rb
Expand Up @@ -21,7 +21,7 @@ def default
saved = Yast::Execute.on_target("/usr/bin/grub2-editenv", "list", stdout: :capture)
saved_line = saved.lines.grep(/saved_entry=/).first

saved_line ? saved_line.[/saved_entry=(\S*)\s\n/,1] : @data.first
saved_line ? saved_line[/saved_entry=(\S*)\s\n/, 1] : @data.first
end

# Sets default section internally
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/serial_console.rb
Expand Up @@ -76,7 +76,7 @@ def self.load_from_console_args(console_args)
end

def initialize(unit, speed = SPEED_DEFAULT, parity = PARITY_DEFAULT,
word = WORD_DEFAULT)
word = WORD_DEFAULT)
@unit = unit
@speed = speed
@parity = parity
Expand Down
25 changes: 12 additions & 13 deletions src/lib/bootloader/stage1.rb
Expand Up @@ -39,15 +39,15 @@ def write
# @see for keys in globals to https://old-en.opensuse.org/YaST/Bootloader_API#global_options_in_map
def propose
result = case Yast::Arch.architecture
when "i386", "x86_64"
propose_x86
when /ppc/
propose_ppc
when /s390/
propose_s390
else
raise "unsuported architecture #{Yast::Arch.architecture}"
end
when "i386", "x86_64"
propose_x86
when /ppc/
propose_ppc
when /s390/
propose_s390
else
raise "unsuported architecture #{Yast::Arch.architecture}"
end

log.info "location configured. Resulting globals #{Yast::BootCommon.globals}"

Expand Down Expand Up @@ -120,7 +120,7 @@ def propose_boot_location
# IMO it is good idea check MBR also in this case
# see bug #279837 comment #53
if boot_partition_on_mbr_disk?
selected_location = separate_boot ? :boot : :root
selected_location = separate_boot ? :boot : :root
elsif underlying_boot_partition_devices.size > 1
selected_location = :mbr
end
Expand Down Expand Up @@ -226,18 +226,17 @@ def assign_bootloader_device(selected_location)
raise "Unknown value to select bootloader device #{selected_location.inspect}"
end

@model.add_device(selected_location[1]) #add directly proposed value without changes
@model.add_device(selected_location[1]) # add directly proposed value without changes
else
raise "Unknown value to select bootloader device #{selected_location.inspect}"
end
end

def add_udev_device(dev)
udev_device = Bootloader::UdevMapping.to_mountby_device(dev)
@model.add_device(dev)
@model.add_device(udev_device)
end


# FIXME: find better location
def gpt_boot_disk?
targets = Yast::BootCommon.GetBootloaderDevices
Expand Down

0 comments on commit a9b8720

Please sign in to comment.