-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* supporting Grub2-BLS
- Loading branch information
Showing
35 changed files
with
1,505 additions
and
1,417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
require "yast" | ||
require "bootloader/sysconfig" | ||
require "bootloader/cpu_mitigations" | ||
require "cfa/grub2/default" | ||
|
||
Yast.import "Report" | ||
|
||
module Bootloader | ||
# Represents bls compatile system calls which can be used | ||
# e.g. by grub2-bls and systemd-boot | ||
class Bls | ||
include Yast::Logger | ||
extend Yast::I18n | ||
|
||
SDBOOTUTIL = "/usr/bin/sdbootutil" | ||
|
||
def initialize | ||
textdomain "bootloader" | ||
end | ||
|
||
def self.create_menu_entries | ||
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", "add-all-kernels") | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot create boot menu entry:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
end | ||
|
||
def self.install_bootloader | ||
Yast::Execute.on_target!(SDBOOTUTIL, "--verbose", | ||
"install") | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot install bootloader:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
end | ||
|
||
def self.write_menu_timeout(timeout) | ||
Yast::Execute.on_target!(SDBOOTUTIL, "set-timeout", timeout) | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot write boot menu timeout:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
end | ||
|
||
def self.menu_timeout | ||
begin | ||
output = Yast::Execute.on_target!(SDBOOTUTIL, "get-timeout", stdout: :capture).to_i | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot read boot menu timeout:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
output = -1 | ||
end | ||
output | ||
end | ||
|
||
def self.write_default_menu(default) | ||
Yast::Execute.on_target!(SDBOOTUTIL, "set-default", default) | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot write default boot menu entry:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
end | ||
|
||
def self.default_menu | ||
begin | ||
output = Yast::Execute.on_target!(SDBOOTUTIL, "get-default", stdout: :capture) | ||
rescue Cheetah::ExecutionFailed => e | ||
Yast::Report.Error( | ||
format(_( | ||
"Cannot read default menu:\n" \ | ||
"Command `%{command}`.\n" \ | ||
"Error output: %{stderr}" | ||
), command: e.commands.inspect, stderr: e.stderr) | ||
) | ||
output = "" | ||
end | ||
output | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
require "yast" | ||
require "yast2/execute" | ||
require "bootloader/bls" | ||
|
||
Yast.import "Misc" | ||
|
||
module Bootloader | ||
# Represents available sections and handling of default BLS boot entry | ||
class BlsSections | ||
include Yast::Logger | ||
|
||
# @return [Array<String>] list of all available boot titles | ||
# or an empty array | ||
attr_reader :all | ||
|
||
# @return [String] title of default boot section. | ||
attr_reader :default | ||
|
||
def initialize | ||
@all = [] | ||
@default = "" | ||
end | ||
|
||
# Sets default section internally. | ||
# @param [String] value of new boot title to boot | ||
# @note to write it to system use #write later | ||
def default=(value) | ||
log.info "set new default to '#{value.inspect}'" | ||
|
||
# empty value mean no default specified | ||
if !all.empty? && !all.include?(value) && !value.empty? | ||
log.warn "Invalid value #{value} trying to set as default. Fallback to default" | ||
value = "" | ||
end | ||
|
||
@default = value | ||
end | ||
|
||
# writes default to system making it persistent | ||
def write | ||
return if @default.empty? | ||
|
||
Bls.write_default_menu(@default) | ||
end | ||
|
||
def read | ||
@data = read_entries | ||
@all = @data.map { |e| e["title"] } | ||
@default = Bls.default_menu | ||
end | ||
|
||
private | ||
|
||
# @return [Array] return array of entries or [] | ||
def read_entries | ||
output = Yast::Execute.on_target( | ||
"/usr/bin/bootctl", "--json=short", "list", stdout: :capture | ||
) | ||
return [] if output.nil? | ||
|
||
JSON.parse(output) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.