-
Notifications
You must be signed in to change notification settings - Fork 20
/
inst_autoconfigure.rb
378 lines (332 loc) · 13.3 KB
/
inst_autoconfigure.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File: clients/inst_autoconfigure.ycp
# Package: Auto-installation
# Author: Anas Nashif <nashif@suse.de>
# Summary: This module finishes auto-installation and configures
# the system as described in the profile file.
#
# $Id$
require "yast2/system_time"
require "autoinstall/entries/description_sorter"
require "autoinstall/entries/registry"
require "autoinstall/importer"
require "autoinstall/package_searcher"
module Yast
class InstAutoconfigureClient < Client
include Yast::Logger
def main
Yast.import "UI"
textdomain "autoinst"
Yast.import "AutoinstConfig"
Yast.import "AutoinstGeneral"
Yast.import "AutoinstScripts"
Yast.import "Call"
Yast.import "Label"
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Profile"
Yast.import "Report"
Yast.import "Wizard"
@current_step = 0 # Required by logStep()
@resource = ""
@module_auto = ""
# Help text for last dialog of base installation
@help_text = _(
"<p>\n" \
"Please wait while the system is being configured.\n" \
"</p>"
)
log.info "Profile general,mode:#{AutoinstGeneral.mode.inspect}"
need_systemd_isolate = AutoinstGeneral.mode.fetch("activate_systemd_default_target", true)
final_restart_services = AutoinstGeneral.mode.fetch("final_restart_services", true)
registry = Y2Autoinstallation::Entries::Registry.instance
# additional for scripting and finished message
@max_steps = registry.writable_descriptions.size + 3
@max_steps = Ops.add(@max_steps, 1) if need_systemd_isolate
@max_steps += 1 if final_restart_services
Builtins.y2milestone(
"max steps: %1 need_isolate:%2",
@max_steps,
need_systemd_isolate
)
@contents = VBox(
LogView(Id(:log), "", 10, 0),
# Progress bar that displays overall progress in this dialog
ProgressBar(Id(:progress), _("Progress"), @max_steps, 0)
)
Wizard.SetNextButton(:next, Label.NextButton)
Wizard.SetBackButton(:back, Label.BackButton)
Wizard.SetAbortButton(:abort, Label.AbortButton)
Wizard.SetContents(
# Dialog title for autoyast dialog
_("Configuring System according to auto-install settings"),
@contents,
@help_text,
false,
false
)
Wizard.DisableAbortButton
# Report only those that are 'not unsupported', these were already reported
# Unsupported sections have already been reported in the first stage
importer = Y2Autoinstallation::Importer.new(Profile.current)
unsupported_sections = importer.obsolete_sections
unknown_sections = importer.unhandled_sections - unsupported_sections
if unknown_sections.any?
log.error "Could not process these unknown profile sections: #{unknown_sections}"
needed_packages = Y2Autoinstallation::PackagerSearcher.new(
unknown_sections
).evaluate_via_rpm
schema_package_list = if needed_packages.empty?
unknown_sections.map { |section| "<#{section}/>" }
else
needed_packages.map do |section, packages|
package_description = case packages.size
when 0
_("No needed package found.")
when 1
# TRANSLATOR: %s is the package name
_("Needed package: %s") % packages.first
else
# TRANSLATOR: %s is the list of package names
_("Needed packages: %s") % packages.join(",")
end
"<#{section}/> - #{package_description}"
end
end
Report.LongWarning(
# TRANSLATORS: Error message, %s is replaced by newline-separated
# list of unknown sections of the profile
# Do not translate words in brackets
_(
"These sections of the AutoYaST profile cannot be processed on this " \
"system:<br><br>%s<br><br>" \
"Maybe they were misspelled or your profile does not contain " \
"all the needed YaST packages in the <software/> section " \
"as required for functionality provided by additional modules."
) %
schema_package_list.join("<br>")
)
end
descriptions = registry.writable_descriptions
descriptions = Y2Autoinstallation::Entries::DescriptionSorter.new(descriptions).sort
log.info "Order: #{descriptions.inspect}"
descriptions.each do |description|
log.info "Processing #{description.inspect}"
processWait(description.module_name, "pre-modules")
result = importer.import_entry(description)
log.info "Imported #{result.inspect}"
Call.Function(description.client_name, ["Write"]) unless result.sections.empty?
processWait(description.module_name, "post-modules")
@current_step = Ops.add(@current_step, 1)
UI.ChangeWidget(Id(:progress), :Value, @current_step)
end
# Initialize scripts stack
AutoinstScripts.Import(Profile.current.fetch_as_hash("scripts"))
# online update
if Ops.get_boolean(
Profile.current,
["software", "do_online_update"],
false
) == true
processWait("do_online_update", "pre-modules")
@online_update_ret = Convert.to_symbol(
Call.Function("do_online_update_auto", ["Write"])
)
processWait("do_online_update", "post-modules")
if @online_update_ret == :reboot
# AddEditScript(scriptName, source, interpreter, type, chrooted, debug, feedback,
# feedback_type, location, notification)
# make sure to avoid conflicts with "zzz_reboot" script here
# https://github.com/yast/yast-autoinstallation/blob/104c18f1a56d02ab50055cdf09653db964b97888/src/modules/Profile.rb#L157
AutoinstScripts.AddEditScript("zzzz_reboot", "shutdown -r now", "shell", "init-scripts",
false, false, false, "", "", "") # wonderful API without defaults
end
end
logStep(_("Executing Post-Scripts"))
AutoinstScripts.Write("post-scripts", false)
logStep(_("Writing Init-Scripts"))
AutoinstScripts.Write("init-scripts", false)
max_wait = AutoinstGeneral.mode.fetch("max_systemd_wait", 30)
@ser_ignore = [
"YaST2-Second-Stage.service",
"autoyast-initscripts.service",
# Do not restart dbus. Otherwise some services will hang.
# bnc#937900
"dbus.service",
# Do not restart wickedd* services
# bnc#944349
"^wickedd",
# Do not restart NetworkManager* services
# bnc#955260
"^NetworkManager"
]
if final_restart_services
logStep(_("Restarting all running services"))
@cmd = "systemctl --type=service list-units | grep \" running \""
@out = Convert.to_map(SCR.Execute(path(".target.bash_output"), @cmd))
@sl = Ops.get_string(@out, "stdout", "").split("\n").collect { |c| c.split.first }
Builtins.y2milestone("running services \"%1\"", @sl)
# Filtering out all services which must not to be restarted
@sl.reject! { |s| @ser_ignore.any? { |i| s.match(/#{i}/) } }
Builtins.y2milestone("restarting services \"%1\"", @sl)
@cmd = Ops.add(
"systemctl --no-block restart ",
Builtins.mergestring(@sl, " ")
)
Builtins.y2milestone("before calling \"%1\"", @cmd)
@out = Convert.to_map(SCR.Execute(path(".target.bash_output"), @cmd))
Builtins.y2milestone("after calling \"%1\"", @cmd)
wait_systemd_finished(max_wait, @ser_ignore)
else
Builtins.y2milestone("Do not restart all services (defined in autoyast.xml)")
end
if need_systemd_isolate
logStep(_("Activating systemd default target"))
@cmd = "systemctl --no-block --ignore-dependencies isolate default.target"
Builtins.y2milestone("before calling \"%1\"", @cmd)
@out = Convert.to_map(SCR.Execute(path(".target.bash_output"), @cmd))
Builtins.y2milestone("after calling \"%1\"", @cmd)
Builtins.y2milestone("ret=%1", @out)
wait_systemd_finished(max_wait, @ser_ignore)
else
Builtins.y2milestone("Do not activate systemd default target (defined in autoyast.xml)")
end
# Just in case, remove this file to avoid reconfiguring...
SCR.Execute(path(".target.remove"), "/var/lib/YaST2/runme_at_boot")
logStep(_("Finishing Configuration"))
# Invoke SnapshotsFinish client to perform snapshots (if needed)
WFM.CallFunction("snapshots_finish", ["Write"])
# Disabling all local repos
WFM.CallFunction("pkg_finish", ["Write"])
# Saving y2logs
WFM.CallFunction("save_y2logs")
:next
end
# Display a step in the LogView widget and increment the progress bar.
# Uses global variable 'current_step'.
#
# @param [String] step_descr description of the step.
def logStep(step_descr)
@current_step = Ops.add(@current_step, 1)
UI.ChangeWidget(Id(:progress), :Value, @current_step)
UI.ChangeWidget(Id(:log), :LastLine, Ops.add(step_descr, "\n"))
Builtins.y2milestone(
"current step: %1 desc:%2",
@current_step,
step_descr
)
nil
end
def MatchInterface(id)
ret = id
if Builtins.substring(id, 0, 7) == "eth-id-"
ls = Builtins.splitstring(Builtins.substring(id, 7), ":")
ls = Builtins.maplist(ls) do |s|
Ops.less_than(Builtins.size(s), 2) ? Ops.add("0", s) : s
end
Builtins.y2milestone("MatchInterface ls:%1", ls)
cmd = Builtins.sformat(
"ifconfig | grep -i \"hwaddr.*%1\"",
Builtins.mergestring(ls, ":")
)
bo = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
ls = Builtins.splitstring(Ops.get_string(bo, "stdout", ""), "\n")
ls = Builtins.filter(Builtins.splitstring(Ops.get(ls, 0, ""), " \t")) do |s|
!Builtins.isempty(s)
end
ret = Ops.get(ls, 0, "") unless Builtins.isempty(ls)
end
Builtins.y2milestone("MatchInterface id:%1 ret:%2", id, ret)
ret
end
def processWait(resource, stage)
AutoinstGeneral.processes_to_wait(stage).each do |process|
next if Ops.get_string(process, "name", "") != resource
if Builtins.haskey(process, "sleep")
if Ops.get_boolean(process, ["sleep", "feedback"], false) == true
Popup.ShowFeedback(
"",
Builtins.sformat(_("Processing resource %1"), resource)
)
end
Builtins.sleep(
Ops.multiply(1000, Ops.get_integer(process, ["sleep", "time"], 0))
)
Popup.ClearFeedback if Ops.get_boolean(process, ["sleep", "feedback"], false) == true
end
next unless Builtins.haskey(process, "script")
debug = Ops.get_boolean(process, ["script", "debug"], true) ? "-x" : ""
scriptName = Builtins.sformat("%1-%2", stage, resource)
scriptPath = Builtins.sformat(
"%1/%2",
AutoinstConfig.scripts_dir,
scriptName
)
SCR.Write(
path(".target.string"),
scriptPath,
Ops.get_string(
process,
["script", "source"],
"echo Empty script!"
)
)
executionString = Builtins.sformat(
"/bin/sh %1 %2 2&> %3/%4.log ",
debug,
scriptPath,
AutoinstConfig.logs_dir,
scriptName
)
SCR.Execute(path(".target.bash"), executionString)
end
nil
end
def wait_systemd_finished(max_wait, ser_ignore)
ser_ignore = deep_copy(ser_ignore)
Builtins.y2milestone(
"wait_systemd_finished max_wait=%1 ser_ignore=%2",
max_wait,
ser_ignore
)
st_time = Yast2::SystemTime.uptime
cur_time = st_time
last_busy = st_time
cmd = "systemctl --full list-jobs"
while Ops.less_or_equal(Ops.subtract(cur_time, st_time), max_wait) &&
Ops.less_than(Ops.subtract(cur_time, last_busy), 5)
out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
Builtins.y2milestone(
"wait_systemd_finished ret exit:%1 stderr:%2",
Ops.get_integer(out, "exit", -1),
Ops.get_string(out, "stderr", "")
)
sl = Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
Builtins.y2milestone("sl=%1", sl)
ll = Builtins.maplist(sl) do |s|
Builtins.filter(Builtins.splitstring(s, " \t")) do |e|
!Builtins.isempty(e)
end
end
ll = Builtins.filter(ll) { |l| Ops.get_string(l, 3, "") == "running" }
cnt = Builtins.size(Builtins.filter(ll) do |l|
!Builtins.contains(ser_ignore, Ops.get_string(l, 1, ""))
end)
Builtins.y2milestone("size ll=%1 ll:%2", cnt, ll)
last_busy = cur_time if Ops.greater_than(cnt, 0)
Builtins.sleep(500)
cur_time = Yast2::SystemTime.uptime
Builtins.y2milestone(
"wait_systemd_finished time:%1 idle:%2",
Ops.subtract(cur_time, st_time),
Ops.subtract(cur_time, last_busy)
)
end
Builtins.y2milestone(
"wait_systemd_finished waited time:%1",
Ops.subtract(cur_time, st_time)
)
nil
end
end
end
Yast::InstAutoconfigureClient.new.main