Module: Yast::AutoinstallScriptDialogsInclude

Defined in:
../../src/include/autoinstall/script_dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) initialize_autoinstall_script_dialogs(include_target)



11
12
13
14
15
16
# File '../../src/include/autoinstall/script_dialogs.rb', line 11

def initialize_autoinstall_script_dialogs(include_target)
  textdomain "autoinst"

  Yast.import "Popup"
  Yast.import "AutoinstConfig"
end

- (Object) script_dialog_contents

Script Configuration

Returns:

  • script configuration dialog



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
# File '../../src/include/autoinstall/script_dialogs.rb', line 20

def script_dialog_contents
  allscripts = Builtins.maplist(AutoinstScripts.merged) do |s|
    Item(
      Id(Ops.get_string(s, "filename", "Unknown")),
      Ops.get_string(s, "filename", "Unknown"),
      AutoinstScripts.typeString(Ops.get_string(s, "type", "")),
      Ops.get_string(s, "interpreter", "Unknown")
    )
  end
  contents = VBox(
    Left(Label(_("Available Scripts"))),
    Table(
      Id(:table),
      Opt(:notify),
      Header(_("Script Name"), _("Type"), _("Interpreter")),
      allscripts
    ),
    HBox(
      PushButton(Id(:new), Label.NewButton),
      PushButton(Id(:edit), Label.EditButton),
      PushButton(Id(:delete), Label.DeleteButton)
    )
  )
  deep_copy(contents)
end

- (Symbol) ScriptDialog(mode, name)

Dialog for adding/Editing a script

Parameters:

  • mode (Symbol)

    edit ornew

  • name (String)

    script name

Returns:

  • (Symbol)


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
# File '../../src/include/autoinstall/script_dialogs.rb', line 52

