-
Notifications
You must be signed in to change notification settings - Fork 22
/
BootGRUB2EFI.rb
181 lines (155 loc) · 5.94 KB
/
BootGRUB2EFI.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# encoding: utf-8
# File:
# modules/BootGRUB2EFI.ycp
#
# Module:
# Bootloader installation and configuration
#
# Summary:
# Module containing specific functions for GRUB2EFI configuration
# and installation
#
# Authors:
# Jiri Srain <jsrain@suse.cz>
# Joachim Plack <jplack@suse.de>
# Olaf Dabrunz <od@suse.de>
# Philipp Thomas <pth@suse.de>
#
# $Id: BootGRUB2EFI.ycp 63508 2011-03-04 12:53:27Z jreidinger $
#
require "yast"
require "bootloader/grub2base"
module Yast
class BootGRUB2EFIClass < GRUB2Base
def main
super
textdomain "bootloader"
BootGRUB2EFI()
end
# general functions
# Read settings from disk
# @param [Boolean] reread boolean true to force reread settings from system
# @param [Boolean] avoid_reading_device_map do not read new device map from file, use
# internal data
# @return [Boolean] true on success
def Read(reread, avoid_reading_device_map)
BootCommon.InitializeLibrary(reread, "grub2-efi")
BootCommon.ReadFiles(avoid_reading_device_map) if reread
BootCommon.Read(false, avoid_reading_device_map)
# read status of secure boot to boot common cache (bnc#892032)
BootCommon.getSystemSecureBootStatus(reread)
@orig_globals ||= deep_copy(BootCommon.globals)
end
# Write bootloader settings to disk
# @return [Boolean] true on success
def Write
ret = BootCommon.UpdateBootloader
# we do not have originals or it changed
if !@orig_globals ||
@orig_globals["distributor"] != BootCommon.globals["distributor"]
BootCommon.location_changed = true
end
if BootCommon.location_changed
grub_ret = BootCommon.InitializeBootloader
grub_ret = false if grub_ret.nil?
Builtins.y2milestone("GRUB2EFI return value: %1", grub_ret)
ret &&= grub_ret
end
# something with PMBR needed
if BootCommon.pmbr_action
efi_disk = Storage.GetEntryForMountpoint("/boot/efi")["device"]
efi_disk ||= Storage.GetEntryForMountpoint("/boot")["device"]
efi_disk ||= Storage.GetEntryForMountpoint("/")["device"]
pmbr_setup(BootCommon.pmbr_action, efi_disk)
end
ret
end
def Propose
super
# for UEFI always set PMBR flag on disk (bnc#872054)
BootCommon.pmbr_action = :add if !BootCommon.was_proposed || Mode.autoinst || Mode.autoupgrade
# set secure boot always on (bnc #879486)
BootCommon.setSystemSecureBootStatus(true) if !BootCommon.was_proposed && Arch.x86_64
end
# Display bootloader summary
# @return a list of summary lines
def Summary
result = [
Builtins.sformat(
_("Boot Loader Type: %1"),
BootCommon.getLoaderName(BootCommon.getLoaderType(false), :summary)
)
]
result = Builtins.add(
result,
Builtins.sformat(
_("Enable Secure Boot: %1"),
BootCommon.getSystemSecureBootStatus(false)
)
)
deep_copy(result)
end
# Return map of provided functions
# @return a map of functions (eg. $["write":BootGRUB2EFI::Write])
def GetFunctions
{
"read" => fun_ref(method(:Read), "boolean (boolean, boolean)"),
"reset" => fun_ref(method(:Reset), "void (boolean)"),
"propose" => fun_ref(method(:Propose), "void ()"),
"save" => fun_ref(method(:Save), "boolean (boolean, boolean, boolean)"),
"summary" => fun_ref(method(:Summary), "list <string> ()"),
"update" => fun_ref(method(:Update), "void ()"),
"widgets" => fun_ref(
method(:grub2efiWidgets),
"map <string, map <string, any>> ()"
),
"dialogs" => fun_ref(method(:Dialogs), "map <string, symbol ()> ()"),
"write" => fun_ref(method(:Write), "boolean ()")
}
end
# Constructor
def BootGRUB2EFI
if Arch.i386
packages = ["grub2-i386-efi"]
elsif Arch.x86_64
packages = ["grub2-x86_64-efi", "shim", "mokutil"]
elsif Arch.aarch64
packages = ["grub2-arm64-efi"]
else
# do not raise exception as we call constructor everywhere even if it doesn't make sense
packages = []
end
Ops.set(
BootCommon.bootloader_attribs,
"grub2-efi",
"required_packages" => packages,
"loader_name" => "GRUB2-EFI",
"initializer" => fun_ref(method(:Initializer), "void ()")
)
nil
end
publish :variable => :common_help_messages, :type => "map <string, string>"
publish :variable => :common_descriptions, :type => "map <string, string>"
publish :variable => :grub_help_messages, :type => "map <string, string>"
publish :variable => :grub_descriptions, :type => "map <string, string>"
publish :variable => :grub2_help_messages, :type => "map <string, string>"
publish :variable => :grub2_descriptions, :type => "map <string, string>"
publish :variable => :password, :type => "string"
publish :function => :askLocationResetPopup, :type => "boolean (string)"
publish :function => :grub2Widgets, :type => "map <string, map <string, any>> ()"
publish :function => :grub2efiWidgets, :type => "map <string, map <string, any>> ()"
publish :function => :StandardGlobals, :type => "map <string, string> ()"
publish :function => :Read, :type => "boolean (boolean, boolean)"
publish :function => :Update, :type => "void ()"
publish :function => :Write, :type => "boolean ()"
publish :function => :Reset, :type => "void (boolean)"
publish :function => :Propose, :type => "void ()"
publish :function => :Summary, :type => "list <string> ()"
publish :function => :Dialogs, :type => "map <string, symbol ()> ()"
publish :function => :GetFunctions, :type => "map <string, any> ()"
publish :function => :Initializer, :type => "void ()"
publish :function => :BootGRUB2EFI, :type => "void ()"
end
BootGRUB2EFI = BootGRUB2EFIClass.new
BootGRUB2EFI.main
end