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

yast / yast-autoinstallation / 13435181380

20 Feb 2025 12:22PM UTC coverage: 69.018% (+0.03%) from 68.993%
13435181380

push

github

teclator
Added pervasive encryption fields

6429 of 9315 relevant lines covered (69.02%)

10.35 hits per line

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

12.57
/src/include/autoinstall/dialogs.rb
1
# File:  include/autoinstall/dialogs.ycp
2
# Module:  Auto-Installation Configuration System
3
# Summary:  This module handles the configuration for auto-installation
4
# Authors:  Anas Nashif <nashif@suse.de>
5
# $Id$
6
module Yast
1✔
7
  module AutoinstallDialogsInclude
1✔
8
    def initialize_autoinstall_dialogs(include_target)
1✔
9
      Yast.import "UI"
33✔
10
      textdomain "autoinst"
33✔
11

12
      Yast.import "Label"
33✔
13
      Yast.import "Popup"
33✔
14
      Yast.import "Profile"
33✔
15
      Yast.import "Directory"
33✔
16
      Yast.import "Wizard"
33✔
17
      Yast.import "AutoinstConfig"
33✔
18
      Yast.import "AutoinstClass"
33✔
19
      Yast.import "Package"
33✔
20
      Yast.include include_target, "autoinstall/helps.rb"
33✔
21
    end
22

23
    # Preferences Dialog
24
    # @return [Symbol]
25
    def Settings
1✔
26
      Wizard.CreateDialog
×
27
      Wizard.SetDesktopIcon("org.opensuse.yast.AutoYaST")
×
28
      contents = HVSquash(
×
29
        VBox(
30
          VSquash(
31
            HBox(
32
              TextEntry(
33
                Id(:repository),
34
                _("&Profile Repository:"),
35
                AutoinstConfig.Repository
36
              ),
37
              VBox(
38
                VSpacing(),
39
                Bottom(PushButton(Id(:opendir), _("&Select Directory")))
40
              )
41
            )
42
          ),
43
          VSquash(
44
            HBox(
45
              TextEntry(
46
                Id(:classdir),
47
                _("&Class directory:"),
48
                AutoinstConfig.classDir
49
              ),
50
              VBox(
51
                VSpacing(),
52
                Bottom(PushButton(Id(:openclassdir), _("Select &Directory")))
53
              )
54
            )
55
          )
56
        )
57
      )
58

59
      help = _(
×
60
        "<P>\n" \
61
        "Enter the directory where all <em>control files</em> should be stored in\n" \
62
        "the <b>Repository</b> field.</P>"
63
      )
64

65
      help = Ops.add(
×
66
        help,
67
        _(
68
          "<P>If you are using the classes feature\n" \
69
          "of Autoyast, also enter the class directory. This is where\n" \
70
          "all class files are stored.</p>\n"
71
        )
72
      )
73

74
      Wizard.SetContents(_("Settings"), contents, help, true, true)
×
75

76
      Wizard.HideAbortButton
×
77
      Wizard.RestoreNextButton
×
78

79
      changed = false
×
80
      ret = :none
×
81
      loop do
×
82
        ret = Convert.to_symbol(UI.UserInput)
×
83

84
        new_rep = Convert.to_string(UI.QueryWidget(Id(:repository), :Value))
×
85
        new_classdir = Convert.to_string(UI.QueryWidget(Id(:classdir), :Value))
×
86

87
        case ret
×
88
        when :opendir
89
          new_rep = UI.AskForExistingDirectory(
×
90
            AutoinstConfig.Repository,
91
            _("Select Directory")
92
          )
93
          UI.ChangeWidget(Id(:repository), :Value, new_rep) if new_rep != ""
×
94
          next
×
95
        when :openclassdir
96
          new_classdir = UI.AskForExistingDirectory(
×
97
            AutoinstConfig.classDir,
98
            _("Select Directory")
99
          )
100
          UI.ChangeWidget(Id(:classdir), :Value, new_classdir) if new_classdir != ""
×
101
          next
×
102
        when :next
103
          if AutoinstConfig.Repository != new_rep
×
104
            changed = true
×
105
            AutoinstConfig.Repository = new_rep
×
106
          end
107
          if AutoinstConfig.classDir != new_classdir
×
108
            changed = true
×
109
            # AutoinstConfig::classDir = new_classdir;
110
            AutoinstClass.classDirChanged(new_classdir)
×
111
          end
112
        end
113
        break if ret == :back || ret == :next
×
114
      end
115

116
      Wizard.RestoreScreenShotName
×
117
      AutoinstConfig.Save if changed
×
118
      Wizard.CloseDialog
×
119
      ret
×
120
    end
121

122
    # Check validity of file name
123
    #
124
    # @param name [String] file name
125
    # @return [Integer] 0 if valid, -1 if not.
126
    def checkFileName(name)
1✔
127
      if name !=
×
128
          Builtins.filterchars(
129
            name,
130
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
131
          ) ||
132
          Ops.greater_than(Builtins.size(name), 127)
133
        return -1
×
134
      end
135

136
      0
×
137
    end
138

139
    # Return a message about invalid file names
140
    #