def ScriptDialog(mode, name)
  script = {}
  if mode == :edit
    filtered_scripts = Builtins.filter(AutoinstScripts.merged) do |s|
      Ops.get_string(s, "filename", "") == name
    end
    if Ops.greater_than(Builtins.size(filtered_scripts), 0)
      script = Ops.get_map(filtered_scripts, 0, {})
    end
  end

  # help 1/6
  help = _(
    "\n" +
      "<h3>Preinstallation Scripts</h3>\n" +
      "<P>Add commands to run on the system  before the installation begins. </P>\n"
  )
  # help 2/6
  help = Ops.add(
    help,
    _(
      "\n" +
        "<h3>Postinstallation Scripts</h3>\n" +
        "<P>You can also add commands to execute on the system after the installation\n" +
        "is completed. These scripts are run outside the chroot environment.\n" +
        "</P>"
    )
  )
  # help 3/6
  help = Ops.add(
    help,
    _(
      "\n" +
        "<H3>Chroot Scripts</H3>\n" +
        "<P>For your postinstallation script to run inside the chroot\n" +
        "environment, choose the <i>chroot scripts</i> options. Those scripts are\n" +
        "run before the system reboots for the first time. By default, the chroot \n" +
        "scripts are run in the installation system. To access files in the installed \n" +
        "system, always use the mount point \"/mnt\" in your scripts.\n" +
        "</P>\n"
    )
  )
  # help 4/6
  help = Ops.add(
    help,
    _(
      "\n" +
        "<p>It is possible to run chroot scripts in a later stage after\n" +
        "the boot loader has been configured using the special boolean tag \"chrooted\".\n" +
        "This runs the scripts in the installed system. \n" +
        "</p>\n"
    )
  )
  # help 5/6
  help = Ops.add(
    help,
    _(
      "\n" +
        "<H3>Init Scripts</H3>\n" +
        "<P>These scripts are executed during the initial boot process and after\n" +
        "YaST has finished configuring the system. The final scripts are executed \n" +
        "using a special <b>rc</b> script that is executed only once. \n" +
        "The final scripts are executed toward the end of the boot\n" +
        "process and after network has been initialized.\n" +
        "</P>\n"
    )
  )

  # help 6/6
  help = Ops.add(
    help,
    _(
      "\n" +
        "<H3>Interpreter:</H3>\n" +
        "<P>Preinstallation scripts can only be shell scripts. Do not use <i>Perl</i> or \n" +
        "<i>Python</i> for preinstallation scripts.\n" +
        "</P>\n"
    )
  )
  help = Ops.add(
    help,
    _(
      "\n" +
        "<H3>Network Access:</H3>\n" +
        "<P>While executing postinstallation scripts, the network is disabled and\n" +
        "requires initialization in the scripts to make the network accessible. An\n" +
        "alternative for postinstallation scripts with network is using init scripts, which\n" +
        "guarantee a fully configured system when running the scripts. If you did an installation\n" +
        "over a network, you can use the <b>Network</b> option for the postscript, too.\n" +
        "</P>\n"
    )
  )
  help = Ops.add(
    help,
    _(
      "\n" +
        "<H3>Feedback and Debug:</H3>\n" +
        "<P>All scripts except the init scripts can show STDOUT+STDERR in a pop-up box as feedback.\n" +
        "If you turn on debugging, you get more output in the feedback dialog that might help\n" +
        "you to debug your script.</P>\n"
    )
  )

  title = _("Script Editor")

  contents = VBox(
    HBox(
      TextEntry(
        Id(:filename),
        _("&File Name"),
        Ops.get_string(script, "filename", "")
      ),
      ComboBox(
        Id(:interpreter),
        _("&Interpreter"),
        [
          Item(
            Id("perl"),
            _("Perl"),
            Ops.get_string(script, "interpreter", "shell") == "perl"
          ),
          Item(
            Id("shell"),
            _("Shell"),
            Ops.get_string(script, "interpreter", "shell") == "shell"
          ),
          Item(
            Id("shell"),
            _("Python"),
            Ops.get_string(script, "interpreter", "shell") == "python"
          )
        ]
      ),
      ComboBox(
        Id(:type),
        Opt(:notify),
        _("&Type"),
        [
          Item(
            Id("pre-scripts"),
            "Pre",
            Ops.get_string(script, "type", "") == "pre-scripts"
          ),
          Item(
            Id("chroot-scripts"),
            "Chroot",
            Ops.get_string(script, "type", "") == "chroot-scripts"
          ),
          Item(
            Id("post-scripts"),
            "Post",
            Ops.get_string(script, "type", "") == "post-scripts"
          ),
          Item(
            Id("init-scripts"),
            "Init",
            Ops.get_string(script, "type", "") == "init-scripts"
          )
        ]
      ),
      HStretch(),
      Empty()
    ),
    HBox(
      # a checkbox where you can choose if you want to see script-feedback output or not
      CheckBox(
        Id(:feedback),
        Opt(:notify),
        _("&Feedback"),
        Ops.get_boolean(script, "feedback", false)
      ),
      # a checkbox where you can choose if you want to see script-debug output or not
      CheckBox(
        Id(:debug),
        _("&Debug"),
        Ops.get_boolean(script, "debug", true)
      ),
      CheckBox(
        Id(:chrooted),
        _("&Chrooted"),
        Ops.get_boolean(script, "chrooted", false)
      ),
      # a checkbox where you can choose if you need to have network when the script is running
      CheckBox(
        Id(:network),
        _("&Network"),
        Ops.get_boolean(script, "network_needed", false)
      )
    ),
    HBox(
      # a checkbox where you can choose if you want to see script-feedback output or not
      ComboBox(
        Id(:feedback_type),
        _("&Feedback Type"),
        [
          Item(
            Id(""),
            _("none"),
            Ops.get_string(script, "feedback_type", "") == ""
          ),
          Item(
            Id("message"),
            _("Message"),
            Ops.get_string(script, "feedback_type", "") == "message"
          ),
          Item(
            Id("warning"),
            _("Warning"),
            Ops.get_string(script, "feedback_type", "") == "warning"
          ),
          Item(
            Id("error"),
            _("Error"),
            Ops.get_string(script, "feedback_type", "") == "error"
          )
        ]
      )
    ),
    VSpacing(1),
    HBox(
      TextEntry(
        Id(:notification),
        Opt(:notify),
        _("Text of the notification popup"),
        Ops.get_string(script, "notification", "")
      )
    ),
    HBox(
      TextEntry(
        Id(:location),
        Opt(:notify),
        _("Script Location"),
        Ops.get_string(script, "location", "")
      )
    ),
    HBox(
      MultiLineEdit(
        Id(:source),
        Opt(:notify),
        _("S&cript Source"),
        Ops.get_string(script, "source", "")
      )
    ),
    VSpacing(1),
    HBox(
      PushButton(Id(:save), Label.SaveButton),
      PushButton(Id(:loadsource), _("&Load new source")),
      PushButton(Id(:cancel), Label.CancelButton)
    )
  )

  Wizard.HideNextButton
  Wizard.HideBackButton
  Wizard.HideAbortButton
  Wizard.SetContents(title, contents, help, true, true)
  type = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
  if type == "pre-scripts"
    UI.ChangeWidget(Id(:chrooted), :Enabled, false)
    UI.ChangeWidget(Id(:network), :Enabled, false)
  elsif type == "chroot-scripts"
    UI.ChangeWidget(Id(:network), :Enabled, false)
  elsif type == "post-scripts"
    UI.ChangeWidget(Id(:chrooted), :Enabled, false)
  elsif type == "init-scripts"
    UI.ChangeWidget(Id(:chrooted), :Enabled, false)
    UI.ChangeWidget(Id(:network), :Enabled, false)
    UI.ChangeWidget(Id(:feedback), :Enabled, false)
    UI.ChangeWidget(Id(:notification), :Enabled, false)
  end

  if Ops.greater_than(
      Builtins.size(
        Convert.to_string(UI.QueryWidget(Id(:location), :Value))
      ),
      0
    )
    UI.ChangeWidget(Id(:source), :Enabled, false)
  else
    UI.ChangeWidget(Id(:source), :Enabled, true)
    if Ops.greater_than(
        Builtins.size(
          Convert.to_string(UI.QueryWidget(Id(:source), :Value))
        ),
        0
      )
      UI.ChangeWidget(Id(:location), :Enabled, false)
    end
  end

  if !Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
    UI.ChangeWidget(Id(:feedback_type), :Enabled, false)
  end

  UI.ChangeWidget(Id(:filename), :Enabled, false) if mode == :edit

  ret = :none
  begin
    ret = Convert.to_symbol(UI.UserInput)
    if ret == :save
      scriptName = Convert.to_string(UI.QueryWidget(Id(:filename), :Value))

      type2 = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
      interpreter = Convert.to_string(
        UI.QueryWidget(Id(:interpreter), :Value)
      )
      source = Convert.to_string(UI.QueryWidget(Id(:source), :Value))
      feedback = Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
      feedback_type = Convert.to_string(
        UI.QueryWidget(Id(:feedback_type), :Value)
      )
      debug = Convert.to_boolean(UI.QueryWidget(Id(:debug), :Value))
      chrooted = Convert.to_boolean(UI.QueryWidget(Id(:chrooted), :Value))
      network = Convert.to_boolean(UI.QueryWidget(Id(:network), :Value))
      location = Convert.to_string(UI.QueryWidget(Id(:location), :Value))
      notification = Convert.to_string(
        UI.QueryWidget(Id(:notification), :Value)
      )

      if source == "" && location == "" || scriptName == ""
        Popup.Message(
          _(
            "Provide at least the script\nname and the location or content of the script.\n"
          )
        )
        ret = :again
        next
      else
        AutoinstScripts.AddEditScript(
          scriptName,
          source,
          interpreter,
          type2,
          chrooted,
          debug,
          feedback,
          network,
          feedback_type,
          location,
          notification
        )
      end
    elsif ret == :loadsource
      filename = UI.AskForExistingFile(
        AutoinstConfig.Repository,
        "*",
        _("Select a file to load.")
      )
      if filename != ""
        source = Convert.to_string(
          SCR.Read(path(".target.string"), filename)
        )
        UI.ChangeWidget(Id(:source), :Value, source)
        next
      end
    elsif ret == :type
      type2 = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
      if type2 == "init-scripts"
        UI.ChangeWidget(Id(:feedback), :Enabled, false)
        UI.ChangeWidget(Id(:chrooted), :Enabled, false)
        UI.ChangeWidget(Id(:network), :Enabled, false)
        UI.ChangeWidget(Id(:feedback), :Value, false)
        UI.ChangeWidget(Id(:chrooted), :Value, false)
        UI.ChangeWidget(Id(:network), :Value, false)
        UI.ChangeWidget(Id(:notification), :Enabled, false)
      elsif type2 == "chroot-scripts"
        UI.ChangeWidget(Id(:chrooted), :Enabled, true)
        UI.ChangeWidget(Id(:feedback), :Enabled, true)
        UI.ChangeWidget(Id(:network), :Enabled, false)
        UI.ChangeWidget(Id(:network), :Value, false)
        UI.ChangeWidget(Id(:notification), :Enabled, true)
      elsif type2 == "post-scripts"
        UI.ChangeWidget(Id(:chrooted), :Enabled, false)
        UI.ChangeWidget(Id(:chrooted), :Value, false)
        UI.ChangeWidget(Id(:feedback), :Enabled, true)
        UI.ChangeWidget(Id(:notification), :Enabled, true)
        UI.ChangeWidget(Id(:network), :Enabled, true)
      elsif type2 == "pre-scripts"
        UI.ChangeWidget(Id(:chrooted), :Enabled, false)
        UI.ChangeWidget(Id(:chrooted), :Value, false)
        UI.ChangeWidget(Id(:feedback), :Enabled, true)
        UI.ChangeWidget(Id(:network), :Value, false)
        UI.ChangeWidget(Id(:notification), :Enabled, true)
        UI.ChangeWidget(Id(:network), :Enabled, false)
      end
    elsif ret == :feedback
      UI.ChangeWidget(
        Id(:feedback_type),
        :Enabled,
        Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
      )
      UI.ChangeWidget(Id(:feedback_type), :Value, Id("no_type"))
    end
    if Ops.greater_than(
        Builtins.size(
          Convert.to_string(UI.QueryWidget(Id(:location), :Value))
        ),
        0
      )
      UI.ChangeWidget(Id(:source), :Enabled, false)
    else
      UI.ChangeWidget(Id(:source), :Enabled, true)
    end
    if Ops.greater_than(
        Builtins.size(
          Convert.to_string(UI.QueryWidget(Id(:source), :Value))
        ),
        0
      )
      UI.ChangeWidget(Id(:location), :Enabled, false)
    else
      UI.ChangeWidget(Id(:location), :Enabled, true)
    end
  end until ret == :save || ret == :cancel || ret == :back
  ret
