Class: Yast::InstRpmcopyClient

Inherits:
Client
  • Object
show all
Defined in:
src/clients/inst_rpmcopy.rb

Overview

Install all the RPM packages the user has selected. Show installation dialogue. Show progress bars. Request medium change from user.

Instance Method Summary collapse

Instance Method Details

#AutoinstPostPackagesObject


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
# File 'src/clients/inst_rpmcopy.rb', line 308

def AutoinstPostPackages
  # post packages from autoinstall
  res = Pkg.DoProvide(AutoinstData.post_packages)
  Builtins.foreach(res) do |s, a|
    Builtins.y2warning("Pkg::DoProvide failed for %1: %2", s, a)
  end if Ops.greater_than(
    Builtins.size(res),
    0
  )

  failed = []
  patterns = deep_copy(AutoinstData.post_patterns)
  # set SoftLock to avoid the installation of recommended patterns (#159466)
  Builtins.foreach(Pkg.ResolvableProperties("", :pattern, "")) do |p|
    Pkg.ResolvableSetSoftLock(Ops.get_string(p, "name", ""), :pattern)
  end
  Builtins.foreach(Builtins.toset(patterns)) do |p|
    failed = Builtins.add(failed, p) if !Pkg.ResolvableInstall(p, :pattern)
  end

  if Ops.greater_than(Builtins.size(failed), 0)
    Builtins.y2error(
      "Error while setting pattern: %1",
      Builtins.mergestring(failed, ",")
    )
    Report.Warning(
      Builtins.sformat(
        _("Could not set patterns: %1."),
        Builtins.mergestring(failed, ",")
      )
    )
  end
  #
  # Solve dependencies
  #
  if !Pkg.PkgSolve(false)
    Report.Error(
      _(
        "The package resolver run failed. Check your software section in the AutoYaST profile."
      )
    )
  end

  nil
end

#CountStartingAndMaxMediaNumberObject


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
# File 'src/clients/inst_rpmcopy.rb', line 472

def CountStartingAndMaxMediaNumber
  # Bugzilla #170079
  # Default - unrestricted
  ret = { "maxnumbercds" => 0, "current_cd_no" => 0 }

  # has the inst-sys been successfuly unmounted?
  umount_result = Linuxrc.InstallInf("umount_result")
  media = Linuxrc.InstallInf("InstMode")
  Builtins.y2milestone(
    "umount result: %1, inst repository type: %2",
    umount_result,
    media
  )

  if Packages.metadir_used
    # all is in ramdisk, we can install all repositories now, works in every stage
    Ops.set(ret, "current_cd_no", 0)
    Ops.set(ret, "maxnumbercds", 0)
    Builtins.y2milestone(
      "StartingAndMaxMediaNumber: MetaDir used %1/%2",
      Ops.get(ret, "current_cd_no"),
      Ops.get(ret, "maxnumbercds")
    )
  elsif Stage.initial
    # is CD or DVD medium mounted? (inst-sys)
    if umount_result != "0" && (media == "cd" || media == "dvd")
      Builtins.y2milestone("The installation CD/DVD cannot be changed.")
      # only the first CD will be installed
      Ops.set(ret, "current_cd_no", 1)
      Ops.set(ret, "maxnumbercds", 1)
    end
    # otherwise use the default setting - install all media
    Builtins.y2milestone(
      "StartingAndMaxMediaNumber: Stage initial %1/%2",
      Ops.get(ret, "current_cd_no"),
      Ops.get(ret, "maxnumbercds")
    )

    # Three following cases have the same solution, CDstart = 0, CDfinish = 0
    # ZYPP should solve what it needs and when.
    # Leaving it here as the backward compatibility if someone decides to change it back.
  elsif Mode.autoinst && Stage.cont &&
      Ops.greater_than(Builtins.size(AutoinstData.post_packages), 0)
    # one more compatibility feature to old YaST, post-packages
    # Simply install a list of package after initial installation (only
    # makes sense with nfs installatons)
    Ops.set(ret, "current_cd_no", 0) # was 1
    Ops.set(ret, "maxnumbercds", 0) # was 10
    Builtins.y2milestone(
      "StartingAndMaxMediaNumber: Autoinst in cont %1/%2",
      Ops.get(ret, "current_cd_no"),
      Ops.get(ret, "maxnumbercds")
    )
  elsif Stage.cont
    # continue with second CD but only in continue mode
    # bug #170079, let zypp solve needed CDs
    Ops.set(ret, "current_cd_no", 0)
    Ops.set(ret, "maxnumbercds", 0)
    Builtins.y2milestone(
      "StartingAndMaxMediaNumber: Stage cont %1/%2",
      Ops.get(ret, "current_cd_no"),
      Ops.get(ret, "maxnumbercds")
    )
  elsif Installation.dirinstall_installing_into_dir
    # All in one
    Ops.set(ret, "current_cd_no", 0) # was 1
    Ops.set(ret, "maxnumbercds", 0) # was 10
    Builtins.y2milestone(
      "StartingAndMaxMediaNumber: Dir install %1/%2",
      Ops.get(ret, "current_cd_no"),
      Ops.get(ret, "maxnumbercds")
    )
  end

  deep_copy(ret)
