• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-autoinstallation / 7347071288

28 Dec 2023 11:13AM UTC coverage: 69.009% (+0.4%) from 68.607%
7347071288

push

github

web-flow
Merge pull request #874 from yast/rubocop_update

Rubocop update

94 of 254 new or added lines in 51 files covered. (37.01%)

22 existing lines in 13 files now uncovered.

6373 of 9235 relevant lines covered (69.01%)

10.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.02
/src/include/autoinstall/script_dialogs.rb
1
# File:  clients/autoinst_scripts.ycp
2
# Package:  Autoinstallation Configuration System
3
# Summary:  Scripts
4
# Authors:  Anas Nashif<nashif@suse.de>
5
#
6
# $Id$
7
module Yast
1✔
8
  module AutoinstallScriptDialogsInclude
1✔
9
    def initialize_autoinstall_script_dialogs(_include_target)
1✔
10
      textdomain "autoinst"
10✔
11

12
      Yast.import "Popup"
10✔
13
      Yast.import "AutoinstConfig"
10✔
14
    end
15

16
    # Script Configuration
17
    # @return  script configuration dialog
18
    def script_dialog_contents
1✔
19
      allscripts = AutoinstScripts.scripts.map do |s|
9✔
20
        Item(
×
21
          Id(s.filename),
22
          s.filename,
23
          AutoinstScripts.typeString(s.class.type),
24
          # init scripts does not have interpreter. Is it correct?
25
          s.respond_to?(:interpreter) ? s.interpreter : ""
×
26
        )
27
      end
28
      contents = VBox(
9✔
29
        Left(Label(_("Available Scripts"))),
30
        Table(
31
          Id(:table),
32
          Opt(:notify),
33
          Header(_("Script Name"), _("Type"), _("Interpreter")),
34
          allscripts
35
        ),
36
        HBox(
37
          PushButton(Id(:new), Label.NewButton),
38
          PushButton(Id(:edit), Label.EditButton),
39
          PushButton(Id(:delete), Label.DeleteButton)
40
        )
41
      )
42
      deep_copy(contents)
9✔
43
    end
44

45
    # Dialog for adding/Editing  a script
46
    # @param [Symbol] mode `edit or `new
47
    # @param [String] name script name
48
    # @return [Symbol]
49

50
    def ScriptDialog(mode, name)
1✔
51
      script = {}
1✔
52
      if mode == :edit
1✔
53
        script_o = AutoinstScripts.scripts.find { |s| s.filename == name }
×
54
        if script_o
×
55
          script = script_o.to_hash
×
56
          script["type"] = script_o.class.type
×
57
        end
58
      end
59

60
      # help 1/6
61
      help = _(
1✔
62
        "\n" \
63
        "<h3>Preinstallation Scripts</h3>\n" \
64
        "<P>Add commands to run on the system  before the installation begins. </P>\n"
65
      )
66
      # help 2/6
67
      help = Ops.add(
1✔
68
        help,
69
        _(
70
          "\n" \
71
          "<h3>Postinstallation Scripts</h3>\n" \
72
          "<P>You can also add commands to execute on the system after the installation\n" \
73
          "is completed. These scripts are run outside the chroot environment.\n" \
74
          "</P>"
75
        )
76
      )
77
      # help 3/6
78
      help = Ops.add(
1✔
79
        help,
80
        _(
81
          "\n" \
82
          "<H3>Chroot Scripts</H3>\n" \
83
          "<P>For your postinstallation script to run inside the chroot\n" \
84
          "environment, choose the <i>chroot scripts</i> options. Those scripts are\n" \
85
          "run before the system reboots for the first time. By default, the chroot \n" \
86
          "scripts are run in the installation system. To access files in the installed \n" \
87
          "system, always use the mount point \"/mnt\" in your scripts.\n" \
88
          "</P>\n"
89
        )
90
      )
91
      # help 4/6
92
      help = Ops.add(
1✔
93
        help,
94
        _(
95
          "\n" \
96
          "<p>It is possible to run chroot scripts in a later stage after\n" \
97
          "the boot loader has been configured using the special boolean tag \"chrooted\".\n" \
98
          "This runs the scripts in the installed system. \n" \
99
          "</p>\n"
100
        )
101
      )
102
      # help 5/6
103
      help = Ops.add(
1✔
104
        help,
105
        _(
106
          "\n" \
107
          "<H3>Init Scripts</H3>\n" \
108
          "<P>These scripts are executed during the initial boot process and after\n" \
109
          "YaST has finished configuring the system. The final scripts are executed \n" \
110
          "using a special <b>rc</b> script that is executed only once. \n" \
111
          "The final scripts are executed toward the end of the boot\n" \
112
          "process and after network has been initialized.\n" \
113
          "</P>\n"
114
        )
115
      )
