-
Notifications
You must be signed in to change notification settings - Fork 20
/
inst_autosetup.rb
503 lines (430 loc) · 16.1 KB
/
inst_autosetup.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# encoding: utf-8
# File: clients/inst_autosetup.ycp
# Package: Auto-installation
# Summary: Setup and prepare system for auto-installation
# Authors: Anas Nashif <nashif@suse.de>
# Uwe Gansert <ug@suse.de>
#
# $Id$
require "autoinstall/module_config_builder"
module Yast
import "AutoinstConfig"
class InstAutosetupClient < Client
Target = AutoinstConfigClass::Target
def main
Yast.import "Pkg"
Yast.import "UI"
textdomain "autoinst"
Yast.import "AutoInstall"
Yast.import "Installation"
Yast.import "Profile"
Yast.import "Progress"
Yast.import "Report"
Yast.import "AutoinstStorage"
Yast.import "AutoinstScripts"
Yast.import "AutoinstGeneral"
Yast.import "AutoinstSoftware"
Yast.import "Popup"
Yast.import "Arch"
Yast.import "AutoinstLVM"
Yast.import "AutoinstRAID"
Yast.import "Storage"
Yast.import "Timezone"
Yast.import "Keyboard"
Yast.import "Call"
Yast.import "ProductControl"
Yast.import "ProductLicense"
Yast.import "Language"
Yast.import "Console"
Yast.import "ServicesManager"
Yast.import "Y2ModuleConfig"
Yast.import "AutoinstFunctions"
Yast.import "Wizard"
Yast.include self, "autoinstall/ask.rb"
@help_text = _(
"<P>Please wait while the system is prepared for autoinstallation.</P>"
)
@progress_stages = [
_("Execute pre-install user scripts"),
_("Configure General Settings "),
_("Set up language"),
_("Create partition plans"),
_("Configure Bootloader"),
_("Registration"),
_("Configure Software selections"),
_("Configure Systemd Default Target"),
_("Configure users and groups"),
_("Import SSH keys/settings"),
_("Confirm License")
]
@progress_descriptions = [
_("Executing pre-install user scripts..."),
_("Configuring general settings..."),
_("Setting up language..."),
_("Creating partition plans..."),
_("Configuring Bootloader..."),
_("Registering the system..."),
_("Configuring Software selections..."),
_("Configuring Systemd Default Target..."),
_("Importing users and groups configuration..."),
_("Importing SSH keys/settings..."),
_("Confirming License...")
]
Progress.New(
_("Preparing System for Automated Installation"),
"", # progress_title
Builtins.size(@progress_stages), # progress bar length
@progress_stages,
@progress_descriptions,
@help_text
)
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
Progress.NextStage
# Pre-Scripts
AutoinstScripts.Import(Ops.get_map(Profile.current, "scripts", {}))
AutoinstScripts.Write("pre-scripts", false)
# Reread Profile in case it was modified in pre-script
# User has to create the new profile in a pre-defined
# location for easy processing in pre-script.
return :abort if readModified == :abort
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
#
# Partitioning and Storage
#//////////////////////////////////////////////////////////////////////
@modified = true
begin
askDialog
# Pre-Scripts
AutoinstScripts.Import(Ops.get_map(Profile.current, "scripts", {}))
AutoinstScripts.Write("pre-scripts", false)
@ret2 = readModified
return :abort if @ret2 == :abort
@modified = false if @ret2 == :not_found
if Ops.greater_or_equal(
SCR.Read(path(".target.size"), "/var/lib/YaST2/restart_yast"),
0
)
return :restart_yast
end
end while @modified == true
# reimport scripts, for the case <ask> has changed them
AutoinstScripts.Import(Ops.get_map(Profile.current, "scripts", {}))
#
# Set workflow variables
#
Progress.NextStage
# configure general settings
AutoinstGeneral.Import(Ops.get_map(Profile.current, "general", {}))
Builtins.y2milestone(
"general: %1",
Ops.get_map(Profile.current, "general", {})
)
AutoinstGeneral.Write
write_network = false
general_section = Profile.current["general"] || {}
semiauto_network = general_section["semi-automatic"] &&
general_section["semi-automatic"].include?("networking")
if Profile.current["networking"] &&
( Profile.current["networking"]["setup_before_proposal"] ||
semiauto_network ||
!AutoinstConfig.second_stage()
)
Builtins.y2milestone(
"Importing Network settings from configuration file")
Call.Function(
"lan_auto",
["Import", Ops.get_map(Profile.current, "networking", {})]
)
if Profile.current["networking"]["setup_before_proposal"]
Builtins.y2milestone("Networking setup before the proposal")
write_network = true
elsif !AutoinstConfig.second_stage()
# Second stage of installation will not be called but a
# network configuration is available. So this will be written
# while the general inst_finish process at the end of the
# first stage. But for the installation workflow the linuxrc
# network settings will be taken. (bnc#944942)
Builtins.y2milestone(
"Networking setup at the end of first installation stage")
end
end
if semiauto_network
Builtins.y2milestone("Networking manual setup before proposal")
Call.Function("inst_lan", ["enable_next" => true])
write_network = true
end
Call.Function("lan_auto", ["Write"]) if write_network
if Builtins.haskey(Profile.current, "add-on")
Progress.Title(_("Handling Add-On Products..."))
Call.Function(
"add-on_auto",
["Import", Ops.get_map(Profile.current, "add-on", {})]
)
Call.Function("add-on_auto", ["Write"])
# The entry "kexec_reboot" can be set by the AutoYaST configuration
# file (general section) and should not be reset by any other
# product description file. So we set it here again.
# bnc#981434
AutoinstGeneral.Write
end
@use_utf8 = true # utf8 is default
@displayinfo = UI.GetDisplayInfo
if !Ops.get_boolean(@displayinfo, "HasFullUtf8Support", true)
@use_utf8 = false # fallback to ascii
end
#
# Set it in the Language module.
#
Progress.NextStage
Progress.Title(_("Configuring language..."))
Language.Import(Ops.get_map(Profile.current, "language", {}))
#
# Set Console font
#
Installation.encoding = Console.SelectFont(Language.language)
if Ops.get_boolean(@displayinfo, "HasFullUtf8Support", true)
Installation.encoding = "UTF-8"
end
UI.SetLanguage(Language.language, Installation.encoding)
WFM.SetLanguage(Language.language, "UTF-8")
if Builtins.haskey(Profile.current, "timezone")
Timezone.Import(Ops.get_map(Profile.current, "timezone", {}))
end
# bnc#891808: infer keyboard from language if needed
if Profile.current.has_key?("keyboard")
Keyboard.Import(Profile.current["keyboard"] || {}, :keyboard)
elsif Profile.current.has_key?("language")
Keyboard.Import(Profile.current["language"] || {}, :language)
end
# one can override the <confirm> option by the commandline parameter y2confirm
@tmp = Convert.to_string(
SCR.Read(path(".target.string"), "/proc/cmdline")
)
if @tmp != nil &&
Builtins.contains(Builtins.splitstring(@tmp, " \n"), "y2confirm")
AutoinstConfig.Confirm = true
Builtins.y2milestone("y2confirm found and confirm turned on")
end
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
# moved here from autoinit for fate #301193
# needs testing
if Arch.s390 && AutoinstConfig.remoteProfile == true
Builtins.y2milestone("arch=s390 and remote_profile=true")
if Builtins.haskey(Profile.current, "dasd")
Builtins.y2milestone("dasd found")
if Call.Function("dasd_auto", ["Import", Ops.get_map(Profile.current, "dasd", {})])
Call.Function("dasd_auto", [ "Write" ])
end
end
if Builtins.haskey(Profile.current, "zfcp")
Builtins.y2milestone("zfcp found")
if Call.Function("zfcp_auto", ["Import", Ops.get_map(Profile.current, "zfcp", {})])
Call.Function("zfcp_auto", [ "Write" ])
end
end
end
Progress.NextStage
# if one modifies the partition table in a pre script, we will
# recognize this now
Storage.ReReadTargetMap
if Profile.current["partitioning"] && !Profile.current["partitioning"].empty?
AutoinstStorage.Import(Profile.current["partitioning"])
write_storage = true
elsif Profile.current["partitioning_advanced"] && !Profile.current["partitioning_advanced"].empty?
AutoinstStorage.ImportAdvanced(Profile.current["partitioning_advanced"])
write_storage = true
# No partitioning in the profile means yast2-storage proposal (hmmmm.....)
else
Storage.SetTestsuite(true) # FIXME: *urgs*
WFM.CallFunction("inst_disk_proposal", [true, true]) # FIXME: fragile?
Storage.SetTestsuite(false) # *urgs* again
end
semiauto_partitions = general_section["semi-automatic"] &&
general_section["semi-automatic"].include?("partitioning")
if semiauto_partitions
Builtins.y2milestone("Partitioning manual setup")
# Yes, do not set Storage testsuite here as we want really GUI with proposal
Call.Function("inst_disk_proposal", ["enable_next" => true])
write_storage = true
end
if write_storage &&
!AutoinstStorage.Write
Report.Error(_("Error while configuring partitions.\nTry again.\n"))
Builtins.y2error("Aborting...")
return :abort
end
AutoinstRAID.Write if AutoinstRAID.Init
AutoinstLVM.Write if AutoinstLVM.Init
# Bootloader
# The bootloader has to be called before software selection.
# So the software selection can take care about packages
# needed by the bootloader (bnc#876161)
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
Progress.NextStage
return :abort unless WFM.CallFunction(
"bootloader_auto",
["Import", Ops.get_map(Profile.current, "bootloader", {})]
)
# Registration
# FIXME: There is a lot of duplicate code with inst_autoupgrade.
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
Progress.NextStage
if Profile.current["suse_register"]
return :abort unless WFM.CallFunction(
"scc_auto",
["Import", Profile.current["suse_register"]]
)
return :abort unless WFM.CallFunction(
"scc_auto",
["Write"]
)
# failed relnotes download is not fatal, ignore ret code
WFM.CallFunction("inst_download_release_notes")
elsif general_section["semi-automatic"] &&
general_section["semi-automatic"].include?("scc")
Call.Function("inst_scc", ["enable_next" => true])
end
# Software
return :abort if Popup.ConfirmAbort(:painless) if UI.PollInput == :abort
Progress.NextStage
# Evaluating package and patterns selection.
# Selection will stored in PackageAI.
AutoinstSoftware.Import(Ops.get_map(Profile.current, "software", {}))
# Add additional packages in order to run YAST modules which
# has been defined the AutoYaST configuration file.
# Selection will stored in PackageAI.
add_yast2_dependencies if AutoinstFunctions.second_stage_required?
# Adding selections (defined in PackageAI) to libzypp and solving
# package dependencies.
if !AutoinstSoftware.Write
Report.Error(
_("Error while configuring software selections.\nTry again.\n")
)
Builtins.y2error("Aborting...")
return :abort
end
# fate #301321 - AutoYaST imaging support
# no generic images, just the ones the manual installation would use too, to speed up
# installation
#
# no check if section is available makes product default possible
Call.Function(
"deploy_image_auto",
["Import", Ops.get_map(Profile.current, "deploy_image", {})]
)
Call.Function("deploy_image_auto", ["Write"])
# SLES only
if Builtins.haskey(Profile.current, "kdump")
Call.Function(
"kdump_auto",
["Import", Ops.get_map(Profile.current, "kdump", {})]
)
end
Progress.NextStage
if Profile.current.has_key? ('runlevel')
# still supporting old format "runlevel"
ServicesManager.import(Profile.current['runlevel'])
elsif Profile.current.has_key? ('services-manager')
ServicesManager.import(Profile.current['services-manager'])
else
# We will have to set default entries which are defined
# in the import call of ServicesManager
ServicesManager.import({})
end
#
# Import users configuration from the profile
#
Progress.NextStage
autosetup_users
#
# Import profile settings for copying SSH keys from a
# previous installation
#
Progress.NextStage
if Profile.current["ssh_import"]
config = Profile.current["ssh_import"]
Profile.remove_sections("ssh_import")
return :abort unless WFM.CallFunction(
"ssh_import_auto",
["Import", config]
)
end
#
# Checking Base Product licenses
#
Progress.NextStage
if general_section["mode"] && general_section["mode"].fetch( "confirm_base_product_license", false )
Wizard.EnableAbortButton
result = ProductLicense.AskLicenseAgreement(nil,
"",
ProductLicense.license_patterns,
"abort",
# back button is disabled
false,
true,
true,
# unique id
"0"
)
return :abort if result == :abort
end
Progress.Finish
@ret = ProductControl.RunFrom(
Ops.add(ProductControl.CurrentStep, 1),
true
)
return :finish if @ret == :next
@ret
end
def readModified
if Ops.greater_than(
SCR.Read(path(".target.size"), AutoinstConfig.modified_profile),
0
)
if !Profile.ReadXML(AutoinstConfig.modified_profile) ||
Profile.current == {}
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
cpcmd = Builtins.sformat(
"mv %1 %2",
"/tmp/profile/autoinst.xml",
"/tmp/profile/pre-autoinst.xml"
)
Builtins.y2milestone("copy original profile: %1", cpcmd)
SCR.Execute(path(".target.bash"), cpcmd)
cpcmd = Builtins.sformat(
"mv %1 %2",
AutoinstConfig.modified_profile,
"/tmp/profile/autoinst.xml"
)
Builtins.y2milestone("moving modified profile: %1", cpcmd)
SCR.Execute(path(".target.bash"), cpcmd)
return :found
end
:not_found
end
# Import Users configuration from profile
def autosetup_users
users_config = ModuleConfigBuilder.build(Y2ModuleConfig.getModuleConfig("users"), Profile.current)
if users_config
Profile.remove_sections(users_config.keys)
Call.Function("users_auto", ["Import", users_config])
end
end
# Add YaST2 packages dependencies
def add_yast2_dependencies
keys = Profile.current.keys.select do |k|
Profile.current[k].is_a?(Array)||Profile.current[k].is_a?(Hash)
end
AutoinstSoftware.AddYdepsFromProfile(keys)
end
end
end
Yast::InstAutosetupClient.new.main