end

#InitRemainingPackagesObject

Fills-up 'remaining' and 'srcremaining' lists with information of objects that need to be installed.


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
# File 'src/clients/inst_rpmcopy.rb', line 194

def InitRemainingPackages
  Builtins.y2milestone("Looking for remaining packages")

  file_remaining_packages = Ops.add(
    Installation.destdir,
    "/var/lib/YaST2/remaining"
  )
  file_remaining_srcs = Ops.add(
    Installation.destdir,
    "/var/lib/YaST2/srcremaining"
  )

  # Packages remaining for installation
  if FileUtils.Exists(file_remaining_packages)
    @remaining = Convert.convert(
      SCR.Read(path(".target.ycp"), [file_remaining_packages, []]),
      from: "any",
      to:   "list <map <string, any>>"
    )
    @remaining = [] if @remaining.nil?
    Builtins.y2milestone(
      "File %1 contains %2 packages",
      file_remaining_packages,
      Builtins.size(@remaining)
    )
  end

  # repositories remaining for installation
  if FileUtils.Exists(file_remaining_srcs)
    @srcremaining = Convert.convert(
      SCR.Read(path(".target.ycp"), [file_remaining_srcs, []]),
      from: "any",
      to:   "list <string>"
    )
    @srcremaining = [] if @srcremaining.nil?
    Builtins.y2milestone(
      "File %1 contains %2 packages",
      file_remaining_srcs,
      Builtins.size(@srcremaining)
    )
  end

  nil
end

#InstallPackagesFromMedia(current_cd_no, maxnumbercds) ⇒ Object


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
# File 'src/clients/inst_rpmcopy.rb', line 354

def InstallPackagesFromMedia(current_cd_no, maxnumbercds)
  result = :next

  Builtins.y2milestone(
    "Installing packages from media %1 -> %2",
    current_cd_no,
    maxnumbercds
  )

  # 1->1 for default fist stage installation
  # 0->0 for default second stage (or other) installation
  while Ops.less_or_equal(current_cd_no, maxnumbercds)
    # nothing to install/delete
    if Pkg.IsAnyResolvable(:any, :to_remove) == false &&
        Pkg.IsAnyResolvable(:any, :to_install) == false
      Builtins.y2milestone("No package left for installation")
      break
    end

    # returns [ int successful, list failed, list remaining ]
    config = { "medium_nr" => current_cd_no }
    if PackageInstallation.DownloadInAdvance == true
      Ops.set(config, "download_mode", :download_in_advance)
    end

    Builtins.y2milestone("Commit config: %1", config)

    commit_result = PackageInstallation.Commit(config)

    if commit_result.nil? || Builtins.size(commit_result).zero?
      Builtins.y2error("Commit failed")
      # error message - displayed in a scrollable text area
      # %1 - an error message (details)
      Report.LongError(
        Builtins.sformat(
          _(
            "Installation failed.\n" \
              "\n" \
              "Details:\n" \
              "%1\n" \
              "\n" \
              "Package installation will be aborted.\n"
          ),
          Pkg.LastError
        )
      )

      return :abort
    end

    count = Ops.get_integer(commit_result, 0, 0)
    Builtins.y2milestone("%1 packages installed", count)

    failed = Ops.get_list(commit_result, 1, [])
    if Ops.greater_than(Builtins.size(failed), 0)
      Builtins.y2milestone("failed: %1", failed)
      previous_failed = Convert.to_list(
        SCR.Read(
          path(".target.ycp"),
          [
            Ops.add(Installation.destdir, "/var/lib/YaST2/failed_packages"),
            []
          ]
        )
      )
      if Ops.greater_than(Builtins.size(previous_failed), 0)
        failed = Builtins.union(previous_failed, failed)
      end
      SCR.Write(
        path(".target.ycp"),
        Ops.add(Installation.destdir, "/var/lib/YaST2/failed_packages"),
        failed
      )
    end

    remaining = Ops.get_list(commit_result, 2, [])
    if Ops.greater_or_equal(Builtins.size(remaining), 0)
      Builtins.y2milestone("remaining: %1", remaining)
      SCR.Write(
        path(".target.ycp"),
        Ops.add(Installation.destdir, "/var/lib/YaST2/remaining"),
        remaining
      )
    else
      SCR.Execute(
        path(".target.remove"),
        Ops.add(Installation.destdir, "/var/lib/YaST2/remaining")
      )
    end

    srcremaining = Ops.get_list(commit_result, 3, [])
    if Ops.greater_or_equal(Builtins.size(srcremaining), 0)
      Builtins.y2milestone("repository remaining: %1", srcremaining)
      SCR.Write(
        path(".target.ycp"),
        Ops.add(Installation.destdir, "/var/lib/YaST2/srcremaining"),
        srcremaining
      )
    else
      SCR.Execute(
        path(".target.remove"),
        Ops.add(Installation.destdir, "/var/lib/YaST2/srcremaining")
      )
    end

    if Ops.less_than(count, 0) # aborted by user
      result = :abort
      break
    end

    # break on first round with Mediums
    break if Stage.initial && !Mode.test

    current_cd_no = Ops.add(current_cd_no, 1)
  end
  result