141
    # @return [String] message
142
    def invalidFileName
1✔
143
      _(
×
144
        "Invalid file name.\n" \
145
        "Names can only contain letters, numbers, and underscore,\n" \
146
        "must begin with letter, and must be\n" \
147
        "127 characters long or less.\n"
148
      )
149
    end
150

151
    # Popup for a new file name
152
    # @param [String] caption
153
    # @param [String] textentry
154
    # @return [String] new file name
155
    def NewFileName(caption, textentry)
1✔
156
      con = HBox(
×
157
        HSpacing(1),
158
        VBox(
159
          VSpacing(0.2),
160
          # Translators: popup dialog heading
161
          Heading(caption),
162
          #  _("&New Profile Name") _("New Profile")
163
          # Translators: text entry label
164
          Left(TextEntry(Id(:newname), textentry, "")),
165
          VSpacing(0.2),
166
          ButtonBox(
167
            PushButton(Id(:ok), Opt(:default), Label.OKButton),
168
            PushButton(Id(:cancel), Label.CancelButton)
169
          ),
170
          VSpacing(0.2)
171
        ),
172
        HSpacing(1)
173
      )
174

175
      UI.OpenDialog(Opt(:decorated), con)
×
176
      UI.SetFocus(Id(:newname))
×
177
      f = ""
×
178
      ret = nil
×
179
      loop do
×
180
        ret = UI.UserInput
×
181
        case ret
×
182
        when :cancel
183
          break
×
184
        when :ok
185
          f = Convert.to_string(UI.QueryWidget(Id(:newname), :Value))
×
186
          if checkFileName(f) != 0 || f == ""
×
187
            Popup.Error(invalidFileName)
×
188
            next
×
189
          end
190
          break
×
191
        end
192
      end
193

194
      UI.CloseDialog
×
195

196
      (ret == :ok) ? f : ""
×
197
    end
198

199
    # Clone running system
200
    # @return [Symbol]
201
    def cloneSystem
1✔
202
      Yast.import "AutoinstClone"
×
203
      Yast.import "Profile"
×
204

205
      Wizard.CreateDialog
×
206
      Wizard.SetDesktopIcon("org.opensuse.yast.CloneSystem")
×
207

208
      # title
209
      title = _("Create a Reference Control File")
×
210
      items = AutoinstClone.createClonableList
×
211
      contents = VBox(
×
212
        MultiSelectionBox(Id(:res), _("Select Additional Resources:"), items)
213
      )
214

215
      Wizard.SetContents(
×
216
        title,
217
        contents,
218
        Ops.get_string(@HELPS, "clone", ""),
219
        true,
220
        true
221
      )
222
      Wizard.HideAbortButton
×
223
      Wizard.SetNextButton(:next, Label.CreateButton)
×
224

225
      ret = :none
×
226
      loop do
×
227
        ret = Convert.to_symbol(UI.UserInput)
×
228
        if ret == :next
×
229
          AutoinstClone.additional = Convert.convert(
×
230
            UI.QueryWidget(Id(:res), :SelectedItems),
231
            from: "any",
232
            to:   "list <string>"
233
          )
234
          Popup.ShowFeedback(
×
235
            _("Collecting system data..."),
236
            _("This may take a while...")
237
          )
238
          AutoinstClone.Process
×
239
          Profile.changed = true
×
240
          Popup.ClearFeedback
×
241
        end
242
        break if ret == :next || ret == :back
×
243
      end
244
      Wizard.CloseDialog
×
245
      ret
×
246
    end
247

248
    def UpdateValidDialog(summary, log)
1✔
249
      UI.ChangeWidget(Id(:richtext), :Value, summary)
×
250
      UI.ChangeWidget(Id(:log), :LastLine, log)
×
251

252
      nil
×
253
    end
254

255
    # Validate Dialog
256
    # @return [Symbol]
257
    def ValidDialog
1✔
258
      Yast.import "Summary"
×
259
      Yast.import "HTML"
×
260
      Wizard.CreateDialog
×
261
      contents = VBox(
×
262
        RichText(Id(:richtext), Opt(:autoScrollDown), ""),
263
        LogView(Id(:log), "", 5, 100)
264
      )
265
      Wizard.SetContents(
×
266
        _("Check profile validity"),
267
        contents,
268
        Ops.get_string(@HELPS, "valid", ""),
269
        true,
270
        true
271
      )
272
      Builtins.y2milestone("Checking validity")
×
273
      Wizard.HideAbortButton
×
274
      Wizard.HideBackButton
×
275
      UI.ChangeWidget(Id(:next), :Label, Label.FinishButton)
×
276

277
      sectionFiles = Profile.SaveSingleSections(AutoinstConfig.tmpDir)
×
278
      Builtins.y2debug("Got section map: %1", sectionFiles)
×
279

280
      html_ok = HTML.Colorize(_("OK"), "green")
×
281
      html_ko = HTML.Colorize(_("Error"), "red")
×
282
      html_warn = HTML.Colorize(_("Warning"), "yellow")
×
283
      summary = ""
×
284

285
      # some of these can be commented out for the release
