Class: Yast::SupportClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Support.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



169
170
171
172
# File '../../src/modules/Support.rb', line 169

def Abort
  return @AbortFunction.call == true if @AbortFunction != nil
  false
end

- (Object) AskForRootPwd



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
# File '../../src/modules/Support.rb', line 138

def AskForRootPwd
  while @root_pw == nil
    UI.OpenDialog(
      VBox(
        Label(_("To continue, enter root password")),
        Password(Id(:passwd), _("root Password")),
        ButtonBox(
          PushButton(
            Id(:ok),
            Opt(:okButton, :default, :key_F10),
            Label.OKButton
          ),
          PushButton(
            Id(:cancel),
            Opt(:cancelButton, :key_F9),
            Label.CancelButton
          )
        )
      )
    )
    input = Convert.to_symbol(UI.UserInput)
    pw = Convert.to_string(UI.QueryWidget(Id(:passwd), :Value))
    UI.CloseDialog
    return false if input == :cancel
    Report.Error(_("Password incorrect")) if !CheckRootPw(pw)
  end
  true
end

- (Hash) AutoPackages

Return packages needed to be installed and removed during Autoinstallation to insure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



444
445
446
447
# File '../../src/modules/Support.rb', line 444

def AutoPackages
  # TODO FIXME: your code here...
  { "install" => [], "remove" => [] }
end

- (Object) CheckRootPw(pw)



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
# File '../../src/modules/Support.rb', line 90

def CheckRootPw(pw)
  if @pwd_file == nil
    @pwd_file = Ops.add(
      Convert.to_string(SCR.Read(path(".target.tmpdir"))),
      "/pwd_file"
    )
  end
  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat("test -e %1 || touch %1", @pwd_file)
  )
  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat("chmod 600 %1", @pwd_file)
  )
  SCR.Write(path(".target.string"), @pwd_file, Ops.add(pw, "\n"))
  exit = Convert.to_integer(
    SCR.Execute(
      path(".target.bash"),
      Builtins.sformat("cat %1 | su -c 'echo 0'", @pwd_file)
    )
  )
  SCR.Write(path(".target.string"), @pwd_file, "")
  success = exit == 0
  Builtins.y2milestone("Root password check: %1", success)
  @root_pw = pw if success
  success
end

- (Hash) Export

Dump the support settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



420
421
422
423
# File '../../src/modules/Support.rb', line 420

def Export
  # TODO FIXME: your code here (return the above mentioned variables)...
  {}
end

- (Object) GetParameterList



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
# File '../../src/modules/Support.rb', line 218

def GetParameterList
  parameters = ""
  parameters = Builtins.sformat("%1 %2", parameters, "-D") if @use_defaults
  if @full_listening
    parameters = Builtins.sformat("%1 %2", parameters, "-L")
  end
  if @exclude_disk_scan
    parameters = Builtins.sformat("%1 %2", parameters, "-d")
  end
  if @search_for_edir
    parameters = Builtins.sformat("%1 %2", parameters, "-e")
  end
  parameters = Builtins.sformat("%1 %2", parameters, "-A") if @full_logging
  parameters = Builtins.sformat("%1 %2", parameters, "-m") if @minimal_logs
  parameters = Builtins.sformat("%1 %2", parameters, "-s") if @include_slp
  parameters = Builtins.sformat("%1 %2", parameters, "-v") if @rpm_check
  parameters = Builtins.sformat("%1 %2", parameters, "-l") if @additional_logs
  if Ops.greater_than(Builtins.size(@novell_number), 0)
    parameters = Builtins.sformat(
      "%1 %2 %3",
      parameters,
      "-r",
      @novell_number
    )
  end
  Builtins.y2milestone("Create parameter list : %1", parameters)
  parameters
end

- (Boolean) Import(settings)

Get all support settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



411
412
413
414
415
# File '../../src/modules/Support.rb', line 411

def Import(settings)
  settings = deep_copy(settings)
  # TODO FIXME: your code here (fill the above mentioned variables)...
  true
end

- (Object) main



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
# File '../../src/modules/Support.rb', line 35

def main
  Yast.import "UI"
  textdomain "support"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Map"
  Yast.import "PackageSystem"
  Yast.import "Label"

  # Data was modified?
  @modified = false


  @proposal_valid = false

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")

  # root password for running supportconfig if module run as non-root
  @root_pw = nil

  @pwd_file = nil

  # content of /etc/supportconfig.conf
  @configuration = {}

  # options parsed from configuration map
  @options = {}

  # command line parameters for support
  @use_defaults = false
  @full_listening = false
  @exclude_disk_scan = false
  @search_for_edir = false
  @full_logging = false
  @minimal_logs = false
  @include_slp = false
  @rpm_check = false
  @additional_logs = false
  @novell_number = ""

  @log_files = {}
  #global string created_directory="";

  @browser = nil
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



176
177
178
179
# File '../../src/modules/Support.rb', line 176

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



435
436
437
438
# File '../../src/modules/Support.rb', line 435

def Overview
  # TODO FIXME: your code here...
  []
end

- (Object) ProposalValid



188
189
190
# File '../../src/modules/Support.rb', line 188

def ProposalValid
  @proposal_valid
end

- (Object) Read

Read all support settings

Returns:

  • true on success



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
# File '../../src/modules/Support.rb', line 264