116

117
      # help 6/6
118
      help = Ops.add(
1✔
119
        help,
120
        _(
121
          "\n" \
122
          "<H3>Interpreter:</H3>\n" \
123
          "<P>Preinstallation scripts can only be shell scripts. Do not use <i>Perl</i> or \n" \
124
          "<i>Python</i> for preinstallation scripts.\n" \
125
          "</P>\n"
126
        )
127
      )
128
      help = Ops.add(
1✔
129
        help,
130
        _(
131
          "\n" \
132
          "<H3>Feedback and Debug:</H3>\n" \
133
          "<P>All scripts except the init scripts can show STDOUT+STDERR " \
134
          "in a pop-up box as feedback.\n" \
135
          "If you turn on debugging, you get more output in the " \
136
          "feedback dialog that might help\n" \
137
          "you to debug your script.</P>\n"
138
        )
139
      )
140

141
      title = _("Script Editor")
1✔
142

143
      contents = VBox(
1✔
144
        HBox(
145
          TextEntry(
146
            Id(:filename),
147
            _("&File Name"),
148
            Ops.get_string(script, "filename", "")
149
          ),
150
          ComboBox(
151
            Id(:interpreter),
152
            Opt(:editable),
153
            _("&Interpreter"),
154
            [
155
              Item(
156
                Id("perl"),
157
                _("Perl"),
158
                Ops.get_string(script, "interpreter", "shell") == "perl"
159
              ),
160
              Item(
161
                Id("shell"),
162
                _("Shell"),
163
                Ops.get_string(script, "interpreter", "shell") == "shell"
164
              ),
165
              Item(
166
                Id("shell"),
167
                _("Python"),
168
                Ops.get_string(script, "interpreter", "shell") == "python"
169
              )
170
            ]
171
          ),
172
          ComboBox(
173
            Id(:type),
174
            Opt(:notify),
175
            _("&Type"),
176
            [
177
              Item(
178
                Id("pre-scripts"),
179
                # TRANSLATORS: Pre installation script type
180
                _("Pre"),
181
                Ops.get_string(script, "type", "") == "pre-scripts"
182
              ),
183
              Item(
184
                # TRANSLATORS: Post partitioning installation script type
185
                Id("postpartitioning-scripts"),
186
                _("PostPartitioning"),
187
                Ops.get_string(script, "type", "") == "post-scripts"
188
              ),
189
              Item(
190
                Id("chroot-scripts"),
191
                # TRANSLATORS: Change root installation script type
192
                _("Chroot"),
193
                Ops.get_string(script, "type", "") == "chroot-scripts"
194
              ),
195
              Item(
196
                Id("post-scripts"),
197
                # TRANSLATORS: Post installation script type
198
                _("Post"),
199
                Ops.get_string(script, "type", "") == "post-scripts"
200
              ),
201
              Item(
202
                Id("init-scripts"),
203
                # TRANSLATORS: Init system post installation script type
204
                _("Init"),
205
                Ops.get_string(script, "type", "") == "init-scripts"
206
              )
207
            ]
208
          ),
209
          HStretch(),
210
          Empty()
211
        ),
212
        HBox(
213
          # a checkbox where you can choose if you want to see script-feedback output or not
214
          CheckBox(
215
            Id(:feedback),
216
            Opt(:notify),
217
            _("&Feedback"),
218
            Ops.get_boolean(script, "feedback", false)
219
          ),
220
          # a checkbox where you can choose if you want to see script-debug output or not
221
          CheckBox(
222
            Id(:debug),
223
            _("&Debug"),
224
            Ops.get_boolean(script, "debug", true)
225
          ),
226
          CheckBox(
227
            Id(:chrooted),
228
            _("&Chrooted"),
229
            Ops.get_boolean(script, "chrooted", false)
230
          )
231
        ),
232
        HBox(
233
          # a checkbox where you can choose if you want to see script-feedback output or not
234
          ComboBox(
235
            Id(:feedback_type),
236
            _("&Feedback Type"),
237
            [
238
              Item(
239
                Id(""),
240
                _("none"),
241
                Ops.get_string(script, "feedback_type", "") == ""
242
              ),
243
              Item(
244
                Id("message"),
245
                _("Message"),
246
                Ops.get_string(script, "feedback_type", "") == "message"
247
              ),
248
              Item(
249
                Id("warning"),
250
                _("Warning"),
251
                Ops.get_string(script, "feedback_type", "") == "warning"
252
              ),
253
              Item(
254
                Id("error"),
255
                _("Error"),
256
                Ops.get_string(script, "feedback_type", "") == "error"
257
              )
258
            ]
259
          )
260
        ),
261
        VSpacing(1),
262
        HBox(
263
          TextEntry(
264
            Id(:notification),
265
            Opt(:notify),
266
            _("Text of the notification popup"),
267
            Ops.get_string(script, "notification", "")
268
          )
269
        ),
270
        HBox(
271
          TextEntry(
272
            Id(:location),
273
            Opt(:notify),
274
            _("Script Location"),
275
            Ops.get_string(script, "location", "")
276
          )
277
        ),
278
        HBox(
279
          MultiLineEdit(
280
            Id(:source),
281
            Opt(:notify),
282
            _("S&cript Source"),
283
            Ops.get_string(script, "source", "")
284
          )
285
        ),
286
        VSpacing(1),
287
        HBox(
288
          PushButton(Id(:save), Label.SaveButton),
289
          PushButton(Id(:loadsource), _("&Load new source")),
290
          PushButton(Id(:cancel), Label.CancelButton)
291
        )
292
      )
