/
luks2_systemd_boot_checkbox.rb
128 lines (112 loc) · 4.42 KB
/
luks2_systemd_boot_checkbox.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
# ------------------------------------------------------------------------------
# Copyright (c) 2024 SUSE LLC, All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# ------------------------------------------------------------------------------
require "yast"
require "cwm"
require "installation/console/menu_plugin"
require "y2storage"
require "y2storage/storage_env"
Yast.import "ProductFeatures"
Yast.import "Arch"
Yast.import "Report"
module Installation
module Console
module Plugins
# define a checkbox for enabling LUKS2 and systemd_boot support in the installer
class LUKS2SystemdBootCheckBox < CWM::CustomWidget
include Yast::Logger
def initialize
super
textdomain "installation"
end
def contents
CheckBoxFrame(
Id(:frame),
_("Set systemd-bootloader and LUKS2 Encryption while evaluating the propsal"),
false,
HBox(
HSpacing(2),
# TRANSLATORS: text entry, please keep it short
Password(Id(:pw1), _("&Password for LUKS2 Encryption")),
HSpacing(8),
# text entry
Password(Id(:pw2), _("Re&type LUKS2 Encryption Password"))
)
)
end
def validate
return true unless Yast::UI.QueryWidget(Id(:frame), :Value)
if Yast::UI.QueryWidget(Id(:pw1), :Value) == ""
Yast::Report.Error(_("The password must not be empty."))
Yast::UI.SetFocus(Id(:pw1))
return false
end
if Yast::UI.QueryWidget(Id(:pw1), :Value) == Yast::UI.QueryWidget(Id(:pw2), :Value)
return true
end
Yast::Report.Error(_(
"'Password' and 'Retype password'\ndo not match. Retype the password."
))
Yast::UI.SetFocus(Id(:pw1))
false
end
# set the initial status
def init
proposal_section = Yast::ProductFeatures.GetFeature("partitioning", "proposal")
encryption = proposal_section.nil? ? nil : proposal_section["encryption"]
password = if !encryption.nil? && !encryption["password"].nil?
encryption["password"]
else
""
end
Yast::UI.ChangeWidget(Id(:frame), :Value, !password.empty?)
Yast::UI.ChangeWidget(Id(:pw2), :Value, password)
Yast::UI.ChangeWidget(Id(:pw1), :Value, password)
end
def store
proposal_section = Yast::ProductFeatures.GetFeature("partitioning", "proposal")
if Yast::UI.QueryWidget(Id(:frame), :Value)
# pbkdf2 is default because it can be used by grub2 too
proposal_section["encryption"] = { "type" => "luks2", "pbkdf" => "argon2id",
"password" => Yast::UI.QueryWidget(Id(:pw1), :Value) }
ENV["YAST_LUKS2_AVAILABLE"] = "1"
Yast::ProductFeatures.SetStringFeature("globals", "prefered_bootloader", "systemd-boot")
else
proposal_section["encryption"] = {}
Yast::ProductFeatures.SetStringFeature("globals", "prefered_bootloader", "")
end
Yast::ProductFeatures::SetFeature("partitioning", "proposal", proposal_section)
end
def help
# TRANSLATORS: help text for the checkbox enabling LUKS2 and systemd_boot
_("<p>You can set LUKS2 encryption and systemd boot installation.</p>")
end
end
# define the plugin
class LUKS2SystemdBootCheckBoxPlugin < MenuPlugin
def widget
if Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
Y2Storage::Arch.new.efiboot? &&
(Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported
LUKS2SystemdBootCheckBox.new
else
CWM::Empty.new("empty")
end
end
# Set after the availability of LUKS2 encryption checkbox
def order
3000
end
end
end
end
end