end

#InstallRemainingAndBinarySourceObject

Sets remaining packages to be installed


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
# File 'src/clients/inst_rpmcopy.rb', line 257

def InstallRemainingAndBinarySource
  # second stage of package installation, re-read list of remaining binary and source
  # packages

  backupPath = Convert.to_string(
    SCR.Read(
      path(".target.string"),
      [Ops.add(Installation.destdir, "/var/lib/YaST2/backup_path"), ""]
    )
  )
  if !backupPath.nil? && backupPath != ""
    Builtins.y2milestone("create package backups in %1", backupPath)
    Pkg.CreateBackups(true)
    Pkg.SetBackupPath(backupPath)
  end

  failed_packages = 0
  Builtins.y2milestone(
    "%1 resolvables remaining",
    Builtins.size(@remaining)
  )
  Builtins.foreach(@remaining) do |res|
    name = Ops.get_string(res, "name", "")
    kind = Ops.get_symbol(res, "kind", :package)
    arch = Ops.get_string(res, "arch", "")
    vers = Ops.get_string(res, "version", "")
    if !Pkg.ResolvableInstallArchVersion(name, kind, arch, vers)
      failed_packages = Ops.add(failed_packages, 1)
    end
  end

  Builtins.y2milestone(
    "%1 source packages remaining",
    Builtins.size(@srcremaining)
  )
  Builtins.foreach(@srcremaining) do |pkg|
    failed_packages = Ops.add(failed_packages, 1) if !Pkg.PkgSrcInstall(pkg)
  end
  if Ops.greater_than(failed_packages, 0)
    # error report, %1 is number
    Report.Error(
      Builtins.sformat(
        _("Failed to select %1 packages for installation."),
        failed_packages
      )
    )
  end

  nil
end

#mainObject


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
# File 'src/clients/inst_rpmcopy.rb', line 7

