Skip to content

Commit

Permalink
set timeout via loader.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Apr 25, 2023
1 parent df5f99e commit a2e7740
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
67 changes: 41 additions & 26 deletions src/lib/bootloader/systemdboot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class SystemdBoot < BootloaderBase
include Yast::Logger
include Yast::I18n

# @!attribute timeout
# @!attribute menue_timeout
# @return [Integer] menue timeout
attr_accessor :timeout
attr_accessor :menue_timeout

# @!attribute secure_boot
# @return [Boolean] current secure boot setting
Expand All @@ -23,13 +23,13 @@ def initialize
super

textdomain "bootloader"
self.timeout = 10
self.menue_timeout = 10
end

def read
super

read_timeout()
read_menue_timeout()
self.secure_boot = Systeminfo.secure_boot_active?
end

Expand All @@ -41,6 +41,8 @@ def write(etc_only: false)

install_bootloader
create_menue_entries
# Set menue timeout
write_menue_timeout

unless etc_only
# writing in none transactional systems
Expand Down Expand Up @@ -95,7 +97,7 @@ def delete
KERNELINSTALL = "/usr/bin/kernel-install".freeze
BOOTCTL = "/bin/bootctl".freeze
CAT = "/bin/cat".freeze
TIMEOUTFILE="/sys/firmware/efi/efivars/LoaderConfigTimeout-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f".freeze
LOADERCONF = "/boot/efi/loader/loader.conf"

def create_menue_entries
Dir.foreach('/usr/lib/modules') do |kernel_name|
Expand All @@ -118,14 +120,40 @@ def create_menue_entries
end
end

def read_timeout
if File.file?(TIMEOUTFILE)
data = "".dup
read_bytes = File.read(TIMEOUTFILE)
read_bytes.each_byte do |c|
data << c.chr if c >=48 && c <=57
def read_menue_timeout
filename = File.join(Yast::Installation.destdir, LOADERCONF)
if File.file?(filename)
f = File.open(filename, "r")
f.each_line do |line|
line.lstrip!
next if line.start_with?("#")
if line.start_with?("timeout")
self.menue_timeout = line.split(" ")[1].to_i
break
end
end
end
end

def write_menue_timeout
filename = File.join(Yast::Installation.destdir, LOADERCONF)
if File.file?(filename)
output = []
entry_set = false
f = File.open(filename, "r")
f.each_line do |line|
line.lstrip!
if line.start_with?("timeout") || line.start_with?("#timeout")
output << "timeout #{self.menue_timeout}\n"
entry_set = true
next
end
output << line
end
output << "timeout #{self.menue_timeout}" unless entry_set
File.open(filename, "w+") do |fw|
fw.puts(output)
end
self.timeout = data.to_i
end
end

Expand Down Expand Up @@ -163,19 +191,6 @@ def install_bootloader
), command: e.commands.inspect, stderr: e.stderr))
return
end

# Set menue timeout.
begin
Yast::Execute.on_target!(BOOTCTL, "set-timeout", self.timeout)
rescue Cheetah::ExecutionFailed => e
Yast::Report.Error(
format(_(
"Cannot set menue timeout:\n" \
"Command `%{command}`.\n" \
"Error output: %{stderr}"
), command: e.commands.inspect, stderr: e.stderr))
return
end
end
end
end
end
4 changes: 2 additions & 2 deletions src/lib/bootloader/systemdboot_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def help
end

def init
self.value = systemdboot.timeout.to_i
self.value = systemdboot.menue_timeout.to_i
end

def store
systemdboot.timeout = value.to_s
systemdboot.menue_timeout = value.to_s
end
end

Expand Down

0 comments on commit a2e7740

Please sign in to comment.