293

294
      Wizard.HideNextButton
1✔
295
      Wizard.HideBackButton
1✔
296
      Wizard.HideAbortButton
1✔
297
      Wizard.SetContents(title, contents, help, true, true)
1✔
298
      type = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
1✔
299
      case type
1✔
300
      when "pre-scripts", "post-scripts"
UNCOV
301
        UI.ChangeWidget(Id(:chrooted), :Enabled, false)
×
302
      when "init-scripts"
303
        UI.ChangeWidget(Id(:chrooted), :Enabled, false)
×
304
        UI.ChangeWidget(Id(:feedback), :Enabled, false)
×
305
        UI.ChangeWidget(Id(:notification), :Enabled, false)
×
306
      end
307

308
      if Ops.greater_than(
1✔
309
        Builtins.size(
310
          Convert.to_string(UI.QueryWidget(Id(:location), :Value))
311
        ),
312
        0
313
      )
314
        UI.ChangeWidget(Id(:source), :Enabled, false)
×
315
      else
316
        UI.ChangeWidget(Id(:source), :Enabled, true)
1✔
317
        if Ops.greater_than(
1✔
318
          Builtins.size(
319
            Convert.to_string(UI.QueryWidget(Id(:source), :Value))
320
          ),
321
          0
322
        )
323
          UI.ChangeWidget(Id(:location), :Enabled, false)
×
324
        end
325
      end
326

327
      if !Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
1✔
328
        UI.ChangeWidget(Id(:feedback_type), :Enabled, false)
1✔
329
      end
330

331
      UI.ChangeWidget(Id(:filename), :Enabled, false) if mode == :edit
1✔
332

333
      ret = :none
1✔
334
      loop do
1✔
335
        ret = Convert.to_symbol(UI.UserInput)
1✔
336
        case ret
1✔
337
        when :save
338
          scriptName = Convert.to_string(UI.QueryWidget(Id(:filename), :Value))
1✔
339

340
          type2 = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
1✔
341
          interpreter = Convert.to_string(
1✔
342
            UI.QueryWidget(Id(:interpreter), :Value)
343
          )
344
          source = Convert.to_string(UI.QueryWidget(Id(:source), :Value))
1✔
345
          feedback = Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
1✔
346
          feedback_type = Convert.to_string(
1✔
347
            UI.QueryWidget(Id(:feedback_type), :Value)
348
          )
349
          debug = Convert.to_boolean(UI.QueryWidget(Id(:debug), :Value))
1✔
350
          chrooted = Convert.to_boolean(UI.QueryWidget(Id(:chrooted), :Value))
1✔
351
          location = Convert.to_string(UI.QueryWidget(Id(:location), :Value))
1✔
352
          notification = Convert.to_string(
1✔
353
            UI.QueryWidget(Id(:notification), :Value)
354
          )
355

356
          if (source == "" && location == "") || scriptName == ""
1✔
357
            Popup.Message(
×
358
              _(
359
                "Provide at least the script\nname and the location or content of the script.\n"
360
              )
361
            )
362
            ret = :again
×
363
            next
×
364
          else
365
            AutoinstScripts.AddEditScript(
1✔
366
              scriptName,
367
              source,
368
              interpreter,
369
              type2,
370
              chrooted,
371
              debug,
372
              feedback,
373
              feedback_type,
374
              location,
375
              notification
376
            )
377
          end
378
        when :loadsource
379
          filename = UI.AskForExistingFile(
×
380
            AutoinstConfig.Repository,
381
            "*",
382
            _("Select a file to load.")
383
          )
