/
inst_autoinit.rb
232 lines (200 loc) · 7.05 KB
/
inst_autoinit.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
# encoding: utf-8
# File: clients/inst_autoinit.ycp
# Package: Auto-installation
# Summary: Parses XML Profile for automatic installation
# Authors: Anas Nashif <nashif@suse.de>
#
# $Id$
#
module Yast
class InstAutoinitClient < Client
include Yast::Logger
def main
Yast.import "UI"
textdomain "autoinst"
Yast.import "Installation"
Yast.import "AutoInstall"
Yast.import "AutoinstConfig"
Yast.import "AutoinstFunctions"
Yast.import "AutoinstGeneral"
Yast.import "ProfileLocation"
Yast.import "AutoInstallRules"
Yast.import "Progress"
Yast.import "Report"
Yast.import "Profile"
Yast.import "Call"
Yast.import "Console"
Yast.import "Mode"
Yast.import "Y2ModuleConfig"
Yast.import "Popup"
Yast.include self, "autoinstall/autoinst_dialogs.rb"
Console.Init
@help_text = _(
"<p>\nPlease wait while the system is prepared for autoinstallation.</p>\n"
)
@progress_stages = [
_("Probe hardware"),
_("Retrieve & Read Control File"),
_("Parse control file"),
_("Initial Configuration"),
]
@profileFetched = false
Progress.New(
_("Preparing System for Automatic Installation"),
"", # progress_title
6, # progress bar length
@progress_stages,
[],
@help_text
)
Progress.NextStage
Progress.Title(_("Preprobing stage"))
Builtins.y2milestone("pre probing")
@tmp = Convert.to_string(
SCR.Read(path(".target.string"), "/etc/install.inf")
)
if @tmp != nil && Builtins.issubstring(Builtins.tolower(@tmp), "iscsi: 1")
WFM.CallFunction("inst_iscsi-client", [])
end
Progress.NextStep
Progress.Title(_("Probing hardware..."))
Builtins.y2milestone("Probing hardware...")
if !@profileFetched
# if profile is defined, first read it, then probe hardware
@autoinstall = SCR.Read(path(".etc.install_inf.AutoYaST"))
if Mode.autoupgrade &&
!(@autoinstall != nil && Ops.is_string?(@autoinstall) &&
Convert.to_string(@autoinstall) != "")
AutoinstConfig.ParseCmdLine("file:///mnt/root/autoupg.xml")
AutoinstConfig.ProfileInRootPart = true
end
@ret = processProfile
return @ret if @ret != :ok
end
Progress.Finish
if !(Mode.autoupgrade && AutoinstConfig.ProfileInRootPart)
WFM.CallFunction("inst_system_analysis", [])
end
if Builtins.haskey(Profile.current, "iscsi-client")
Builtins.y2milestone("iscsi-client found")
WFM.CallFunction(
"iscsi-client_auto",
["Import", Ops.get_map(Profile.current, "iscsi-client", {})]
)
WFM.CallFunction("iscsi-client_auto", ["Write"])
end
if Builtins.haskey(Profile.current, "fcoe-client")
Builtins.y2milestone("fcoe-client found")
WFM.CallFunction(
"fcoe-client_auto",
["Import", Ops.get_map(Profile.current, "fcoe-client", {})]
)
WFM.CallFunction("fcoe-client_auto", ["Write"])
end
if !AutoinstFunctions.selected_product
msg = _("None or wrong base product has been defined in the AutoYaST configuration file." \
"Please check the <b>products</b> entry in the <b>software</b> section.<br><br>" \
"Following base products are available:<br>")
Y2Packager::Product.available_base_products.each do |product|
msg += "#{product.name} (#{product.display_name})<br>"
end
Popup.LongError(msg) # No timeout because we are stopping the installation/upgrade.
return :abort
end
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
:next
end
private
# Checking profile for unsupported sections.
def check_unsupported_profile_sections
unsupported_sections = Y2ModuleConfig.unsupported_profile_sections
if unsupported_sections.any?
log.error "Could not process these unsupported profile " \
"sections: #{unsupported_sections}"
Report.LongWarning(
# TRANSLATORS: Error message, %s is replaced by newline-separated
# list of unsupported sections of the profile
# Do not translate words in brackets
_(
"These sections of AutoYaST profile are not supported " \
"anymore:<br><br>%s<br><br>" \
"Please, use, e.g., <scripts/> or <files/>" \
" to change the configuration."
) % unsupported_sections.map{|section| "<#{section}/>"}.join("<br>")
)
end
end
def processProfile
Progress.NextStage
Builtins.y2milestone("Starting processProfile msg:%1",AutoinstConfig.message)
Progress.Title(AutoinstConfig.message)
ret = false
Progress.NextStep
while true
r = ProfileLocation.Process
if r
break
else
newURI = ProfileSourceDialog(AutoinstConfig.OriginalURI)
if newURI == ""
return :abort
else
# Updating new URI in /etc/install.inf (bnc#963487)
# SCR.Write does not work in inst-sys here.
WFM.Execute(
path(".local.bash"),
"sed -i \'/AutoYaST:/c\AutoYaST: #{newURI}\' /etc/install.inf"
)
AutoinstConfig.ParseCmdLine(newURI)
AutoinstConfig.SetProtocolMessage
next
end
end
end
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
#
# Set reporting behaviour to default, changed later if required
#
Report.LogMessages(true)
Report.LogErrors(true)
Report.LogWarnings(true)
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
Progress.NextStage
Progress.Title(_("Parsing control file"))
Builtins.y2milestone("Parsing control file")
if !Profile.ReadXML(AutoinstConfig.xml_tmpfile) || Profile.current == {} ||
Profile.current == nil
Popup.Error(
_(
"Error while parsing the control file.\n" +
"Check the log files for more details or fix the\n" +
"control file and try again.\n"
)
)
return :abort
end
Builtins.y2debug("Autoinstall control file %1", Profile.current)
# Checking profile for unsupported sections.
check_unsupported_profile_sections
Progress.NextStage
Progress.Title(_("Initial Configuration"))
Builtins.y2milestone("Initial Configuration")
Report.Import(Profile.current.fetch("report",{}))
AutoinstGeneral.Import(Profile.current.fetch("general",{}))
#
# Copy the control file for easy access by user to a pre-defined
# directory
#
SCR.Execute(
path(".target.bash"),
Builtins.sformat(
"cp %1 %2/autoinst.xml",
AutoinstConfig.xml_tmpfile,
AutoinstConfig.profile_dir
)
)
:ok
end
end
end
Yast::InstAutoinitClient.new.main