Class: Yast::InstExtrasourcesClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/lib/installation/clients/inst_extrasources.rb

Overview

This client loads the target and initializes the package manager. Adds all sources defined in control file (software->extra_urls) and stores them at the end.

Instance Method Summary collapse

Instance Method Details

#GetURLsToRegister(registered) ⇒ Array<Hash>

Returns list of maps of repositories to register. See bnc #381360.



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
# File 'src/lib/installation/clients/inst_extrasources.rb', line 216

def GetURLsToRegister(registered)
  urls_from_control_file = ProductFeatures.GetFeature("software", "extra_urls")

  if urls_from_control_file.nil?
    Builtins.y2milestone(
      "Empty or errorneous software/extra_urls: %1",
      urls_from_control_file
    )
    return []
  end

  urls_from_control_file = Builtins.filter(urls_from_control_file) do |one_url|
    url = one_url["baseurl"] || ""
    normalized_url = url.end_with?("/") ? url.chop : url
    if registered.include?(normalized_url)
      Builtins.y2milestone(
        "Already registered: %1",
        Ops.get_string(one_url, "baseurl", "")
      )
      next false
    end
    true
  end

  Builtins.y2milestone(
    "Repositories to register: %1",
    urls_from_control_file
  )
  deep_copy(urls_from_control_file)
end

#InitializePackagerObject

Initialize the package manager needed for registered sources and products



374
375
376
377
378
379
380
381
382
# File 'src/lib/installation/clients/inst_extrasources.rb', line 374

def InitializePackager
  return false if !PackageLock.Check

  # to find out which sources have been already registered
  Pkg.SourceStartManager(false)

  # to initialize target because of installed products
  Pkg.TargetInit(Installation.destdir, false) == true
end

#InstallPackages(msg, details) ⇒ Object

ask user whether to install available package updates returns true after confirming



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
# File 'src/lib/installation/clients/inst_extrasources.rb', line 477

def InstallPackages(msg, details)
  button_box = ButtonBox(
    PushButton(
      Id(:yes),
      Opt(:default, :okButton, :key_F10),
      Label.YesButton
    ),
    PushButton(Id(:no), Opt(:cancelButton, :key_F9), Label.NoButton)
  )

  dialog = HBox(
    HSpacing(0.5),
    Top(MarginBox(1, 1, Icon.Image("question", {}))),
    VBox(
      Left(Label(msg)),
      VSpacing(0.5),
      # check box
      Left(
        CheckBox(Id(:show), Opt(:notify), _("Show &package updates"), false)
      ),
      ReplacePoint(Id(:info), Empty()),
      button_box
    ),
    HSpacing(2)
  )

  UI.OpenDialog(Opt(:decorated), dialog)

  r = nil
  while r != :yes && r != :no && r != :cancel
    r = UI.UserInput

    next if r != :show

    if UI.QueryWidget(Id(:show), :Value) == true
      UI.ReplaceWidget(Id(:info), RichText(Opt(:plainText), details))
    else
      UI.ReplaceWidget(Id(:info), Empty())
    end
  end

  UI.CloseDialog

  Builtins.y2milestone("User input: %1", r)

  r == :yes
end

#IsUpdateRepo(repo) ⇒ Object

is the repository an update repo?



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'src/lib/installation/clients/inst_extrasources.rb', line 399

def IsUpdateRepo(repo)
  Builtins.y2milestone(
    "Checking whether repository %1 is an update repo...",
    repo
  )
  ret = false

  # check if there is a patch available in the repository
  Builtins.foreach(Pkg.ResolvableProperties("", :patch, "")) do |patch|
    if Ops.get_integer(patch, "source", -1) == repo
      Builtins.y2milestone(
        "Found patch %1 in the repository",
        Ops.get_string(patch, "name", "")
      )
      ret = true
      raise Break
    end
  end

  Builtins.y2milestone("Repository %1 is update repo: %2", repo, ret)

  ret
end

#mainObject



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
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
# File 'src/lib/installation/clients/inst_extrasources.rb', line 43

