/
inst_finish.rb
594 lines (531 loc) · 18.5 KB
/
inst_finish.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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. 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 Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File: clients/inst_finish.ycp
# Package: installation
# Summary: Finish installation
# Authors: Klaus Kämpf <kkaempf@suse.de>
# Arvin Schnell <arvin@suse.de>
# Jiri Srain <jsrain@suse.de>
#
# $Id$
module Yast
class InstFinishClient < Client
def main
Yast.import "UI"
Yast.import "Pkg"
textdomain "installation"
Yast.import "AddOnProduct"
Yast.import "WorkflowManager"
Yast.import "Installation"
Yast.import "Linuxrc"
Yast.import "Misc"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "Popup"
Yast.import "ProductControl"
Yast.import "Progress"
Yast.import "Report"
Yast.import "Wizard"
Yast.import "String"
Yast.import "GetInstArgs"
Yast.import "ProductFeatures"
Yast.import "SlideShow"
Yast.import "InstError"
Yast.import "PackageCallbacks"
Yast.import "Hooks"
# added for fate# 303395
Yast.import "Directory"
return :auto if GetInstArgs.going_back
# <-- Functions
@test_mode = false
if Ops.greater_than(Builtins.size(WFM.Args), 0) &&
Ops.is_string?(WFM.Args(0))
Builtins.y2milestone("Args: %1", WFM.Args)
@test_mode = true if WFM.Args(0) == "test"
end
Wizard.CreateDialog if @test_mode
Wizard.DisableBackButton
Wizard.DisableNextButton
# Adjust a SlideShow dialog if not configured
@get_setup = SlideShow.GetSetup
if @get_setup == nil || @get_setup == {}
Builtins.y2milestone("No SlideShow setup has been set, adjusting")
SlideShow.Setup(
[
{
"name" => "finish",
"description" => _("Finishing Basic Installation"),
# fixed value
"value" => 100,
"units" => :sec
}
]
)
end
@get_setup = nil
Wizard.SetTitleIcon("yast-sysconfig")
# Do not open a new SlideShow widget, reuse the old one instead
# variable used later to close that dialog (if needed)
@required_to_open_sl_dialog = !SlideShow.HaveSlideWidget
if @required_to_open_sl_dialog
Builtins.y2milestone("SlideShow dialog not yet created")
SlideShow.OpenDialog
end
# Might be left from the previous stage
SlideShow.HideTable
SlideShow.MoveToStage("finish")
@log = _("Creating list of finish scripts to call...")
SlideShow.SubProgress(0, "")
SlideShow.StageProgress(0, @log)
SlideShow.AppendMessageToInstLog(@log)
# Used later in 'stages' definition
# Using empty callbacks that don't break the UI
PackageCallbacks.RegisterEmptyProgressCallbacks
Pkg.TargetInitialize(Installation.destdir)
Pkg.TargetLoad
PackageCallbacks.RestorePreviousProgressCallbacks
@stages = [
{
"id" => "copy_files",
# progress stage
"label" => _("Copy files to installed system"),
"steps" => [
"autoinst_scripts1",
"copy_files",
"copy_systemfiles",
"clone",
# For live installer only
Mode.live_installation ? "live_copy_files" : "",
"switch_scr"
],
"icon" => "pattern-basis"
},
{
"id" => "save_config",
# progress stage
"label" => _("Save configuration"),
"steps" => [
"ldconfig",
"save_config",
# For live installer only
Mode.live_installation ? "live_save_config" : "",
"default_target",
"desktop",
"storage",
"iscsi-client",
"kernel",
"cio_ignore",
"x11",
"proxy",
"pkg",
# registration is optional
WFM.ClientExists("scc_finish") ? "scc" : "",
"driver_update1",
"random",
# bnc #340733
"system_settings"
],
"icon" => "yast-desktop-select"
},
{
"id" => "save_settings",
# progress stage
"label" => _("Save installation settings"),
"steps" => [
"yast_inf",
"network",
"firewall_stage1",
"ntp-client",
"ssh_settings",
"ssh_service",
"save_hw_status",
"users",
"autoinst_scripts2",
"installation_settings"
],
"icon" => "yast-network"
},
# bnc#860089: Save bootloader as late as possible
# all different (config) files need to be written and copied first
{
"id" => "install_bootloader",
# progress stage
"label" => _("Install boot manager"),
"steps" => [
"bootloader",
ProductFeatures.GetBooleanFeature("globals", "enable_kdump") == true ? "kdump" : ""
],
"icon" => "yast-bootloader"
},
{
"id" => "prepare_for_reboot",
# progress stage
"label" => _("Prepare system for initial boot"),
"steps" => [
# For live installer only
Mode.live_installation ? "live_runme_at_boot" : "",
# vm_finish called only if yast2-vm is installed
# Can't use PackageSystem::Installed as the current SCR is attached to inst-sys
# instead of the installed system
Pkg.PkgInstalled("yast2-vm") ? "vm" : "",
"driver_update2",
# no second stage if possible
"pre_umount",
# copy logs just before 'umount'
# keeps maximum logs available after reboot
"copy_logs",
"umount"
],
# bnc #438154
"icon" => Mode.live_installation ?
"yast-live-install-finish" :
"yast-scripts"
}
]
if Ops.greater_than(Builtins.size(ProductControl.inst_finish), 0)
Builtins.y2milestone(
"Using inst_finish steps definition from control file"
)
@stages = deep_copy(ProductControl.inst_finish)
# Inst-finish need to be translated (#343783)
@textdom = Ops.get_string(
ProductControl.productControl,
"textdomain",
"control"
)
@stages_copy = deep_copy(@stages)
Builtins.y2milestone("Inst finish stages before: %1", @stages)
@counter = -1
# going through copy, the original is going to be changed in the loop
Builtins.foreach(@stages_copy) do |one_stage|
@counter = Ops.add(@counter, 1)
label = Ops.get_string(one_stage, "label", "")
next if label == nil || label == ""
loc_label = Builtins.dgettext(@textdom, label)
# if translated
if loc_label != nil && loc_label != "" && loc_label != label
Ops.set(@stages, [@counter, "label"], loc_label)
end
end
Builtins.y2milestone("Inst finish stages after: %1", @stages)
else
Builtins.y2milestone(
"inst_finish steps definition not found in control file"
)
end
# merge steps from add-on products
# bnc #438678
Ops.set(
@stages,
[0, "steps"],
Builtins.merge(
WorkflowManager.GetAdditionalFinishSteps("before_chroot"),
Ops.get_list(@stages, [0, "steps"], [])
)
)
Ops.set(
@stages,
[1, "steps"],
Builtins.merge(
WorkflowManager.GetAdditionalFinishSteps("after_chroot"),
Ops.get_list(@stages, [1, "steps"], [])
)
)
Ops.set(
@stages,
[3, "steps"],
Builtins.merge(
Ops.get_list(@stages, [3, "steps"], []),
WorkflowManager.GetAdditionalFinishSteps("before_umount")
)
)
@run_type = :installation
if Mode.update
@run_type = :update
elsif Mode.autoinst
@run_type = :autoinst
elsif Mode.live_installation
@run_type = :live_installation
end
@steps_count = 0
@stages_to_check = Builtins.size(@stages)
@currently_checking = 0
@stages = Builtins.maplist(@stages) do |stage|
@currently_checking = Ops.add(@currently_checking, 1)
SlideShow.SubProgress(
Ops.divide(Ops.multiply(100, @currently_checking), @stages_to_check),
Builtins.sformat(
_("Checking stage: %1..."),
Ops.get_string(stage, "label", Ops.get_string(stage, "id", ""))
)
)
steps = Builtins.maplist(Ops.get_list(stage, "steps", [])) do |s|
# some steps are called in live installer only
next nil if s == "" || s == nil
s = Ops.add(s, "_finish")
if !WFM.ClientExists(s)
Builtins.y2error("Missing YCP client: %1", s)
next nil
end
Builtins.y2milestone("Calling inst_finish script: %1 (Info)", s)
orig = Progress.set(false)
info = Convert.to_map(WFM.CallFunction(s, ["Info"]))
if @test_mode == true
info = {} if info == nil
Builtins.y2milestone("Test mode, forcing run")
Ops.set(info, "when", [:installation, :update, :autoinst])
end
Progress.set(orig)
if info == nil
Builtins.y2error("Client %1 returned invalid data", s)
ReportClientError(
Builtins.sformat("Client %1 returned invalid data.", s)
)
next nil
end
if Ops.get(info, "when") != nil &&
!Builtins.contains(Ops.get_list(info, "when", []), @run_type) &&
# special hack for autoupgrade - should be as regular upgrade as possible, scripts are the only exception
!(Mode.autoupgrade &&
Builtins.contains(Ops.get_list(info, "when", []), :autoupg))
next nil
end
Builtins.y2milestone("inst_finish client %1 will be called", s)
Ops.set(info, "client", s)
@steps_count = Ops.add(
@steps_count,
Ops.get_integer(info, "steps", 1)
)
deep_copy(info)
end
Ops.set(stage, "steps", Builtins.filter(steps) { |s| s != nil })
deep_copy(stage)
end
Builtins.y2milestone("These inst_finish stages will be called:")
Builtins.foreach(@stages) do |stage|
Builtins.y2milestone("Stage: %1", stage)
end
@stages = Builtins.filter(@stages) do |s|
Ops.greater_than(Builtins.size(Ops.get_list(s, "steps", [])), 0)
end
@stage_names = Builtins.maplist(@stages) do |s|
Ops.get_string(s, "label", "")
end
@aborted = false
@stages_nr = Builtins.size(@stages)
@current_stage = -1
@current_stage_percent = 0
@fallback_msg = nil
Builtins.foreach(@stages) do |stage|
if Ops.get_string(stage, "icon", "") != ""
Wizard.SetTitleIcon(Ops.get_string(stage, "icon", ""))
end
@current_stage = Ops.add(@current_stage, 1)
@current_stage_percent = Ops.divide(
Ops.multiply(100, @current_stage),
@stages_nr
)
SlideShow.StageProgress(
@current_stage_percent,
Ops.get_string(stage, "label", "")
)
SlideShow.AppendMessageToInstLog(Ops.get_string(stage, "label", ""))
steps_nr = Builtins.size(Ops.get_list(stage, "steps", []))
current_step = -1
Builtins.foreach(Ops.get_list(stage, "steps", [])) do |step|
current_step = Ops.add(current_step, 1)
# a fallback busy message
@fallback_msg = Builtins.sformat(
_("Calling step %1..."),
Ops.get_string(step, "client", "")
)
SlideShow.SubProgress(
Ops.divide(Ops.multiply(100, current_step), steps_nr),
Ops.get_string(step, "title", @fallback_msg)
)
SlideShow.StageProgress(
Ops.add(
@current_stage_percent,
Ops.divide(
Ops.multiply(Ops.divide(100, @stages_nr), current_step),
steps_nr
)
),
nil
)
# use as ' * %1' -> ' * One of the finish steps...' in the SlideShow log
SlideShow.AppendMessageToInstLog(
Builtins.sformat(
_(" * %1"),
Ops.get_string(step, "title", @fallback_msg)
)
)
orig = Progress.set(false)
if @test_mode == true
Builtins.y2milestone(
"Test-mode, skipping WFM::CallFunction (%1, ['Write'])",
Ops.get_string(step, "client", "")
)
Builtins.sleep(500)
else
Hooks.run "before_#{step['client']}"
WFM.CallFunction(Ops.get_string(step, "client", ""), ["Write"])
Hooks.run "after_#{step['client']}"
end
Progress.set(orig)
# Handle user input during client run
user_ret = UI.PollInput
# Aborting...?
if user_ret == :abort
if Popup.ConfirmAbort(:incomplete)
@aborted = true
raise Break
end
# Anything else
else
SlideShow.HandleInput(user_ret)
end
end
raise Break if @aborted
SlideShow.SubProgress(100, nil)
end
SlideShow.StageProgress(100, nil)
SlideShow.AppendMessageToInstLog(_("Finished"))
if @aborted
Builtins.y2milestone("inst_finish aborted")
return :abort
end
if @required_to_open_sl_dialog
Builtins.y2milestone("Closing previously opened SlideShow dialog")
SlideShow.CloseDialog
end
used_hooks = Hooks.all.select(&:used?)
failed_hooks = used_hooks.select(&:failed?)
if !failed_hooks.empty?
Builtins.y2error "#{failed_hooks.size} failed hooks found: " +
"#{failed_hooks.map(&:name).join(', ')}"
end
Builtins.y2milestone('Hook summary:') unless used_hooks.empty?
used_hooks.each do |hook|
Builtins.y2milestone("Hook name: #{hook.name}")
Builtins.y2milestone("Hook result: #{hook.succeeded? ? 'success' : 'failure' }")
hook.files.each do |file|
Builtins.y2milestone("Hook file: #{file.path}")
Builtins.y2milestone("Hook output: #{file.output}")
end
end
show_used_hooks(used_hooks) unless failed_hooks.empty?
# --------------------------------------------------------------
# Check if there is a message left to display
# and display it, if necessary
# Do not call any SCR, it's already closed!
if Ops.greater_than(Builtins.size(Misc.boot_msg), 0) && !Mode.autoinst
# bugzilla #245742, #160301
if Linuxrc.usessh && !Linuxrc.vnc ||
# also live installation - bzilla #297691
Mode.live_installation
# Display the message and wait for user to accept it
Report.DisplayMessages(true, 0)
else
Report.DisplayMessages(true, 10)
end
Report.LongMessage(Misc.boot_msg)
Misc.boot_msg = ""
end
if @test_mode
Wizard.CloseDialog
return :auto
end
# fate #303395: Use kexec to avoid booting between first and second stage
# run new kernel via kexec instead of reboot
# command for reading kernel_params
@cmd = Builtins.sformat(
"ls '%1/kexec_done' |tr -d '\n'",
String.Quote(Directory.vardir)
)
Builtins.y2milestone(
"Checking flag of successful loading kernel via command %1",
@cmd
)
@out = Convert.to_map(WFM.Execute(path(".local.bash_output"), @cmd))
@cmd = Builtins.sformat("%1/kexec_done", Directory.vardir)
# check output
if Ops.get_string(@out, "stdout", "") != @cmd
Builtins.y2milestone("File kexec_done was not found, output: %1", @out)
return :next
end
# hack for using kexec switch to console 1
@cmd = Builtins.sformat("chvt 1")
Builtins.y2milestone("Switch to console 1 via command: %1", @cmd)
# switch to console 1
@out = Convert.to_map(WFM.Execute(path(".local.bash_output"), @cmd))
# check output
if Ops.get(@out, "exit") != 0
Builtins.y2error("Switching failed, output: %1", @out)
return :next
end
# waiting s for switching...
Builtins.sleep(1000)
:next
end
def show_used_hooks hooks
content = Table(
Id(:hooks_table),
Opt(:notify),
Header('Hook name', 'Result', 'Output'),
hooks.map do |hook|
Item(
Id(:hook),
hook.name,
hook.failed? ? 'failure' : 'success',
hook.files.map(&:output).reject(&:empty?).join
)
end
)
Builtins.y2milestone "Showing the hooks results in UI"
Popup.LongText(
'Hooks results',
content,
# the width and hight numbers reflect subjective visual appearance of the popup
80, 5 + hooks.size
)
end
# --> Functions
def ReportClientError(client_error_text)
# get the latest errors
cmd = Convert.to_map(
WFM.Execute(
path(".local.bash_output"),
"tail -n 200 /var/log/YaST2/y2log | grep ' <\\(3\\|5\\)> '"
)
)
InstError.ShowErrorPopUp(
_("Installation Error"),
client_error_text,
Ops.get_integer(cmd, "exit", -1) == 0 &&
Ops.get_string(cmd, "stdout", "") != "" ?
Ops.get_string(cmd, "stdout", "") :
nil
)
nil
end
end
end
Yast::InstFinishClient.new.main