/
options.rb
334 lines (314 loc) · 9.65 KB
/
options.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# encoding: utf-8
# File:
# modules/BootGRUB.ycp
#
# Module:
# Bootloader installation and configuration
#
# Summary:
# Module containing specific functions for GRUB 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$
#
module Yast
module BootloaderGrubOptionsInclude
def initialize_bootloader_grub_options(include_target)
textdomain "bootloader"
Yast.import "Label"
Yast.import "BootStorage"
Yast.include include_target, "bootloader/routines/common_options.rb"
Yast.include include_target, "bootloader/routines/popups.rb"
Yast.include include_target, "bootloader/routines/helps.rb"
Yast.include include_target, "bootloader/grub/helps.rb"
end
# Handle function of a widget
# @param [String] widget string id of the widget
# @param [Hash] event map event description of event that occured
# @return [Symbol] always nil
def HandlePasswdWidget(widget, event)
event = deep_copy(event)
if Ops.get(event, "ID") == :use_pas
enabled = Convert.to_boolean(UI.QueryWidget(Id(:use_pas), :Value))
UI.ChangeWidget(Id(:pw1), :Enabled, enabled)
UI.ChangeWidget(Id(:pw2), :Enabled, enabled)
end
nil
end
# Validate function of a popup
# @param [String] key any widget key
# @param [Hash] event map event that caused validation
# @return [Boolean] true if widget settings ok
def ValidatePasswdWidget(key, event)
event = deep_copy(event)
return true if !Convert.to_boolean(UI.QueryWidget(Id(:use_pas), :Value))
if UI.QueryWidget(Id(:pw1), :Value) == ""
emptyPasswdErrorPopup
UI.SetFocus(Id(:pw1))
return false
end
if UI.QueryWidget(Id(:pw1), :Value) == UI.QueryWidget(Id(:pw2), :Value)
return true
end
passwdMissmatchPopup
UI.SetFocus(Id(:pw1))
false
end
def passwd_content
HBox(
CheckBoxFrame(
Id(:use_pas),
_("Prot&ect Boot Loader with Password"),
true,
HBox(
HSpacing(2),
# text entry
Password(Id(:pw1), Opt(:hstretch), _("&Password")),
# text entry
HSpacing(2),
Password(Id(:pw2), Opt(:hstretch), _("Re&type Password")),
HStretch()
)
)
)
end
# Init function of a widget
# @param [String] widget string widget key
def InitBootLoaderLocationWidget(widget)
boot_devices = BootStorage.getPartitionList(:boot, "grub")
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)
else
list_global_target_keys = [
"boot_mbr",
"boot_boot",
"boot_root",
"boot_extended"
]
list_global_target_keys.each do |key|
value = BootCommon.globals[key]
if value && UI.WidgetExists(Id(key))
UI.ChangeWidget(Id(key), :Value, value == "true" ? true : false)
end
end
UI.ChangeWidget(Id("boot_custom_list"), :Items, boot_devices)
end
if !Builtins.haskey(BootCommon.globals, "boot_custom") ||
Ops.get(BootCommon.globals, "boot_custom", "") == ""
UI.ChangeWidget(Id("boot_custom_list"), :Enabled, false)
else
UI.ChangeWidget(Id("boot_custom"), :Value, true)
UI.ChangeWidget(Id("boot_custom_list"), :Enabled, true)
UI.ChangeWidget(
Id("boot_custom_list"),
:Value,
Ops.get(BootCommon.globals, "boot_custom", "")
)
end
nil
end
# handle function of a widget
# @param [String] widget string widget key
# @param [Hash] event map event that caused the operation
# @return [Symbol]
def HandleBootLoaderLocationWidget(widget, event)
event = deep_copy(event)
ret = Ops.get(event, "ID")
if ret == "boot_custom"
if Convert.to_boolean(UI.QueryWidget(Id("boot_custom"), :Value))
UI.ChangeWidget(Id("boot_custom_list"), :Enabled, true)
else
UI.ChangeWidget(Id("boot_custom_list"), :Enabled, false)
end
end
nil
end
# Store function of a widget
# @param [String] widget string widget key
# @param [Hash] event map event that caused the operation
def StoreBootLoaderLocationWidget(widget, event)
event = deep_copy(event)
if BootCommon.VerifyMDArray
BootCommon.enable_md_array_redundancy = Convert.to_boolean(
UI.QueryWidget(Id("enable_redundancy"), :Value)
)
Ops.set(
BootCommon.globals,
"boot_mbr",
Convert.to_boolean(UI.QueryWidget(Id("boot_mbr"), :Value)) ? "true" : "false"
)
else
list_global_target_keys = [
"boot_mbr",
"boot_boot",
"boot_root",
"boot_extended"
]
Builtins.foreach(list_global_target_keys) do |key|
value = UI.WidgetExists(Id(key)) && UI.QueryWidget(Id(key), :Value)
BootCommon.globals[key] = value.to_s
end
end
if UI.QueryWidget(Id("boot_custom"), :Value)
custom_value = UI.QueryWidget(Id("boot_custom_list"), :Value)
else
#bnc#544809 Custom Boot Partition cannot be deleted
custom_value = ""
end
BootCommon.globals["boot_custom"] = custom_value
nil
end
# FIXME: merge help text to one for BootLoaderLocationWidget
# Function merge help text from ../grub/helps.ycp
#
# @return [String] help text for widget BootLoaderLocationWidget
def HelpBootLoaderLocationWidget
ret = ""
ret = Ops.get(@grub_help_messages, "boot_mbr", "")
ret = Ops.add(ret, "\n")
ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_custom", ""))
ret = Ops.add(ret, "\n")
if BootCommon.VerifyMDArray
ret = Ops.add(
ret,
Ops.get(@grub_help_messages, "enable_redundancy", "")
)
else
ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_root", ""))
ret = Ops.add(ret, "\n")
ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_boot", ""))
ret = Ops.add(ret, "\n")
ret = Ops.add(ret, Ops.get(@grub_help_messages, "boot_extended", ""))
end
ret
end
# Create Frame "Boot Loader Location"
#
# @return [Yast::Term] with widgets
def grubBootLoaderLocationWidget
if BootStorage.can_boot_from_partition
partition_boot = BootStorage.BootPartitionDevice == BootStorage.RootPartitionDevice ?
Left(CheckBox(Id("boot_root"), _("Boot from &Root Partition"))) :
Left(CheckBox(Id("boot_boot"), _("Boo&t from Boot Partition")))
else
partition_boot = Empty()
end
boot_custom = [
Left(
CheckBox(
Id("boot_custom"),
Opt(:notify),
_("C&ustom Boot Partition")
)
),
Left(
ComboBox(
Id("boot_custom_list"),
Opt(:editable, :hstretch),
"",
[]
)
)]
contents = VBox(
VSpacing(1),
Frame(
_("Boot Loader Location"),
VBox(
HBox(
HSpacing(1),
VBox(
Left(
CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
),
partition_boot,
BootStorage.ExtendedPartitionDevice ?
Left(
CheckBox(
Id("boot_extended"),
_("Boot from &Extended Partition")
)
) :
Empty(),
*boot_custom
)
)
)
),
VSpacing(1)
)
if !BootCommon.PartitionInstallable
contents = VBox(
Frame(
_("Boot Loader Location"),
VBox(
HBox(
HSpacing(1),
VBox(
Left(
CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
),
*boot_custom,
VStretch()
)
)
)
),
VStretch()
)
end
if BootCommon.VerifyMDArray
contents = VBox(
Frame(
_("Boot Loader Location"),
VBox(
HBox(
HSpacing(1),
VBox(
Left(
CheckBox(Id("boot_mbr"), _("Boot from &Master Boot Record"))
),
Left(
CheckBox(
Id("enable_redundancy"),
_("Enable Red&undancy for MD Array")
)
),
*boot_custom,
VStretch()
)
)
)
),
VStretch()
)
end
{
"widget" => :custom,
"custom_widget" => contents,
"init" => fun_ref(
method(:InitBootLoaderLocationWidget),
"void (string)"
),
"handle" => fun_ref(
method(:HandleBootLoaderLocationWidget),
"symbol (string, map)"
),
"store" => fun_ref(
method(:StoreBootLoaderLocationWidget),
"void (string, map)"
),
"help" => HelpBootLoaderLocationWidget()
}
end
end
end