def main
  textdomain "installation"

  # local sources that have been attached under /mnt during upgrade
  @local_urls = {}

  # USB sources that were used during installation should be disabled (bnc#793709)
  @usb_sources = {}

  # ////////////////////////////////////////

  if GetInstArgs.going_back # going backwards?
    return :auto # don't execute this once more
  end

  # autoyast mode, user cannot be asked
  if Mode.autoinst
    Builtins.y2milestone(
      "Skipping extra source configuration in AutoYaST mode"
    )
    return :auto
  end

  # bugzilla #263289
  if !InitializePackager()
    Builtins.y2error("Cannot connect to the Packager")
    return :auto
  end

  @already_registered = RegisteredUrls()

  @register_url = GetURLsToRegister(@already_registered)

  # fix local sources temporary attached under /mnt
  if Ops.greater_than(Builtins.size(@local_urls), 0)
    Builtins.foreach(@local_urls) do |srcid, url|
      new_url = Ops.add(
        "dir:",
        Builtins.substring(url, Ops.add(Builtins.find(url, "/mnt"), 4))
      )
      Builtins.y2milestone(
        "changing temporary url '%1' to '%2'",
        url,
        new_url
      )
      Pkg.SourceChangeUrl(srcid, new_url)
    end
    Pkg.SourceSaveAll
  end

  # disable USB sources
  if Ops.greater_than(Builtins.size(@usb_sources), 0)
    Builtins.foreach(@usb_sources) do |srcid, url|
      Builtins.y2milestone("disabling USB source %1", url)
      Pkg.SourceSetEnabled(srcid, false)
    end
    Pkg.SourceSaveAll
  end

  # any confirmed source to register?
  if Ops.greater_than(Builtins.size(@register_url), 0)
    # register (create) the sources
    @added_ids = RegisterRepos(@register_url)

    # synchronize the sources if any source has been added
    if Ops.greater_than(Builtins.size(@added_ids), 0)
      # If any source has been added, store the sources
      # bnc #440184
      Builtins.y2milestone(
        "Some (%1) sources have been added, storing them...",
        @added_ids
      )
      Pkg.SourceSaveAll
    end

    # check during upgrade whether the added repositories provide an upgrade for installed package
    # (openSUSE DVD does not contain all packages, packages from OSS repository might not have been upgraded,
    # see bnc#693230 for details)
    if Mode.update && Ops.greater_than(Builtins.size(@added_ids), 0)
      Builtins.y2milestone(
        "Checking whether there is and update provided by extra (non-update) repo..."
      )

      # network up?
      if NetworkService.isNetworkRunning
        # refresh the added repositories and load them
        if RefreshRepositories(@added_ids) && Pkg.SourceStartManager(true)
          # ignore update repositories - the updates will be installed later by online update
          @check_repos = Builtins.filter(@added_ids) do |repo|
            !IsUpdateRepo(repo)
          end

          if Ops.greater_than(Builtins.size(@check_repos), 0)
            UpgradeFrom(@check_repos)

            @upgrade_info = UpgradesAvailable(@check_repos)
            @upgrade_repos = Ops.get_list(@upgrade_info, "repositories", [])

            if Ops.greater_than(Builtins.size(@upgrade_repos), 0)
              # popup message, list of repositores is appended to the text
              @message = _(
                "Package updates have been found in these additional repositories:"
              ) + "\n\n"
              Builtins.foreach(@upgrade_repos) do |repo|
                repo_info = Pkg.SourceGeneralData(repo)
                @message = Ops.add(
                  @message,
                  Builtins.sformat(
                    "%1 (%2)\n",
                    Ops.get_string(repo_info, "name", ""),
                    Ops.get_string(repo_info, "url", "")
                  )
                )
              end

              # yes/no popup question
              @message = Ops.add(
                Ops.add(@message, "\n\n"),
                _(
                  "Start the software manager to check and install the updates?"
                )
              )

              @package_list = Builtins.mergestring(
                Ops.get_list(@upgrade_info, "packages", []),
                "\n"
              )

              if InstallPackages(@message, @package_list)
                # start the software manager
                @ui = PackagesUI.RunPackageSelector(
                  "mode" => :summaryMode
                )
                Builtins.y2milestone("Package manager returned: %1", @ui)

                if @ui == :accept
                  # install the packages
                  Builtins.y2milestone("Installing packages")
                  WFM.call("inst_rpmcopy")
                end
              else
                Builtins.y2milestone(
                  "Skipping installation of the available updates"
                )
              end
            else
              Builtins.y2milestone(
                "Everything OK, no available update found"
              )
            end

            RevertUpgradeFrom(@check_repos)
          end
        else
          Builtins.y2warning("Could not load new repositories")
        end
      else
        Builtins.y2milestone(
          "Network is not running, skipping available updates check"
        )
      end
    end
  end

  :auto

  # EOF
end

#RefreshRepositories(repos) ⇒ Object

refresh the requested repositories returns true on success



386
387
388
389
390
391
392
393
394
395
396
# File 'src/lib/installation/clients/inst_extrasources.rb', line 386

def RefreshRepositories(repos)
  repos = deep_copy(repos)
  ret = true

  Builtins.y2milestone("Refreshing repositories %1", repos)
  Builtins.foreach(repos) { |repo| ret &&= Pkg.SourceRefreshNow(repo) }

  Builtins.y2milestone("Refresh succeeded: %1", ret)

  ret
end

#RegisteredUrlsArray<String>

Returns list of already registered repositories.



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
# File 'src/lib/installation/clients/inst_extrasources.rb', line 342