384
          if filename != ""
×
385
            source = Convert.to_string(
×
386
              SCR.Read(path(".target.string"), filename)
387
            )
388
            UI.ChangeWidget(Id(:source), :Value, source)
×
389
            next
×
390
          end
391
        when :type
392
          type2 = Convert.to_string(UI.QueryWidget(Id(:type), :Value))
×
NEW
393
          case type2
×
394
          when "init-scripts"
395
            UI.ChangeWidget(Id(:feedback), :Enabled, false)
×
396
            UI.ChangeWidget(Id(:chrooted), :Enabled, false)
×
397
            UI.ChangeWidget(Id(:feedback), :Value, false)
×
398
            UI.ChangeWidget(Id(:chrooted), :Value, false)
×
399
            UI.ChangeWidget(Id(:notification), :Enabled, false)
×
400
          when "chroot-scripts"
401
            UI.ChangeWidget(Id(:chrooted), :Enabled, true)
×
402
            UI.ChangeWidget(Id(:feedback), :Enabled, true)
×
403
            UI.ChangeWidget(Id(:notification), :Enabled, true)
×
404
          when "post-scripts", "pre-scripts"
405
            UI.ChangeWidget(Id(:chrooted), :Enabled, false)
×
406
            UI.ChangeWidget(Id(:chrooted), :Value, false)
×
407
            UI.ChangeWidget(Id(:feedback), :Enabled, true)
×
408
            UI.ChangeWidget(Id(:notification), :Enabled, true)
×
409
          end
410
        when :feedback
411
          UI.ChangeWidget(
×
412
            Id(:feedback_type),
413
            :Enabled,
414
            Convert.to_boolean(UI.QueryWidget(Id(:feedback), :Value))
415
          )
416
          UI.ChangeWidget(Id(:feedback_type), :Value, Id("no_type"))
×
417
        end
418
        if Ops.greater_than(
1✔
419
          Builtins.size(
420
            Convert.to_string(UI.QueryWidget(Id(:location), :Value))
421
          ),
422
          0
423
        )
424
          UI.ChangeWidget(Id(:source), :Enabled, false)
×
425
        else
426
          UI.ChangeWidget(Id(:source), :Enabled, true)
1✔
427
        end
428
        if Ops.greater_than(
1✔
429
          Builtins.size(
430
            Convert.to_string(UI.QueryWidget(Id(:source), :Value))
431
          ),
432
          0
433
        )
434
          UI.ChangeWidget(Id(:location), :Enabled, false)
×
435
        else
436
          UI.ChangeWidget(Id(:location), :Enabled, true)
1✔
437
        end
438
        break if ret == :save || ret == :cancel || ret == :back
1✔
439
      end
440
      ret
1✔
441
    end
442

443
    # Main dialog
444
    # @return [Symbol]
445
    def ScriptsDialog
1✔
446
      help = _(
4✔
447
        "<p>\n" \
448
        "By adding scripts to the autoinstallation process, customize the installation for\n" \
449
        "your needs and take control in different stages of the installation.</p>\n"
450
      )
451

452
      title = _("User Script Management")
4✔
453
      Wizard.SetContents(title, script_dialog_contents, help, true, true)
4✔
454

455
      Wizard.HideAbortButton
4✔
456
      Wizard.SetNextButton(:next, Label.FinishButton)
4✔
457
      ret = nil
4✔
458
      loop do
4✔
459
        ret = UI.UserInput
5✔
460

461
        case ret
5✔
462
        when :new
463
          Wizard.CreateDialog
1✔
464
          ScriptDialog(Convert.to_symbol(ret), "")
1✔
465
          Wizard.CloseDialog
1✔
466
        when :edit
467
          name = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))
×
NEW
468
          if name.nil?
×
NEW
469
            Popup.Message(_("Select a script first."))
×
NEW
470
            next
×
471
          else
472
            Wizard.CreateDialog
×
473
            ScriptDialog(Convert.to_symbol(ret), name)
×
474
            Wizard.CloseDialog
×
475
          end
476
        when :delete
477
          name = Convert.to_string(UI.QueryWidget(Id(:table), :CurrentItem))
×
NEW
478
          if name.nil?
×
479
            Popup.Message(_("Select a script first."))
×
480
            next
×
481
          else
NEW
482
            AutoinstScripts.deleteScript(name)
×
483
          end
484
        end
485
        Wizard.SetContents(title, script_dialog_contents, help, true, true)
5✔
486
        break if ret == :next || ret == :back || ret == :cancel
5✔
487
      end
488

489
      Convert.to_symbol(ret)
4✔
490
    end
491
  end
492
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc