/
inst_autosetup.rb
427 lines (361 loc) · 14.4 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
# Copyright (c) [2013-2019] 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.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
# 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 "yast"
require "autoinstall/autosetup_helpers"
require "autoinstall/importer"
Yast.import "Pkg"
Yast.import "UI"
Yast.import "AutoinstConfig"
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 "Call"
Yast.import "ProductControl"
Yast.import "ServicesManager"
Yast.import "AutoinstFunctions"
Yast.import "Wizard"
module Y2Autoinstallation
module Clients
class InstAutosetup < Yast::Client
include Yast::Logger
include Y2Autoinstallation::AutosetupHelpers
Target = AutoinstConfigClass::Target
def main
textdomain "autoinst"
@help_text = _(
"<P>Please wait while the system is prepared for autoinstallation.</P>"
)
@progress_stages = [
_("Configure General Settings "),
_("Set up language"),
_("Create partition plans"),
_("Configure Bootloader"),
_("Configure security settings"),
_("Set up configuration management system"),
_("Registration"),
_("Configure Kdump"),
_("Configure Software selections"),
_("Configure Systemd Default Target"),
_("Configure users and groups"),
_("Import SSH keys/settings"),
_("Set up user defined configuration files"),
_("Confirm License"),
_("Configure firewall")
]
@progress_descriptions = [
_("Configuring general settings..."),
_("Setting up language..."),
_("Creating partition plans..."),
_("Configuring Bootloader..."),
_("Configuring security settings"),
_("Setting up configuration management system..."),
_("Registering the system..."),
_("Configuring Kdump..."),
_("Configuring Software selections..."),
_("Configuring Systemd Default Target..."),
_("Importing users and groups configuration..."),
_("Importing SSH keys/settings..."),
_("Setting up user defined configuration files..."),
_("Confirming License..."),
_("Configuring the firewall")
]
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 UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
#
# Set workflow variables
#
Progress.NextStage
# Ensure that we clean product cache to avoid product from control (bsc#1156058)
AutoinstFunctions.reset_product
# Merging selected product
AutoinstSoftware.merge_product(AutoinstFunctions.selected_product)
# configure general settings
general_section = Profile.current["general"] || {}
networking_section = Profile.current["networking"] || {}
pkg_list = networking_section["managed"] ? ["NetworkManager"] : []
AutoinstGeneral.Import(general_section)
log.info("general: #{general_section}")
AutoinstGeneral.Write
autosetup_network
if Builtins.haskey(Profile.current, "add-on")
Progress.Title(_("Handling Add-On Products..."))
unless Call.Function(
"add-on_auto",
["Import", Ops.get_map(Profile.current, "add-on", {})]
)
log.warn("User has aborted the installation.")
return :abort
end
Call.Function("add-on_auto", ["Write"])
# Recover partitioning settings that were removed by the add-on_auto client (bsc#1073548)
Yast::AutoinstStorage.import_general_settings(general_section["storage"])
# The entry "kexec_reboot" in the Product description can be set
# by the AutoYaST configuration setting (general/forceboot) and should
# not be reset by any other Product description file.
# So we set it here again.
# bnc#981434
AutoinstGeneral.SetRebootAfterFirstStage
end
#
# Set it in the Language module.
#
Progress.NextStage
Progress.Title(_("Configuring language..."))
autosetup_country
# 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 UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
# moved here from autoinit for fate #301193
# needs testing
if Arch.s390
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
#
# Partitioning and Storage
# //////////////////////////////////////////////////////////////////////
Progress.NextStage
# Pre-scripts can modify the AutoYaST profile. Even more, a pre-script could change
# the initial disks layout/configuration (e.g., by creating a new partition).
# It is difficult to evaluate whether a pre-script has modified something related
# to storage devices, so a re-probing is always performed here (related to bsc#1133045).
probe_storage
write_storage = if Profile.current["partitioning_advanced"] &&
!Profile.current["partitioning_advanced"].empty?
AutoinstStorage.ImportAdvanced(Profile.current["partitioning_advanced"])
else
AutoinstStorage.Import(Profile.current["partitioning"])
end
return :abort unless write_storage
semiauto_partitions = 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
# Bootloader
# The bootloader has to be called before software selection.
# So the software selection is aware and can manage packages
# needed by the bootloader (bnc#876161)
return :abort if UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
Progress.NextStage
return :abort unless WFM.CallFunction(
"bootloader_auto",
["Import", Ops.get_map(Profile.current, "bootloader", {})]
)
Progress.NextStage
# Importing security settings
autosetup_security
return :abort if UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
Progress.NextStage
# The configuration_management has to be called before software selection.
# So the software selection is aware and can manage packages
# needed by the configuration_management.
if Profile.current["configuration_management"]
return :abort unless WFM.CallFunction(
"configuration_management_auto",
["Import", Profile.current["configuration_management"]]
)
# Do not start it in second installation stage again.
# Provisioning will already be called in the first stage.
Profile.remove_sections("configuration_management")
end
return :abort if UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
Progress.NextStage
# Register system
return :abort unless suse_register
Progress.NextStage
# SLES only. Have to be run before software to add required packages to enable kdump
if Builtins.haskey(Profile.current, "kdump")
Call.Function(
"kdump_auto",
["Import", Ops.get_map(Profile.current, "kdump", {})]
)
# Don't run it again in 2nd installation stage
Profile.remove_sections("kdump")
end
# Software
return :abort if UI.PollInput == :abort && Popup.ConfirmAbort(:painless)
Progress.NextStage
# Evaluating package and patterns selection.
# Selection will be stored in PackageAI.
AutoinstSoftware.Import(Ops.get_map(Profile.current, "software", {}))
# Add additional packages in order to run YAST modules which
# have been defined in the AutoYaST configuration file.
# Selection will be stored in PackageAI.
add_yast2_dependencies if AutoinstFunctions.second_stage_required?
# Also add packages needed by some profile configuration but missing the
# explicit declaration in the software section
AutoinstSoftware.add_additional_packages(pkg_list) unless pkg_list.empty?
# 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"])
Progress.NextStage
if Profile.current.key?("runlevel")
# still supporting old format "runlevel"
ServicesManager.import(Profile.current["runlevel"])
# Do not start it in second installation stage again.
# Writing will be called in inst_finish.
Profile.remove_sections("runlevel")
elsif Profile.current.key? "services-manager"
ServicesManager.import(Profile.current["services-manager"])
# Do not start it in second installation stage again.
# Writing will be called in inst_finish.
Profile.remove_sections("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
#
# Import profile settings for creating configuration files.
#
Progress.NextStage
autosetup_files
#
# Checking Base Product licenses
#
Progress.NextStage
if general_section["mode"]&.fetch("confirm_base_product_license", false)
result = nil
while result != :next
result = WFM.CallFunction("inst_product_license", [{ "enable_back"=>false }])
return :abort if result == :abort && Yast::Popup.ConfirmAbort(:painless)
end
end
Progress.NextStage
#
# Run firewall configuration according to the profile
#
autosetup_firewall
# Results of imported values semantic check.
return :abort unless AutoInstall.valid_imported_values
Progress.Finish
@ret = ProductControl.RunFrom(ProductControl.CurrentStep + 1, true)
return :finish if @ret == :next
@ret
end
# Import Files section from profile
def autosetup_files
importer.import_entry("files").each do |e|
Profile.remove_sections(e)
end
end
# Import Users configuration from profile
def autosetup_users
importer.import_entry("users").each do |e|
Profile.remove_sections(e)
end
end
# Import security settings from profile
def autosetup_security
importer.import_entry("security").each do |e|
Profile.remove_sections(e)
end
end
# Add YaST2 packages dependencies
def add_yast2_dependencies
AutoinstSoftware.AddYdepsFromProfile(Profile.current.keys)
end
def importer
@importer ||= Y2Autoinstallation::Importer.new(Profile.current)
end
end
end
end