end

- (Symbol) ScriptsDialog

Main dialog

Returns:

  • (Symbol)


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
# File '../../src/include/autoinstall/script_dialogs.rb', line 473

def ScriptsDialog
  help = _(
    "<p>\n" +
      "By adding scripts to the autoinstallation process, customize the installation for\n" +
      "your needs and take control in different stages of the installation.</p>\n"
  )

  title = _("User Script Management")
  Wizard.SetContents(title, script_dialog_contents, help, true, true)

  Wizard.HideAbortButton
  Wizard.SetNextButton(:next, Label.FinishButton)
  ret = nil
  begin
    ret = UI.UserInput

    if ret == :new
      Wizard.CreateDialog
      ScriptDialog(Convert.to_symbol(ret), "")
      Wizard.CloseDialog
    elsif ret == :edit
      name = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))
      if name != nil
        Wizard.CreateDialog
        ScriptDialog(Convert.to_symbol(ret), name)
        Wizard.CloseDialog
      else
        Popup.Message(_("Select a script first."))
        next
      end
    elsif ret == :delete
      name = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))
      if name != nil
        AutoinstScripts.deleteScript(name)
      else
        Popup.Message(_("Select a script first."))
        next
      end
    end
    Wizard.SetContents(title, script_dialog_contents, help, true, true)
  end until ret == :next || ret == :back || ret == :cancel

  Convert.to_symbol(ret)
end