def RegisteredUrls
  # get all registered installation sources
  srcs = Pkg.SourceGetCurrent(false)

  result = srcs.each_with_object([]) do |src, ret|
    general = Pkg.SourceGeneralData(src)
    url = general["url"]
    next if url.nil? || url.empty?
    @local_urls[src] = url if Mode.update && url =~ /^dir:\/+mnt\/+/
    # check for USB sources which should be disabled
    @usb_sources[src] = url if url.include?("device=/dev/disk/by-id/usb-")
    url.chop! if url.end_with?("/") # remove trailing slash to normalize path (see bnc#970488)
    ret << url
  end

  # remove duplicates
  result.uniq!

  Builtins.y2milestone("Registered sources: %1", result)

  Builtins.y2milestone(
    "Registered local sources under /mnt: %1",
    @local_urls
  )

  Builtins.y2milestone("Registered USB sources: %1", @usb_sources)

  result
end

#RegisterRepos(url_list) ⇒ Array<Fixnum>

Register the installation sources in offline mode (no network connection required). The repository metadata will be downloaded by sw_single (or another yast module) when the repostory is enabled



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
# File 'src/lib/installation/clients/inst_extrasources.rb', line 255

def RegisterRepos(url_list)
  url_list = deep_copy(url_list)
  ret = []

  Builtins.foreach(url_list) do |new_url|
    if Ops.get_string(new_url, "baseurl", "").nil? ||
        Ops.get_string(new_url, "baseurl", "") == ""
      Builtins.y2error(
        "Cannot use repository: %1, no 'baseurl' defined",
        new_url
      )
      next
    end
    repo_prop = {}
    # extra repos are disabled by default
    Ops.set(
      repo_prop,
      "enabled",
      Ops.get_boolean(new_url, "enabled", false)
    )
    Ops.set(
      repo_prop,
      "autorefresh",
      Ops.get_boolean(new_url, "autorefresh", true)
    )
    # repository name (try) name, alias, (fallback) baseurl
    Ops.set(
      repo_prop,
      "name",
      Ops.get_string(
        new_url,
        "name",
        Ops.get_string(
          new_url,
          "alias",
          Ops.get_string(new_url, "baseurl", "")
        )
      )
    )
    # repository alias (try) alias, (fallback) baseurl
    Ops.set(
      repo_prop,
      "alias",
      Ops.get_string(
        new_url,
        "alias",
        Ops.get_string(new_url, "baseurl", "")
      )
    )
    Ops.set(
      repo_prop,
      "base_urls",
      [Ops.get_string(new_url, "baseurl", "")]
    )
    if Builtins.haskey(new_url, "prod_dir")
      Ops.set(
        repo_prop,
        "prod_dir",
        Ops.get_string(new_url, "prod_dir", "/")
      )
    end
    if Builtins.haskey(new_url, "priority")
      Ops.set(
        repo_prop,
        "priority",
        Builtins.tointeger(Ops.get_integer(new_url, "priority", 99))
      )
    end
    new_repo_id = Pkg.RepositoryAdd(repo_prop)
    if !new_repo_id.nil? && Ops.greater_or_equal(new_repo_id, 0)
      Builtins.y2milestone(
        "Registered extra repository: %1: %2",
        new_repo_id,
        repo_prop
      )
      ret = Builtins.add(ret, new_repo_id)
    else
      Builtins.y2error("Cannot register: %1", repo_prop)
    end
  end

  deep_copy(ret)
end

#RevertUpgradeFrom(repos) ⇒ Object

revert the upgrading repos, reset package selection



437
438
439
440
441
442
443
444
445
446
447
448
# File 'src/lib/installation/clients/inst_extrasources.rb', line 437

def RevertUpgradeFrom(repos)
  repos = deep_copy(repos)
  Builtins.foreach(repos) do |repo|
    Builtins.y2milestone("Removing upgrade repo %1", repo)
    Pkg.RemoveUpgradeRepo(repo)
  end

  Pkg.PkgApplReset
  Pkg.PkgReset

  nil
end

#UpgradeFrom(repos) ⇒ Object

mark the repositories for upgrade, run the solver



424
425
426
427
428
429
430
431
432
433
434
# File 'src/lib/installation/clients/inst_extrasources.rb', line 424

def UpgradeFrom(repos)
  repos = deep_copy(repos)
  Builtins.foreach(repos) do |repo|
    Builtins.y2milestone("Adding upgrade repo %1", repo)
    Pkg.AddUpgradeRepo(repo)
  end

  Pkg.PkgSolve(true)

  nil
end

#UpgradesAvailable(repos) ⇒ Object

check if there is a selected package in the requested repositories returns list of repositories providing an update (repo IDs)



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'src/lib/installation/clients/inst_extrasources.rb', line 452

def UpgradesAvailable(repos)
  ret = []
  packages = []

  # only package names (without version)
  names_only = true
  Pkg.GetPackages(:selected, names_only).each do |pkg|
    Pkg.ResolvableProperties(pkg, :package, "").each do |p|
      source = p["source"]
      next unless p["status"] == :selected && repos.include?(source)

      package = "#{p["name"]}-#{p["version"]}.#{p["arch"]}"
      log.info("Found upgrade to install: #{package}")
      packages << package
      ret << source unless ret.include?(source)
    end
  end

  log.info("Upgrades found in repositories: #{ret.inspect}")

  { "repositories" => ret, "packages" => packages }
end