286
      validators = [
287
        #     [
288
        #   _("Checking XML without validation..."),
289
        #   "/usr/bin/xmllint --noout",
290
        #   ],
291
        #       [
292
        #     _("Checking XML with DTD validation..."),
293
        #     "/usr/bin/xmllint --noout --valid"
294
        #     ],
295
        [
296
          _("Checking XML with RNG validation..."),
×
297
          Ops.add(
298
            Ops.add(
299
              "/usr/bin/xmllint --noout --relaxng ",
300
              # was: /usr/share/autoinstall/rng/profile.rng
301
              Directory.schemadir
302
            ),
303
            "/autoyast/rng/profile.rng"
304
          )
305
        ]
306
      ]
307

308
      # section wise validation
309
      Builtins.foreach(validators) do |i|
×
310
        header = Ops.get_string(i, 0, "")
×
311
        summary = Summary.AddHeader(summary, header)
×
312
        UpdateValidDialog(summary, "")
×
313
        summary = Summary.OpenList(summary)
×
314
        Builtins.foreach(sectionFiles) do |section, sectionFile|
×
315
          cmd = Ops.add(Ops.add(Ops.get_string(i, 1, ""), " "), sectionFile)
×
316
          summary = Ops.add(
×
317
            Ops.add(summary, "<li>"),
318
            Builtins.sformat(_("Section %1: "), section)
319
          )
320
          UpdateValidDialog(summary, Ops.add(Ops.add("\n", cmd), "\n"))
×
321
          o = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
×
322
          Builtins.y2debug("validation output: %1", o)
×
323
          summary = Ops.add(
×
324
            summary,
325
            if Ops.get_integer(o, "exit", 1) != 0 ||
×
326
              (Ops.get_string(i, 2, "") == "jing sucks" &&
×
327
                Ops.greater_than(
328
                  Builtins.size(Ops.get_string(o, "stderr", "")),
329
                  0
330
                ))
331
              html_ko
×
332
            else
333
              html_ok
×
334
            end
335
          )
336
          UpdateValidDialog(summary, Ops.get_string(o, "stderr", ""))
×
337
        end
338
        summary = Summary.CloseList(summary)
×
339
      end
340

341
      # jing validation -- validates complete xml profile
342
      if Package.Installed("jing")
×
343
        complete_xml_file = Ops.add(
×
344
          Ops.add(AutoinstConfig.tmpDir, "/"),
345
          "valid.xml"
346
        )
347
        Profile.Save(complete_xml_file)
×
348
        validator = [
349
          _("Checking XML with RNC validation..."),
×
350
          Ops.add(
351
            Ops.add("/usr/bin/jing >&2 -c ", Directory.schemadir),
352
            "/autoyast/rnc/profile.rnc"
353
          ),
354
          "jing sucks"
355
        ]
356
        header = Ops.get_string(validator, 0, "")
×
357
        summary = Summary.AddHeader(summary, header)
×
358
        UpdateValidDialog(summary, "")
×
359
        cmd = Ops.add(
×
360
          Ops.add(Ops.get_string(validator, 1, ""), " "),
361
          complete_xml_file
362
        )
363
        UpdateValidDialog(summary, Ops.add(Ops.add("\n", cmd), "\n"))
×
364
        o = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
×
365
        Builtins.y2debug("validation output: %1", o)
×
366
        summary = Ops.add(
×
367
          summary,
368
          if Ops.get_integer(o, "exit", 1) != 0 ||
×
369
            Ops.greater_than(Builtins.size(Ops.get_string(o, "stderr", "")), 0)
370
            html_ko
×
371
          else
372
            html_ok
×
373
          end
374
        )
375
        UpdateValidDialog(summary, Ops.get_string(o, "stderr", ""))
×
376
      end
377

378
      logicOk = true
×
379
      rootOk = false
×
380
      if Builtins.haskey(Profile.current, "users")
×
381
        Builtins.foreach(Ops.get_list(Profile.current, "users", [])) do |u|
×
382
          if Ops.get_string(u, "username", "") == "root" &&
×
383
              Builtins.haskey(u, "user_password")
384
            rootOk = true
×
385
          end
386
        end
387
      end
388
      # the autoyast interface can check if the profile is logical or if important stuff is missing
389
      # the missing stuff is under the Label "Logic"
390
      summary = Summary.AddHeader(summary, _("Logic"))
×
391
      if !rootOk
×
392
        # the autoyast config frontend can check if a root password is configured
393
        # and can warn the user if it is missing
394
        summary = Ops.add(
×
395
          Ops.add(Ops.add(summary, html_warn), " "),
396
          _("No root password configured")
397
        )
398
        logicOk = false
×
399
      end
400

401
      summary = Ops.add(summary, html_ok) if logicOk
×
402
      UpdateValidDialog(summary, "")
×
403

404
      ret = nil
×
405
      loop do
×
406
        ret = UI.UserInput
×
407
        case ret
×
408
        when :next, :back, :abort
409
          break
×
410
        end
411
      end
412

413
      Wizard.CloseDialog
×
414
      Convert.to_symbol(ret)
×
415
    end
416
  end
417
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

© 2026 Coveralls, Inc