def main
  Yast.import "Pkg"
  textdomain "packager"

  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "Installation"
  Yast.import "Language"
  Yast.import "PackageInstallation"
  Yast.import "Packages"
  Yast.import "SlideShow"
  Yast.import "PackageSlideShow"
  Yast.import "SlideShowCallbacks"
  Yast.import "Popup"
  Yast.import "Report"
  Yast.import "SourceManager"
  Yast.import "Linuxrc"
  Yast.import "FileUtils"
  Yast.import "AutoinstData"

  Yast.include self, "packager/storage_include.rb"

  @remaining = []
  @srcremaining = []

  return :auto if Installation.image_only

  # bugzilla #208222
  ReleaseHDDUsedAsInstallationSource()

  # bugzilla #326327
  Packages.SlideShowSetUp(Language.language)

  Pkg.SetTextLocale(Language.language)

  SlideShow.SetLanguage(Language.language)

  # Initialize and check whether some packages need to be installed
  # stop proceeding the script if they don't (Second stage)
  if Stage.cont && !Mode.live_installation && !Mode.autoinst
    InitRemainingPackages()
    if SomePackagesAreRemainForInstallation() != true
      Builtins.y2milestone("No packages need to be installed, skipping...")
      return :auto
    else
      Builtins.y2milestone("Some packages need to be installed...")
    end
  end

  # start target, create new rpmdb if none is existing
  # FIXME error checking is missing all around here, initialization could actually fail!
  if Pkg.TargetInitialize(Installation.destdir) != true
    # continue-cancel popup
    if Popup.ContinueCancel(_("Initializing the target directory failed.")) == false
      return :abort
    end
  end

  if Mode.update
    # Removes all already installed patches and selections.
    # See bugzilla #210552 for more information.
    RemoveObsoleteResolvables()
  end

  if Stage.cont && !Mode.live_installation
    # initialize the package agent in continue mode
    Packages.Init(true)

    # in 1st stage, this is opened already
    SlideShow.OpenDialog
  end

  AutoinstPostPackages() if Mode.autoinst && Stage.cont

  # initial mode, move download area, check for repository caching
  if Stage.initial
    SourceManager.InstInitSourceMoveDownloadArea

    # continue mode, set remaining packages to be installed
  elsif !Mode.live_installation
    InstallRemainingAndBinarySource()
  end

  # Install the software from Medium1 to Mediummax, but not the already
  # installed base packages.
  # This part is also used for installation in running system (Stage::cont ())

  @cdnumbers = CountStartingAndMaxMediaNumber()
  @maxnumbercds = Ops.get(@cdnumbers, "maxnumbercds", 10)
  @current_cd_no = Ops.get(@cdnumbers, "current_cd_no", 1)

  # re-initialize package information
  PackageSlideShow.InitPkgData(true)

  @get_setup = SlideShow.GetSetup
  if @get_setup.nil? || @get_setup == {}
    Builtins.y2milestone("No SlideShow setup has been set, adjusting")
    SlideShow.Setup(
      [
        {
          "name"        => "packages",
          "description" => _("Installing Packages..."),
          "value"       => Ops.divide(
            PackageSlideShow.total_size_to_install,
            1024
          ), # kilobytes
          "units"       => :kb
        }
      ]
    )
  end
  @get_setup = nil

  # we want the table
  SlideShow.ShowTable

  # Do not open a new SlideShow widget, reuse the old one instead
  @required_to_open_sl_dialog = !SlideShow.HaveSlideWidget

  # BNC #443755
  if @required_to_open_sl_dialog
    Builtins.y2milestone("SlideShow dialog not yet created")
    SlideShow.OpenDialog
  end

  # move the progress to the packages stage
  SlideShow.MoveToStage("packages")

  # bnc#875350: Log the current user/app_high software selection
  Packages.log_software_selection

  # install packages from CD current_cd_no to CD maxnumbercds
  @result = InstallPackagesFromMedia(@current_cd_no, @maxnumbercds)

  # sync package manager FIXME
  if @result != :abort && !Stage.initial
    @config = {}
    if PackageInstallation.DownloadInAdvance == true
      Ops.set(@config, "download_mode", :download_in_advance)
    end
    Builtins.y2milestone("Calling Pkg::Commit(%1)", @config)
    Pkg.Commit(@config)
  end

  # BNC #443755
  if @required_to_open_sl_dialog
    Builtins.y2milestone("Closing previously opened SlideShow dialog")
    SlideShow.CloseDialog
  end

  if @result != :abort
    if Stage.cont
      # some new SCR asgents might have been installed
      SCR.RegisterNewAgents
    end
  end

  # clear the installation log for the next run, save some memory
  Builtins.y2milestone("Resetting SlideShow installation log")
  SlideShow.inst_log = ""

  @result
end

#RemoveObsoleteResolvablesObject

Removes all already installed patches and selections. See bugzilla #210552 for more information.


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'src/clients/inst_rpmcopy.rb', line 173

def RemoveObsoleteResolvables
  Builtins.y2milestone("--------- removing obsolete selections ---------")

  # this removes only information about selections and applied patches
  # it doesn't remove any package
  Builtins.y2milestone(
    "Removing all information about selections and patches in %1",
    Installation.destdir
  )
  Pkg.TargetStoreRemove(Installation.destdir, :selection)

  # disabled by FATE #301990, bugzilla #238488
  # Pkg::TargetStoreRemove (Installation::destdir, `patch);

  Builtins.y2milestone("--------- removing obsolete selections ---------")

  nil
end

#SomePackagesAreRemainForInstallationBoolean

And returns whether some objects need to be installed as the result.


242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'src/clients/inst_rpmcopy.rb', line 242

def SomePackagesAreRemainForInstallation
  # Either 'remaining' or 'srcremaining' are not empty
  size_remaining = @remaining.nil? ? 0 : Builtins.size(@remaining)
  size_srcremaining = @srcremaining.nil? ? 0 : Builtins.size(@srcremaining)

  Builtins.y2milestone(
    "remaining: %1, srcremaining: %2",
    size_remaining,
    size_srcremaining
  )
  Ops.greater_than(size_remaining, 0) ||
    Ops.greater_than(size_srcremaining, 0)
end