def Read
  # Support read dialog caption
  caption = _("Initializing Support Configuration")

  @configuration = Convert.to_map(SCR.Read(path(".etc.supportconfig.all")))
  Builtins.foreach(Ops.get_list(@configuration, "value", [])) do |row|
    Ops.set(
      @options,
      Ops.get_string(row, "name", ""),
      Ops.get_string(row, "value", "")
    )
  end
  # Error message
  Report.Error(Message.CannotReadCurrentSettings) if false

  # read current settings
  if PackageSystem.Installed("MozillaFirefox")
    @browser = "firefox"
  elsif PackageSystem.Installed("kde4-konqueror") ||
      PackageSystem.Installed("kdebase3")
    @browser = "konqueror"
  elsif PackageSystem.Installed("opera")
    @browser = "opera"
  else
    Builtins.y2error("Couldn't find any supported browser installed.")
  end
  # Error message
  Report.Error(Message.CannotReadCurrentSettings) if false

  return false if Abort()
  @log_files = {
    "tmp_dir" => Convert.to_string(SCR.Read(path(".target.tmpdir")))
  }
  @modified = false
  true
end

- (Object) SetAbortFunction(function)



211
212
213
214
215
216
# File '../../src/modules/Support.rb', line 211

def SetAbortFunction(function)
  function = deep_copy(function)
  @AbortFunction = deep_copy(function)

  nil
end

- (Object) SetModified(value)

Mark as modified, for Autoyast.



182
183
184
185
186
# File '../../src/modules/Support.rb', line 182

def SetModified(value)
  @modified = true

  nil
end

- (Object) SetProposalValid(value)



192
193
194
195
196
# File '../../src/modules/Support.rb', line 192

def SetProposalValid(value)
  @proposal_valid = value

  nil
end

- (Object) SetWriteOnly(value)

Set write_only flag (for autoinstalation).



204
205
206
207
208
# File '../../src/modules/Support.rb', line 204

def SetWriteOnly(value)
  @write_only = value

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



427
428
429
430
431
# File '../../src/modules/Support.rb', line 427

def Summary
  # TODO FIXME: your code here...
  # Configuration summary text for autoyast
  [_("Configuration summary..."), []]
end

- (Object) WhoAmI



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File '../../src/modules/Support.rb', line 119

def WhoAmI
  if Ops.less_or_equal(
      Convert.to_integer(SCR.Read(path(".target.size"), "/usr/bin/id")),
      0
    )
    Builtins.y2warning("/usr/bin/id not existing, supposing to be root")
    return 0
  end

  out = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "/usr/bin/id --user")
  )
  lines = Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
  strid = Ops.get(lines, 0, "")
  id = Builtins.tointeger(strid)
  return 0 if id == nil
  id
end

- (Object) Write

Write all support settings

Returns:

  • true on success



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
# File '../../src/modules/Support.rb', line 303

def Write
  # Support read dialog caption
  caption = _("Saving Support Configuration")

  # TODO FIXME And set the right number of stages
  steps = 2

  sl = 500
  Builtins.sleep(sl)

  # TODO FIXME Names of real stages
  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings"),
      # Progress stage 2/2
      _("Run SuSEconfig")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/2
      _("Running SuSEconfig..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # write settings
  return false if Abort()
  Progress.NextStage
  Builtins.sleep(sl)

  # run SuSEconfig
  return false if Abort()
  Progress.NextStage
  # Error message
  Report.Error(Message.SuSEConfigFailed) if false
  Builtins.sleep(sl)

  return false if Abort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if Abort()
  true
end

- (Object) WriteConfig



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
# File '../../src/modules/Support.rb', line 357

def WriteConfig
  Builtins.y2milestone("Writing /etc/supportconfig.conf configuration")
  new_config = []
  used_options = []
  Builtins.foreach(Ops.get_list(@configuration, "value", [])) do |row|
    Ops.set(
      row,
      "value",
      Ops.get_string(@options, Ops.get_string(row, "name", ""), "")
    )
    new_config = Builtins.add(new_config, row)
    used_options = Builtins.add(
      used_options,
      Ops.get_string(row, "name", "")
    )
  end
  Builtins.foreach(
    Convert.convert(
      Map.Keys(@options),
      :from => "list",
      :to   => "list <string>"
    )
  ) do |key|
    if !Builtins.contains(used_options, key)
      Builtins.y2milestone(
        "new option (not in old configuration) %1=%2",
        key,
        Ops.get_string(@options, key, "")
      )
      new_config = Builtins.add(
        new_config,
        {
          "name"    => key,
          "value"   => Ops.get_string(@options, key, ""),
          "comment" => "",
          "kind"    => "value",
          "type"    => 1
        }
      )
    end
  end
  Ops.set(@configuration, "value", new_config)
  SCR.Write(path(".etc.supportconfig.all"), @configuration)
  Builtins.y2milestone(
    "Write /etc/supportconfig.conf :%1",
    SCR.Write(path(".etc.supportconfig"), nil)
  )
  true
end

- (Object) WriteOnly

Returns true if module is marked as “write only” (don't start services etc…)

Returns:

  • true if module is marked as “write only” (don't start services etc…)



199
200
201
# File '../../src/modules/Support.rb', line 199

def WriteOnly
  @write_only
end