Class: Yast::AddOnProductClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
src/modules/AddOnProduct.rb,
src/modules/AddOnProduct.rb

Overview

This module provides integration of the add-on products

Constant Summary collapse

DEFAULT_PRODUCT_RENAMES =
{
  "SUSE_SLES"                         => ["SLES"],
  # SLED or Workstation extension
  "SUSE_SLED"                         => ["SLED", "sle-we"],
  # SLE11 HA has been renamed since SLE12
  "sle-hae"                           => ["sle-ha"],
  # SLE11 HA GEO is now included in SLE15 HA
  "sle-haegeo"                        => ["sle-ha"],
  # SLE12 HA GEO is now included in SLE15 HA
  "sle-ha-geo"                        => ["sle-ha"],
  "SUSE_SLES_SAP"                     => ["SLES_SAP"],
  # SLES-12 with HPC module can be replaced by SLE_HPC-15
  "SLES"                              => ["SLE_HPC"],
  # this is an internal product so far...
  "SLE-HPC"                           => ["SLE_HPC"],
  # SMT is now integrated into the base SLES
  "sle-smt"                           => ["SLES"],
  # Live patching is a module now (bsc#1074154)
  "sle-live-patching"                 => ["sle-module-live-patching"],
  # The Advanced Systems Management Module has been moved to the Basesystem module
  "sle-module-adv-systems-management" => ["sle-module-basesystem"],
  # Toolchain and SDK are now included in the Development Tools SLE15 module
  "sle-module-toolchain"              => ["sle-module-development-tools"],
  "sle-sdk"                           => ["sle-module-development-tools"],
  # openSUSE => SLES migration
  "openSUSE"                          => ["SLES"]
}.freeze
NETWORK_SCHEMES =

Repository network schemes

["http", "https", "ftp", "nfs", "cifs", "slp"].freeze
CD_SCHEMES =

Repository CD/DVD schemes

["cd", "dvd"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#selected_installation_productsObject (readonly)

Products which are selected for installation in libzypp.


50
51
52
# File 'src/modules/AddOnProduct.rb', line 50

def selected_installation_products
  @selected_installation_products
end

Instance Method Details

#AcceptedLicenseAndInfoFile(src_id) ⇒ Boolean

Show beta file in a pop-up message if such file exists. Show license if such exists and return whether users accepts it. Returns 'nil' when did not succed.


534
535
536
537
538
539
540
541
542
543
544
# File 'src/modules/AddOnProduct.rb', line 534

def AcceptedLicenseAndInfoFile(src_id)
  ret = ProductLicense.AskAddOnLicenseAgreement(src_id)
  return nil if ret.nil?

  if ret == :abort || ret == :back
    Builtins.y2milestone("License confirmation failed")
    return false
  end

  true
end

#AcceptFileWithoutChecksum(file) ⇒ Object


1672
1673
1674
1675
# File 'src/modules/AddOnProduct.rb', line 1672

def AcceptFileWithoutChecksum(file)
  Builtins.y2milestone("Accepting file without checksum: %1", file)
  true
end

#AcceptNonTrustedGpgKeyCallback(key) ⇒ Object


1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
# File 'src/modules/AddOnProduct.rb', line 1750

def AcceptNonTrustedGpgKeyCallback(key)
  key = deep_copy(key)
  Builtins.y2milestone("AcceptNonTrustedGpgKeyCallback %1", key)

  Ops.get_boolean(
    @current_addon,
    ["signature-handling", "accept_non_trusted_gpg_key", "all"],
    false
  ) ||
    Builtins.contains(
      Ops.get_list(
        @current_addon,
        ["signature-handling", "accept_non_trusted_gpg_key", "keys"],
        []
      ),
      Ops.get_string(key, "id", "")
    )
end

#AcceptUnknownGpgKeyCallback(filename, keyid, repo) ⇒ Object


1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
# File 'src/modules/AddOnProduct.rb', line 1704

def AcceptUnknownGpgKeyCallback(filename, keyid, repo)
  Builtins.y2milestone(
    "AcceptUnknownGpgKeyCallback %1: %2 (from repository %3)",
    filename,
    keyid,
    repo
  )

  Ops.get_boolean(
    @current_addon,
    ["signature-handling", "accept_unknown_gpg_key", "all"],
    false
  ) ||
    Builtins.contains(
      Ops.get_list(
        @current_addon,
        ["signature-handling", "accept_unknown_gpg_key", "keys"],
        []
      ),
      keyid
    )
end

#AcceptUnsignedFile(file, repo) ⇒ Object


1654
1655
1656
1657
1658
1659
1660
1661
# File 'src/modules/AddOnProduct.rb', line 1654

def AcceptUnsignedFile(file, repo)
  Builtins.y2milestone(
    "Accepting unsigned file %1 from repository %2",
    file,
    repo
  )
  true
end

#AcceptVerificationFailed(file, key, repo) ⇒ Object


1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
# File 'src/modules/AddOnProduct.rb', line 1682

def AcceptVerificationFailed(file, key, repo)
  key = deep_copy(key)
  Builtins.y2milestone(
    "Accepting failed verification of file %1 with key %2 from repository %3",
    file,
    key,
    repo
  )
  true
end

#add_rename(old_name, new_name) ⇒ Object

Add a product's rename

This method won't try to update the rename if it already exists. Renames added will be tracked in order to not loose information.


1910
1911
1912
1913
1914
1915
1916
# File 'src/modules/AddOnProduct.rb', line 1910

def add_rename(old_name, new_name)
  # already known
  return if renamed_externally?(old_name, new_name)
  log.info "Adding product rename: '#{old_name}' => '#{new_name}'"
  self.external_product_renames = add_rename_to_hash(external_product_renames,
    old_name, new_name)
end

#AddOnMode(source_id) ⇒ Object

Returns whether add-on product got as parameter (source id) replaces some already installed add-on or whether it is a new installation. Repositories and target have to be initialized.


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

def AddOnMode(source_id)
  all_products = Pkg.ResolvableProperties("", :product, "")

  check_add_on = {}

  # Search for an add-on using source ID
  Builtins.foreach(all_products) do |one_product|
    if Ops.get_integer(one_product, "source", -1) == source_id
      check_add_on = deep_copy(one_product)
      raise Break
    end
  end

  ret = "installation"

  supported_statuses = [:installed, :selected]
  already_found = false

  # Found the
  if check_add_on != {} && Builtins.haskey(check_add_on, "replaces")
    product_replaces = Ops.get_list(check_add_on, "replaces", [])

    # Run through through all products that the add-on can replace
    Builtins.foreach(product_replaces) do |one_replaces|
      raise Break if already_found
      # Run through all installed (or selected) products
      Builtins.foreach(all_products) do |one_product|
        # checking the status
        if !Builtins.contains(
          supported_statuses,
          Ops.get_symbol(one_product, "status", :unknown)
        )
          next
        end
        # ignore itself
        next if Ops.get_integer(one_product, "source", -42) == source_id
        # check name to replace
        if Ops.get_string(one_product, "name", "-A-") !=
            Ops.get_string(one_replaces, "name", "-B-")
          next
        end
        # check version to replace
        if Ops.get_string(one_product, "version", "-A-") !=
            Ops.get_string(one_replaces, "version", "-B-")
          next
        end
        # check version to replace
        if Ops.get_string(one_product, "arch", "-A-") !=
            Ops.get_string(one_replaces, "arch", "-B-")
          next
        end
        Builtins.y2milestone(
          "Found product matching update criteria: %1 -> %2",
          one_product,
          check_add_on
        )
        ret = "update"
        already_found = true
        raise Break
      end
    end
  end

  ret
end

#AddPreselectedAddOnProducts(filelist) ⇒ Boolean

Auto-integrate add-on products in specified file (usually add_on_products or add_on_products.xml file)

*Structure:*

 Format of /add_on_products.xml file on media root:
 <?xml version="1.0"?>
 <add_on_products xmlns="http://www.suse.com/1.0/yast2ns"
	xmlns:config="http://www.suse.com/1.0/configns">
	<product_items config:type="list">
		<product_item>
			<!-- Product name visible in UI when offered to user (optional item) -->
			<name>Add-on Name to Display</name>
      <!--
        Check product's name (optional item). If set to false, <name> won't be checked
        against product's name found in the media (CD/DVD only).
      -->
      <check_name config:type="boolean">true</check_name>
			<!-- Product URL (mandatory item) -->
			<url>http://product.repository/url/</url>
			<!-- Product path, default is "/" (optional item) -->
			<path>/relative/product/path</path>
			<!--
				List of products to install from media, by default all products
				from media are installed (optional item)
			-->
			<install_products config:type="list">
				<!--
					Product to install - matching the metadata product 'name'
					(mandatory to fully define 'install_products')
				-->
				<product>Product-ID-From-Repository</product>
				<product>...</product>
			</install_products>
			<!--
				If set to 'true', user is asked whether to install this product,
				default is 'false' (optional)
			-->
			<ask_user config:type="boolean">true</ask_user>
			<!--
				Connected to 'ask_user', sets the default status of product,
				default is 'false' (optional)
			-->
			<selected config:type="boolean">true</selected>
			<!--
				Defines priority of the newly added repository (optional).
				Libzypp uses its default priority if not set.
			-->
			<priority config:type="integer">20</priority>
			<!--
				User has to accept license?
			-->
                      <confirm_license config:type="boolean">true</confirm_license>
		</product_item>
		<product_item>
			...
		</product_item>
	</product_items>
 </add_on_products>

*Structure:*

Filelist map is in format
 [
     $[ "file" : "/local/path/to/an/add_on_products/file",     "type":"plain" ],
     $[ "file" : "/local/path/to/an/add_on_products/file.xml", "type":"xml" ]
 ]

See Also:

  • #303675: Support several add-ons on standard medium

1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
# File 'src/modules/AddOnProduct.rb', line 1405

def AddPreselectedAddOnProducts(filelist)
  if filelist.nil? || filelist.empty?
    log.info "No add-on products defined on the media or by inst-sys"
    return true
  end

  base_url = GetBaseProductURL()
  log.info "Base URL: #{URL.HidePassword(base_url)}"

  # Processes all add_on_products files found
  filelist.each do |file|
    add_products = parse_add_on_products_file(
      file.fetch("file", ""), file.fetch("type", ""), base_url
    )
    next unless add_products

    log.info "Adding products: #{add_products}"
    add_products.each do |one_product|
      url = one_product.fetch("url", "")
      pth = one_product.fetch("path", "")
      priority = one_product.fetch("priority", -1).to_i
      prodname = one_product.fetch("name", "")
      check_name = one_product.fetch("check_name", true)
      # Check URL and setup network if required or prompt to insert CD/DVD
      parsed = URL.Parse(url)
      scheme = parsed.fetch("scheme", "").downcase
      # check if network needs to be configured
      if NETWORK_SCHEMES.include?(scheme)
        inc_ret = Convert.to_symbol(
          WFM.CallFunction("inst_network_check", [])
        )
        Builtins.y2milestone("inst_network_check ret: %1", inc_ret)
      end

      # a CD/DVD repository
      repo_id =
        if CD_SCHEMES.include?(scheme)
          add_product_from_cd(url, pth, priority, prodname, check_name)
        else
          # a non CD/DVD repository
          AddRepo(url, pth, priority)
        end
      next false unless repo_id

      if !AcceptedLicenseAndInfoFile(repo_id)
        log.warn "License not accepted, delete the repository"
        Pkg.SourceDelete(repo_id)
        next false
      end
      Integrate(repo_id)
      # adding the product to the list of products (BNC #269625)
      prod = Pkg.SourceProductData(repo_id)
      log.info "Repository (#{repo_id} product data: #{prod})"
      InstallProductsFromRepository(one_product.fetch("install_products", []), repo_id)
      new_add_on_product = {
        "media"            => repo_id,
        "product"          => Ops.get_locale(
          one_product,
          "name",
          Ops.get_locale(
            prod,
            "label",
            Ops.get_locale(prod, "productname", _("Unknown Product"))
          )
        ),
        "autoyast_product" => Ops.get_locale(
          prod,
          "productname",
          Ops.get_locale(one_product, "name", _("Unknown Product"))
        ),
        "media_url"        => url,
        "product_dir"      => pth
      }
      new_add_on_product["priority"] = priority if priority > -1
      @add_on_products = Builtins.add(@add_on_products, new_add_on_product)
    end
  end

  # reread agents, redraw wizard steps, etc.
  ReIntegrateFromScratch()

  true
end

#AddRepo(url, pth, priority) ⇒ Object

Add a new repository


1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
# File 'src/modules/AddOnProduct.rb', line 1301

def AddRepo(url, pth, priority)
  # update the URL to the selected device
  new_repo = { "enabled" => true, "base_urls" => [url], "prod_dir" => pth }

  # BNC #714027: Possibility to adjust repository priority (usually higher)
  new_repo["priority"] = priority if priority > -1

  log.info "Adding Repository: #{URL.HidePassword(url)}, product path: #{pth}"
  new_repo_id = Pkg.RepositoryAdd(new_repo)
  log.info "New repository id: #{new_repo_id}"

  if new_repo_id.nil? || new_repo_id < 0
    log.error "Unable to add product: #{URL.HidePassword(url)}"
    # TRANSLATORS: error message, %1 is replaced with product URL
    Report.Error(format(_("Unable to add product %s."), URL.HidePassword(url)))
    return nil
  end

  # Make sure all changes are refreshed
  Pkg.SourceSaveAll
  # download metadata, build repo cache
  Pkg.SourceRefreshNow(new_repo_id)
  # load resolvables to zypp pool
  Pkg.SourceLoad

  new_repo_id
end

#AnyPatternInRepoObject


546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'src/modules/AddOnProduct.rb', line 546

def AnyPatternInRepo
  patterns = Pkg.ResolvableProperties("", :pattern, "")

  Builtins.y2milestone(
    "Total number of patterns: %1",
    Builtins.size(patterns)
  )

  patterns = Builtins.filter(patterns) do |pat|
    Ops.get(pat, "source") == @src_id
  end

  Builtins.y2milestone("Found %1 add-on patterns", Builtins.size(patterns))
  Builtins.y2debug("Found add-on patterns: %1", patterns)

  Ops.greater_than(Builtins.size(patterns), 0)
end

#AskForCD(url, product_name) ⇒ String?

Ask for a product medium


1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'src/modules/AddOnProduct.rb', line 1254

def AskForCD(url, product_name)
  parsed = URL.Parse(url)
  scheme = Builtins.tolower(Ops.get_string(parsed, "scheme", ""))

  msg = if product_name.nil? || product_name == ""
    # %1 is either "CD" or "DVD"
    Builtins.sformat(
      _("Insert the addon %1 medium"),
      Builtins.toupper(scheme)
    )
  else
    # %1 is the product name, %2 is either "CD" or "DVD"
    Builtins.sformat(
      _("Insert the %1 %2 medium"),
      product_name,
      Builtins.toupper(scheme)
    )
  end

  # make sure no medium is mounted (the drive is not locked)
  Pkg.SourceReleaseAll

  ui = SourceManager.AskForCD(msg)

  return nil if !Ops.get_boolean(ui, "continue", false)

  cd_device = Ops.get_string(ui, "device", "")
  if !cd_device.nil? && cd_device != ""
    Builtins.y2milestone("Selected CD/DVD device: %1", cd_device)
    query = Ops.get_string(parsed, "query", "")

    query = Ops.add(query, "&") if query != ""

    query = Ops.add(Ops.add(query, "devices="), cd_device)

    Ops.set(parsed, "query", query)
    url = URL.Build(parsed)
  end

  url
end

#CheckProductDependencies(_products) ⇒ Object


972
973
974
975
# File 'src/modules/AddOnProduct.rb', line 972

def CheckProductDependencies(_products)
  # TODO: check the dependencies of the product
  true
end

#CleanModeConfigSourcesObject


1599
1600
1601
1602
1603
1604
# File 'src/modules/AddOnProduct.rb', line 1599

def CleanModeConfigSources
  Builtins.foreach(@mode_config_sources) { |src| Pkg.SourceDelete(src) }
  @mode_config_sources = []

  nil
end

#CleanY2UpdateObject

Remove the /y2update directory from the system


523
524
525
526
527
# File 'src/modules/AddOnProduct.rb', line 523

def CleanY2Update
  SCR.Execute(path(".target.bash"), "/bin/rm -rf /y2update")

  nil
end

#ClearRegistrationRequest(src_id) ⇒ Object


714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'src/modules/AddOnProduct.rb', line 714

def ClearRegistrationRequest(src_id)
  Builtins.y2milestone(
    "Clearing registration flag for repository ID %1",
    src_id
  )
  if !src_id.nil?
    @addons_requesting_registration = Builtins.filter(
      @addons_requesting_registration
    ) { |one_source| one_source != src_id }
  end

  nil
end

#Disintegrate(srcid) ⇒ Object

Opposite to Integrate()


933
934
935
936
937
# File 'src/modules/AddOnProduct.rb', line 933

def Disintegrate(srcid)
  WorkflowManager.RemoveWorkflow(:addon, srcid, "")

  nil
end

#DoInstall(install_packages: true) ⇒ Symbol

Do installation of the add-on product within an installed system srcid is got via AddOnProduct::src_id


822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
# File 'src/modules/AddOnProduct.rb', line 822

def DoInstall
  # Display beta file if such file exists
  # Display license and wait for agreement
  # Not needed here, license already shown in the workflow
  # boolean license_ret = AcceptedLicenseAndInfoFile(src_id);
  # if (license_ret != true) {
  # 	y2milestone("Removing the current source ID %1", src_id);
  # 	Pkg::SourceDelete(src_id);
  # 	return nil;
  # }

  # FATE #301312
  PrepareForRegistration(@src_id)

  # FATE #301997: Support update of add-on products properly
  add_on_mode = AddOnMode(@src_id)
  SetMode(add_on_mode)

  # BNC #468449
  # Always store the current set of repositories as they might get
  # changed by registration or the called add-on workflow
  Pkg.SourceSaveAll

  ret = nil

  control = WorkflowManager.GetCachedWorkflowFilename(:addon, @src_id, "")
  if !control.nil?
    # FATE #305578: Add-On Product Requiring Registration
    WorkflowManager.AddWorkflow(:addon, @src_id, "")

    Builtins.y2milestone("Add-On has own control file")
    ret = DoInstall_WithControlFile(control)
  end
  # Fallback -- Repository didn't provide needed control file
  # or control file doesn't contain needed stage/mode
  # Handling as it was a repository
  ret = DoInstall_NoControlFile() if control.nil? || ret.nil?

  Builtins.y2milestone("Result of the add-on installation: %1", ret)

  if !ret.nil? && ret != :abort
    # registers Add-On product if requested
    RegisterAddOnProduct(@src_id)
  end

  if ret == :abort
    # cleanup after abort
    Builtins.y2milestone(
      "Add-on installation aborted, removing installation source %1: %2",
      @src_id,
      Pkg.SourceGeneralData(@src_id)
    )
    Pkg.SourceDelete(@src_id)
    Pkg.SourceSaveAll

    # remove from the internal list
    @add_on_products = Builtins.filter(@add_on_products) do |add_on_product|
      Ops.get_integer(add_on_product, "media", -1) != @src_id
    end

    # reset the src id, it's not valid
    @src_id = nil
  end

  Builtins.y2milestone("Returning: %1", ret)
  ret
end

#DoInstall_NoControlFileObject


564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'src/modules/AddOnProduct.rb', line 564

def DoInstall_NoControlFile
  Builtins.y2milestone(
    "File /installation.xml not found, running sw_single for this repository"
  )

  # display pattern the dialog when there is a pattern provided by the addon
  # otherwise use search mode
  mode = AnyPatternInRepo() ? :patternSelector : :searchMode
  # enable repository management if not in installation mode
  enable_repo_management = Mode.normal

  args = { "dialog_type" => mode, "repo_mgmt" => enable_repo_management }
  Builtins.y2milestone("Arguments for sw_single: %1", args)

  ret = WFM.CallFunction("sw_single", [args])
  Builtins.y2milestone("sw_single returned: %1", ret)

  return :abort if ret == :abort || ret == :cancel || ret == :close

  :register
end

#DoInstall_WithControlFile(control) ⇒ Object


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'src/modules/AddOnProduct.rb', line 639

def DoInstall_WithControlFile(control)
  Builtins.y2milestone(
    "File /installation.xml was found, running own workflow..."
  )
  # copy the control file to local filesystem - in case of media release
  tmp = Convert.to_string(SCR.Read(path(".target.tmpdir")))
  tmp = Ops.add(tmp, "/installation.xml")
  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat("/bin/cp %1 %2", control, tmp)
  )
  control = tmp

  return nil if !IntegrateY2Update(@src_id)

  # set control file
  ProductControl.custom_control_file = control
  if !ProductControl.Init
    # error report
    Report.Error(
      Builtins.sformat(_("Control file %1 not found on media."), control)
    )
    CleanY2Update()
    return nil
  end

  current_stage = "normal"
  current_mode = "installation"

  # Special add-on mode (GetMode()) returns the same
  # add-on can be either installed (first time) or updated by another add-on
  ProductControl.SetAdditionalWorkflowParams(
    "add_on_mode" => AddOnMode(@src_id)
  )

  steps = ProductControl.getModules(current_stage, current_mode, :enabled)
  if steps.nil? || Ops.less_than(Builtins.size(steps), 1)
    Builtins.y2warning(
      "Add-On product workflow for stage: %1, mode: %2 not defined",
      current_stage,
      current_mode
    )
    ProductControl.ResetAdditionalWorkflowParams
    return nil
  end

  # start workflow
  Wizard.OpenNextBackStepsDialog
  # dialog caption
  Wizard.SetContents(_("Initializing..."), Empty(), "", false, false)

  stage_mode = [{ "stage" => current_stage, "mode" => current_mode }]
  Builtins.y2milestone("Using Add-On control file parts: %1", stage_mode)
  ProductControl.AddWizardSteps(stage_mode)

  old_mode = nil
  # Running system, not installation, not update
  if Stage.normal && Mode.normal
    old_mode = Mode.mode
    Mode.SetMode(current_mode)
  end

  # Run the workflow
  ret = ProductControl.Run

  Mode.SetMode(old_mode) if !old_mode.nil?

  UI.CloseDialog
  CleanY2Update()

  ProductControl.ResetAdditionalWorkflowParams

  ret
end

#ExportHash

Returns map describing all used add-ons.

Examples:

This is an XML file created from exported map:

<add-on>
  <add_on_products config:type="list">
    <listentry>
      <media_url>ftp://server.name/.../</media_url>
      <product>NEEDS_TO_MATCH_"PRODUCT"_TAG_FROM_content_FILE!</product>
      <product_dir>/</product_dir>
    </listentry>
    ...
  </add_on_products>
</add-on>

1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
# File 'src/modules/AddOnProduct.rb', line 1506

def Export
  Builtins.y2milestone("Add-Ons Input: %1", @add_on_products)

  exp = Builtins.maplist(@add_on_products) do |p|
    p = Builtins.remove(p, "media") if Builtins.haskey(p, "media")
    # bugzilla #279893
    if Builtins.haskey(p, "autoyast_product")
      Ops.set(p, "product", Ops.get_string(p, "autoyast_product", ""))
      p = Builtins.remove(p, "autoyast_product")
    end
    deep_copy(p)
  end

  Builtins.y2milestone("Add-Ons Output: %1", exp)

  { "add_on_products" => exp }
end

#GetAbsoluteURL(base_url, url) ⇒ Object

Returns an absolute URL from base + relative url. Relative URL needs to start with 'reulrl://' othewise it is not considered being relative and it's returned as it is (just the relative_url parameter).

Examples:

AddOnProduct::GetAbsoluteURL (
  "http://www.example.org/some%20dir/another%20dir",
  "relurl://../AnotherProduct/"
) -> "http://www.example.org/some%20dir/AnotherProduct/"
AddOnProduct::GetAbsoluteURL (
  "username:[email protected]://www.example.org/dir/",
  "relurl://./Product_CD1/"
) -> "username:[email protected]://www.example.org/dir/Product_CD1/"

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/modules/AddOnProduct.rb', line 367

def GetAbsoluteURL(base_url, url)
  if !Builtins.regexpmatch(url, "^relurl://")
    Builtins.y2debug("Not a relative URL: %1", URL.HidePassword(url))
    return url
  end

  if base_url.nil? || base_url == ""
    Builtins.y2error("No base_url defined")
    return url
  end

  # bugzilla #306670
  base_params_pos = Builtins.search(base_url, "?")
  base_params = ""

  if !base_params_pos.nil? && Ops.greater_or_equal(base_params_pos, 0)
    base_params = Builtins.substring(base_url, Ops.add(base_params_pos, 1))
    base_url = Builtins.substring(base_url, 0, base_params_pos)
  end

  added_params_pos = Builtins.search(url, "?")
  added_params = ""

  if !added_params_pos.nil? && Ops.greater_or_equal(added_params_pos, 0)
    added_params = Builtins.substring(url, Ops.add(added_params_pos, 1))
    url = Builtins.substring(url, 0, added_params_pos)
  end

  base_url = Ops.add(base_url, "/") if !Builtins.regexpmatch(base_url, "/$")

  Builtins.y2milestone(
    "Merging '%1' (params '%2') to '%3' (params '%4')",
    url,
    added_params,
    base_url,
    base_params
  )
  url = Builtins.regexpsub(url, "^relurl://(.*)$", "\\1")

  url = Builtins.sformat("%1%2", base_url, url)

  # merge /something/../
  max_count = 100

  while Ops.greater_than(max_count, 0) &&
      Builtins.regexpmatch(url, "(.*/)[^/]+/+\\.\\./")
    max_count = Ops.subtract(max_count, 1)
    str_offset_l = Builtins.regexppos(url, "/\\.\\./")
    str_offset = Ops.get(str_offset_l, 0)

    next unless !str_offset.nil? && Ops.greater_than(str_offset, 0)
    stringfirst = Builtins.substring(url, 0, str_offset)
    stringsecond = Builtins.substring(url, str_offset)

    Builtins.y2debug(
      "Pos: %1 First: >%2< Second: >%3<",
      str_offset,
      stringfirst,
      stringsecond
    )

    stringfirst = Builtins.regexpsub(stringfirst, "^(.*/)[^/]+/*$", "\\1")
    stringsecond = Builtins.regexpsub(
      stringsecond,
      "^/\\.\\./(.*)$",
      "\\1"
    )

    url = Ops.add(stringfirst, stringsecond)
  end

  # remove /./
  max_count = 100

  while Ops.greater_than(max_count, 0) && Builtins.regexpmatch(url, "/\\./")
    max_count = Ops.subtract(max_count, 1)
    url = Builtins.regexpsub(url, "^(.*)/\\./(.*)", "\\1/\\2")
  end

  base_params_map = URL.MakeMapFromParams(base_params)
  added_params_map = URL.MakeMapFromParams(added_params)
  final_params_map = Convert.convert(
    Builtins.union(base_params_map, added_params_map),
    from: "map",
    to:   "map <string, string>"
  )

  if Ops.greater_than(Builtins.size(final_params_map), 0)
    Builtins.y2milestone(
      "%1 merge %2 -> %3",
      base_params_map,
      added_params_map,
      final_params_map
    )

    url = Ops.add(
      Ops.add(url, "?"),
      URL.MakeParamsFromMap(final_params_map)
    )
  end

  Builtins.y2milestone("Final URL: '%1'", URL.HidePassword(url))
  url
end

#GetBaseProductURLObject


346
347
348
# File 'src/modules/AddOnProduct.rb', line 346

def GetBaseProductURL
  @base_product_url
end

#GetCachedFileFromSource(src_id, media, filename, sod, optional) ⇒ String

Downloads a requested file, caches it and returns path to that cached file. If a file is alerady cached, just returns the path to a cached file. Parameter 'sod' defines whether a file is 'signed' (file + file.asc) or 'digested' (file digest mentioned in signed content file).

Examples:

// content file is usually signed with content.asc
AddOnProduct::GetCachedFileFromSource (8, 1, "/content", "signed", false);
// the other files are usually digested in content file
AddOnProduct::GetCachedFileFromSource (8, 1, "/images/images.xml", "digested", true);

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
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/modules/AddOnProduct.rb', line 163

def GetCachedFileFromSource(src_id, media, filename, sod, optional)
  # BNC #486785: Jukebox when using more physical media-based Add-Ons at once
  file_ID = Builtins.sformat("%1|%2|%3", src_id, media, filename)

  provided_file = Ops.get(@source_file_cache, file_ID, "")

  if !provided_file.nil? && provided_file != ""
    # Checking whether the cached file exists
    if FileUtils.Exists(provided_file)
      Builtins.y2milestone(
        "File %1 found in cache: %2",
        file_ID,
        provided_file
      )

      return provided_file
    else
      Builtins.y2warning("Cached file %1 not accessible!", provided_file)
      @source_file_cache = Builtins.remove(@source_file_cache, file_ID)
    end
  end

  optional = true if optional.nil?

  if sod == "signed"
    provided_file = Pkg.SourceProvideSignedFile(
      src_id,
      media,
      filename,
      optional
    )
  elsif sod == "digested"
    provided_file = Pkg.SourceProvideDigestedFile(
      src_id,
      media,
      filename,
      optional
    )
  else
    Builtins.y2error(
      "Unknown SoD: %1. It can be only 'signed' or 'digested'",
      sod
    )
    provided_file = nil
  end

  # A file has been found, caching...
  if !provided_file.nil?
    @filecachecounter = Ops.add(@filecachecounter, 1)

    # Where the file is finally cached
    cached_file = Builtins.sformat("%1%2", @filecachedir, @filecachecounter)

    cmd = Builtins.sformat(
      "/bin/mkdir -p '%1'; /bin/cp '%2' '%3'",
      String.Quote(@filecachedir),
      String.Quote(provided_file),
      String.Quote(cached_file)
    )
    cmd_run = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))

    # Unable to cache a file, the original file will be returned
    if Ops.get_integer(cmd_run, "exit", -1).nonzero?
      Builtins.y2warning("Error caching file: %1: %2", cmd, cmd_run)
    else
      Builtins.y2milestone("File %1 cached as %2", file_ID, cached_file)
      # Writes entry into cache database
      Ops.set(@source_file_cache, file_ID, cached_file)
      # Path to a cached file will be returned
      provided_file = cached_file
    end
  end

  provided_file
end

#GetModeString

Returns the current add-on installation mode.

See Also:

  • #SetMode()

243
244
245
# File 'src/modules/AddOnProduct.rb', line 243

def GetMode
  @_inst_mode
end

#Import(settings) ⇒ Object


1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
# File 'src/modules/AddOnProduct.rb', line 1567

def Import(settings)
  settings = deep_copy(settings)
  @add_on_products = Ops.get_list(settings, "add_on_products", [])
  @modified = false
  Builtins.foreach(@add_on_products) do |prod|
    Builtins.y2milestone("Add-on product: %1", prod)
    pth = Ops.get_string(prod, "product_dir", "/")
    url = SetRepoUrlAlias(
      Ops.get_string(prod, "media_url", ""),
      Ops.get_string(prod, "alias", ""),
      Ops.get_string(prod, "name", "")
    )
    src = Pkg.SourceCreate(url, pth)
    if src != -1
      if Ops.get_string(prod, "product", "") != ""
        repo = {
          "SrcId" => src,
          "name"  => Ops.get_string(prod, "product", "")
        }
        if Ops.greater_than(Ops.get_integer(prod, "priority", -1), -1)
          Ops.set(repo, "priority", Ops.get_integer(prod, "priority", -1))
        end
        Builtins.y2milestone("Setting new repo properties: %1", repo)
        Pkg.SourceEditSet([repo])
      end
      @mode_config_sources = Builtins.add(@mode_config_sources, src)
    end
  end if Mode.config

  true
end

#ImportGpgKeyCallback(key, repo) ⇒ Object


1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
# File 'src/modules/AddOnProduct.rb', line 1727

def ImportGpgKeyCallback(key, repo)
  key = deep_copy(key)
  Builtins.y2milestone(
    "ImportGpgKeyCallback: %1 from repository %2",
    key,
    repo
  )

  Ops.get_boolean(
    @current_addon,
    ["signature-handling", "import_gpg_key", "all"],
    false
  ) ||
    Builtins.contains(
      Ops.get_list(
        @current_addon,
        ["signature-handling", "import_gpg_key", "keys"],
        []
      ),
      Ops.get_string(key, "id", "")
    )
end

#InstallProductsFromRepository(prods_to_install, src) ⇒ Boolean

Installs selected products from repository. If list of prods_to_install is empty, all products found are installed.


1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
# File 'src/modules/AddOnProduct.rb', line 1214

def InstallProductsFromRepository(prods_to_install, src)
  prods_to_install = deep_copy(prods_to_install)
  # there are more products at the destination
  # install the listed ones only
  if !prods_to_install.nil? &&
      Ops.greater_than(Builtins.size(prods_to_install), 0)
    Builtins.foreach(prods_to_install) do |one_prod|
      Builtins.y2milestone(
        "Selecting product '%1' for installation",
        one_prod
      )
      Pkg.ResolvableInstall(one_prod, :product)
    end

    # install all products from the destination
  else
    products = Pkg.ResolvableProperties("", :product, "")
    # only those that come from the new source
    products = Builtins.filter(products) do |p|
      Ops.get_integer(p, "source", -1) == src
    end

    Builtins.foreach(products) do |p|
      Builtins.y2milestone(
        "Selecting product '%1' for installation",
        Ops.get_string(p, "name", "")
      )
      Pkg.ResolvableInstall(Ops.get_string(p, "name", ""), :product)
    end
  end

  nil
end

#Integrate(srcid) ⇒ Boolean

Integrate the add-on product to the installation workflow, including preparations for 2nd stage and inst-sys update


898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'src/modules/AddOnProduct.rb', line 898

def Integrate(srcid)
  Builtins.y2milestone("Integrating repository %1", srcid)

  # Updating inst-sys, this works only with the SUSE tags repositories
  y2update = GetCachedFileFromSource(
    srcid, # optional
    1,
    "/y2update.tgz",
    "digested",
    true
  )

  # try the package containing the installer update, works with all repositories,
  # including RPM-MD
  y2update ||= y2update_path(srcid)

  if y2update.nil?
    Builtins.y2milestone("No YaST update found on the media")
  else
    UpdateInstSys(y2update)
  end

  # FATE #302398: PATTERNS keyword in content file
  # changed for software section in installation.xml
  # or 'defaultpattern()' product Provides (FATE#320199)

  # Adds workflow to the Workflow Store if any workflow exists
  WorkflowManager.AddWorkflow(:addon, srcid, "")

  true
end

#IntegrateY2Update(src_id) ⇒ Object


586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'src/modules/AddOnProduct.rb', line 586

def IntegrateY2Update(src_id)
  # this works only with the SUSE tags repositories
  binaries = GetCachedFileFromSource(
    src_id, # optional
    1,
    "/y2update.tgz",
    "digested",
    true
  )

  # try the package containing the installer update, works with all repositories,
  # including RPM-MD
  binaries ||= y2update_path(src_id)

  # File /y2update.tgz exists
  if !binaries.nil?
    # Try to extract files from the archive
    out = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat(
          "\n" \
            "test -d /y2update && rm -rf /y2update;\n" \
            "/bin/mkdir -p /y2update/all;\n" \
            "cd /y2update/all;\n" \
            "/bin/tar -xvf %1;\n" \
            "cd /y2update;\n" \
            "ln -s all/usr/share/YaST2/* .;\n" \
            "ln -s all/usr/lib/YaST2/* .;\n",
          binaries
        )
      )
    )

    # Failed
    if Ops.get_integer(out, "exit", 0).nonzero?
      # error report
      Report.Error(
        _("An error occurred while preparing the installation system.")
      )
      CleanY2Update()
      return false
    else
      # bugzilla #239055
      RereadAllSCRAgents()
    end
  else
    Builtins.y2milestone("File /y2update.tgz not provided")
  end

  true
end

#mainObject


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

def main
  Yast.import "UI"
  Yast.import "Pkg"

  # IMPORTANT: maintainer of yast2-add-on is responsible for this module

  textdomain "packager"

  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "ProductControl"
  Yast.import "ProductFeatures"
  Yast.import "Report"
  Yast.import "XML"
  Yast.import "Wizard"
  Yast.import "FileUtils"
  Yast.import "Popup"
  Yast.import "InstShowInfo"
  Yast.import "ProductLicense"
  Yast.import "Directory"
  Yast.import "String"
  Yast.import "WorkflowManager"
  Yast.import "URL"
  Yast.import "Stage"
  Yast.import "Icon"
  Yast.import "Package"
  Yast.import "PackageCallbacks"
  Yast.import "PackagesProposal"
  Yast.import "SourceManager"

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

  # variables for installation with product
  # ID for cache in the inst-sys
  @src_cache_id = -1

  # System proposals have already been prepared for merging?
  @system_proposals_prepared = false

  # System workflows have already been prepared for merging?
  @system_workflows_prepared = false

  # List of all selected repositories
  #
  #
  # **Structure:**
  #
  #     add_on_products = [
  #        $[
  #          "media" : 4, // ID of the source
  #          "product_dir" : "/",
  #          "product" : "openSUSE version XX.Y",
  #          "autoyast_product" : "'PRODUCT' tag for AutoYaST Export",
  #        ],
  #        ...
  #      ]
  @add_on_products = []

  # ID of currently added repository for the add-on product
  @src_id = nil

  # for the add-on product workflow - needed for dialog skipping
  # return value of last step in the product adding workflow
  @last_ret = nil

  @modified = false

  @mode_config_sources = []

  @current_addon = {}

  # Bugzilla #239630
  # In installation: check for low-memory machines
  @low_memory_already_reported = false

  # Bugzilla #305554
  # Both online-repositories and add-ons use the same function and variable
  # if true, both are skipped at once without asking
  @skip_add_ons = false

  #
  # **Structure:**
  #
  #     $["src_id|media|filename" : "/path/to/the/file"]
  @source_file_cache = {}

  @filecachedir = Builtins.sformat("%1/AddOns_CacheDir/", Directory.tmpdir)

  @filecachecounter = -1

  # Which part installation.xml will be used
  @_inst_mode = "installation"

  # --> FATE #302123: Allow relative paths in "add_on_products" file
  @base_product_url = nil

  # Contains list of repository IDs that request registration
  @addons_requesting_registration = []

  # Every Add-On can preselect some patterns.
  # Only patterns that are not selected/installed yet will be used.
  #
  #
  # **Structure:**
  #
  #     $[
  #        src_id : [
  #          "pattern_1", "pattern_2", "pattern_6"
  #        ]
  #      ]
  @patterns_preselected_by_addon = {}

  # additional product renames needed for detecting the product update
  # @see #add_rename
  @external_product_renames = {}
end

#PackagesProposalAddonID(src_id) ⇒ Object


890
891
892
# File 'src/modules/AddOnProduct.rb', line 890

def PackagesProposalAddonID(src_id)
  "Add-On-Product-ID:#{src_id}"
end

#ParsePlainAddOnProductsFile(parse_file, base_url) ⇒ Array<Hash>

Reads temporary add_on_products file, parses supported products, merges base URL if products use relative URL and returns list of maps defining additional products to add.

*Structure:*

[
  // product defined with URL and additional path (typically "/")
  $["url":(string) url, "path":(string) path]
  // additional list of products to install
  // media URL can contain several products at once
  $["url":(string) url, "path":(string) path, "install_products":(list <string>) pti]
]

See Also:

  • #303675

997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'src/modules/AddOnProduct.rb', line 997

def ParsePlainAddOnProductsFile(parse_file, base_url)
  if !FileUtils.Exists(parse_file)
    Builtins.y2error("Cannot parse missing file: %1", parse_file)
    return []
  end

  products = Builtins.splitstring(
    Convert.to_string(SCR.Read(path(".target.string"), parse_file)),
    "\r\n"
  )

  if products.nil?
    # TRANSLATORS: error report
    Report.Error(_("Unable to use additional products."))
    Builtins.y2error("Erroneous file: %1", parse_file)
    return []
  end

  ret = []

  Builtins.foreach(products) do |p|
    next if p == ""
    elements = Builtins.splitstring(p, " \t")
    elements = Builtins.filter(elements) { |e| e != "" }
    url = Ops.get(elements, 0, "")
    pth = Ops.get(elements, 1, "/")
    elements = Builtins.remove(elements, 0) unless Ops.get(elements, 0).nil?
    elements = Builtins.remove(elements, 0) unless Ops.get(elements, 0).nil?
    # FATE #302123
    url = GetAbsoluteURL(base_url, url) if !base_url.nil? && base_url != ""
    ret = Builtins.add(
      ret,
      "url" => url, "path" => pth, "install_products" => elements
    )
  end

  deep_copy(ret)
end

#ParseXMLBasedAddOnProductsFile(parse_file, base_url) ⇒ Object


1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
# File 'src/modules/AddOnProduct.rb', line 1162

def ParseXMLBasedAddOnProductsFile(parse_file, base_url)
  if !FileUtils.Exists(parse_file)
    Builtins.y2error("Cannot parse missing file: %1", parse_file)
    return []
  end

  xmlfile_products = XML.XMLToYCPFile(parse_file)

  if xmlfile_products.nil?
    # TRANSLATORS: error report
    Report.Error(_("Unable to use additional products."))
    Builtins.y2error("Erroneous file %1", parse_file)
    return []
  elsif Ops.get_list(xmlfile_products, "product_items", []) == []
    Builtins.y2warning("Empty file %1", parse_file)
    return []
  end

  products = []

  run_ask_user = false

  Builtins.foreach(Ops.get_list(xmlfile_products, "product_items", [])) do |one_prod|
    if !Builtins.haskey(one_prod, "url")
      Builtins.y2error("No 'url' defined in %1", one_prod)
      next
    end
    # FATE #302123
    if !base_url.nil? && base_url != ""
      Ops.set(
        one_prod,
        "url",
        GetAbsoluteURL(base_url, Ops.get_string(one_prod, "url", ""))
      )
    end
    if Ops.get_boolean(one_prod, "ask_user", false) == true
      run_ask_user = true
    end
    products = Builtins.add(products, one_prod)
  end

  products = UserSelectsRequiredAddOns(products) if run_ask_user

  deep_copy(products)
end

#PrepareForRegistration(src_id) ⇒ Object

Checks whether the addon at src_id need registration If it has, product is added into list of products that need registration.


776
777
778
779
780
781
782
783
784
785
# File 'src/modules/AddOnProduct.rb', line 776

def PrepareForRegistration(src_id)
  control_file = WorkflowManager.GetCachedWorkflowFilename(:addon, src_id, "")

  return unless WorkflowManager.IncorporateControlFileOptions(control_file)
  # FATE #305578: Add-On Product Requiring Registration
  return unless WorkflowManager.WorkflowRequiresRegistration(src_id)

  log.info "REGISTERPRODUCT (require_registration) defined in control file"
  @addons_requesting_registration << deep_copy(src_id)
end

#ProcessRegistrationBoolean

Returns whether registration is requested by at least one of used Add-On products.


732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'src/modules/AddOnProduct.rb', line 732

def ProcessRegistration
  force_registration = false

  # checking add-on products one by one
  Builtins.foreach(@add_on_products) do |prod|
    srcid = Ops.get_integer(prod, "media")
    if !srcid.nil? &&
        Builtins.contains(@addons_requesting_registration, srcid)
      force_registration = true
      raise Break
    end
  end

  Builtins.y2milestone("Requesting registration: %1", force_registration)
  force_registration
end

#ReadTmpExportFilenameObject

Reads the Add-Ons configuration stored on disk during the first stage installation.

See Also:

  • #187558

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
# File 'src/modules/AddOnProduct.rb', line 1617

def ReadTmpExportFilename
  tmp_filename = TmpExportFilename()
  @modified = true

  if FileUtils.Exists(tmp_filename)
    Builtins.y2milestone("Reading %1 content", tmp_filename)

    # there might be something already set, store the current configuration
    already_in_configuration = deep_copy(@add_on_products)
    configuration_from_disk = Convert.to_map(
      SCR.Read(path(".target.ycp"), tmp_filename)
    )
    Builtins.y2milestone(
      "Configuration from disk: %1",
      configuration_from_disk
    )

    if !configuration_from_disk.nil?
      Import(configuration_from_disk)
      if already_in_configuration != [] && !already_in_configuration.nil?
        @add_on_products = Convert.convert(
          Builtins.union(@add_on_products, already_in_configuration),
          from: "list",
          to:   "list <map <string, any>>"
        )
      end
      return true
    else
      Builtins.y2error("Reading %1 file returned nil result!", tmp_filename)
      return false
    end
  else
    Builtins.y2warning("File %1 doesn't exists, skipping...", tmp_filename)
    return true
  end
end

#RegisterAddOnProduct(src_id) ⇒ Object

Calls registration client if needed.


790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'src/modules/AddOnProduct.rb', line 790

def RegisterAddOnProduct(src_id)
  # FATE #305578: Add-On Product Requiring Registration
  if WorkflowManager.WorkflowRequiresRegistration(src_id) ||
      Builtins.contains(@addons_requesting_registration, src_id)
    Builtins.y2milestone("Repository ID %1 requests registration", src_id)

    if !WFM.ClientExists("inst_scc")
      package_installed = Package.Install("yast2-registration")

      if !package_installed
        Report.Error(_("Package '%s' is not installed.\n" \
          "The add-on product cannot be registered.") % "yast2-registration")
        return nil
      end
    end

    # pass the addon so it could be registered
    WFM.CallFunction("inst_scc", ["register_media_addon", src_id])
  else
    Builtins.y2milestone(
      "Repository ID %1 doesn't need registration",
      src_id
    )
  end

  nil
end

#ReIntegrateFromScratchObject

Some product(s) were removed, reintegrating their control files from scratch.


940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
# File 'src/modules/AddOnProduct.rb', line 940

def ReIntegrateFromScratch
  Builtins.y2milestone("Reintegration workflows from scratch...")

  # bugzilla #239055
  RereadAllSCRAgents()

  # Should have been done before (by calling AddOnProduct::Integrate()
  #    foreach (map<string,any> prod, AddOnProduct::add_on_products, {
  #        integer srcid = (integer) prod["media"]:nil;
  #
  #        if (srcid == nil) {
  #            y2error ("Wrong definition of Add-on product: %1, cannot reintegrate", srcid);
  #            return;
  #        } else {
  #            y2milestone ("Reintegrating product %1", prod);
  #            Integrate (srcid);
  #        }
  #    });
  redraw = WorkflowManager.SomeWorkflowsWereChanged

  # New implementation: Control files are cached, just merging them into the Base Workflow
  WorkflowManager.MergeWorkflows

  # steps might have been changed, forcing redraw
  if redraw
    Builtins.y2milestone("Forcing RedrawWizardSteps()")
    WorkflowManager.RedrawWizardSteps
  end

  true
end

#RejectFileWithoutChecksum(file) ⇒ Object


1677
1678
1679
1680
# File 'src/modules/AddOnProduct.rb', line 1677

def RejectFileWithoutChecksum(file)
  Builtins.y2milestone("Rejecting file without checksum: %1", file)
  false
end

#RejectUnsignedFile(file, repo) ⇒ Object


1663
1664
1665
1666
1667
1668
1669
1670
# File 'src/modules/AddOnProduct.rb', line 1663

def RejectUnsignedFile(file, repo)
  Builtins.y2milestone(
    "Rejecting unsigned file %1 from repository %2",
    file,
    repo
  )
  false
end

#RejectVerificationFailed(file, key, repo) ⇒ Object


1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
# File 'src/modules/AddOnProduct.rb', line 1693

def RejectVerificationFailed(file, key, repo)
  key = deep_copy(key)
  Builtins.y2milestone(
    "Rejecting failed verification of file %1 with key %2 from repository %3",
    file,
    key,
    repo
  )
  false
end

#RemoveRegistrationFlag(src_id) ⇒ Object

Add-On product might have been added into products requesting registration. This pruduct has been removed (during configuring list of add-on products).


752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'src/modules/AddOnProduct.rb', line 752

def RemoveRegistrationFlag(src_id)
  # filtering out src_id
  @addons_requesting_registration = Builtins.filter(
    @addons_requesting_registration
  ) { |one_id| one_id != src_id }

  # removing cached file
  tmpdir = Ops.add(
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    "/add-on-content-files/"
  )
  cachedfile = Builtins.sformat("%1content-%2", tmpdir, src_id)
  if FileUtils.Exists(cachedfile)
    Builtins.y2milestone("Removing cached file %1", cachedfile)
    SCR.Execute(path(".target.remove"), cachedfile)
  end

  nil
end

#renamed?(old_name, new_name) ⇒ Boolean

Determine whether a product has been renamed


1897
1898
1899
1900
1901
# File 'src/modules/AddOnProduct.rb', line 1897

def renamed?(old_name, new_name)
  renamed_externally?(old_name, new_name) ||
    renamed_by_libzypp?(old_name, new_name) ||
    renamed_by_default?(old_name, new_name)
end

#RereadAllSCRAgentsObject

New add-on product might add also new agents. Functions Rereads all available agents.

See Also:

  • #239055, #245508

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'src/modules/AddOnProduct.rb', line 506

def RereadAllSCRAgents
  Builtins.y2milestone("Registering new agents...")
  ret = SCR.RegisterNewAgents

  if ret
    Builtins.y2milestone("Successful")
  else
    Builtins.y2error("Error occured during registering new agents!")
    Report.Error(
      _("An error occurred while preparing the installation system.")
    )
  end

  nil
end

#SetBaseProductURL(url) ⇒ Object


334
335
336
337
338
339
340
341
342
343
344
# File 'src/modules/AddOnProduct.rb', line 334

def SetBaseProductURL(url)
  Builtins.y2warning("Empty base url") if url == "" || url.nil?

  @base_product_url = url
  Builtins.y2milestone(
    "New base URL: %1",
    URL.HidePassword(@base_product_url)
  )

  nil
end

#SetMode(new_mode) ⇒ Object

Sets internal add-on installation mode to either “installation” or “update”. Mode is used later when deciding which part of the installation.xml to use.

See Also:

  • #GetMode();

252
253
254
255
256
257
258
259
260
261
# File 'src/modules/AddOnProduct.rb', line 252

def SetMode(new_mode)
  if new_mode.nil? ||
      !Builtins.contains(["installation", "update"], new_mode)
    Builtins.y2error("Wrong Add-On mode: %1", new_mode)
  end

  @_inst_mode = new_mode

  nil
end

#SetRepoUrlAlias(url, alias_name, name) ⇒ Object

Create URL with required alias from a URL. If alias is empty the name is used as a fallback. If both are empty the URL is not modified. If alias is already included in the URL then it is modified only if the requested alias is not empty otherwise it is kept unchanged.


1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
# File 'src/modules/AddOnProduct.rb', line 1529

def SetRepoUrlAlias(url, alias_name, name)
  if url.nil? || url == ""
    Builtins.y2error("Invalid 'url' parameter: %1", url)
    return url
  end

  # set repository alias to product name or alias if specified
  if !name.nil? && name != "" || !alias_name.nil? && alias_name != ""
    url_p = URL.Parse(url)
    params = URL.MakeMapFromParams(Ops.get_string(url_p, "query", ""))
    new_alias = ""

    if !alias_name.nil? && alias_name != ""
      new_alias = alias_name
      Builtins.y2milestone("Using repository alias: '%1'", new_alias)
    # no alias present in the URL, use the product name
    elsif Ops.get(params, "alias", "") != ""
      new_alias = name
      Builtins.y2milestone(
        "Using product name '%1' as repository alias",
        new_alias
      )
    else
      Builtins.y2milestone(
        "Keeping the original alias set in the URL: %1",
        Ops.get(params, "alias", "")
      )
      return url
    end

    Ops.set(params, "alias", new_alias)
    Ops.set(url_p, "query", URL.MakeParamsFromMap(params))
    url = URL.Build(url_p)
  end

  url
end

#SetSignatureCallbacks(product) ⇒ Object

<– Export/Import

Examples:

<add-on>
  <add_on_products config:type="list">
    <listentry>
      <media_url>http://software.opensuse.org/download/server:/dns/SLE_10/</media_url>
      <product>buildservice</product>
      <product_dir>/</product_dir>
      <signature-handling>
         <accept_unsigned_file config:type="boolean">true</accept_unsigned_file>
         <accept_file_without_checksum config:type="boolean">
           true
         </accept_file_without_checksum>
         <accept_verification_failed config:type="boolean">true</accept_verification_failed>
         <accept_unknown_gpg_key>
           <all config:type="boolean">true</all>
           <keys config:type="list">
              <keyid>...</keyid>
              <keyid>3B3011B76B9D6523</keyid>
           </keys>
         </accept_unknown_gpg_key>
         <accept_non_trusted_gpg_key>
           <all config:type="boolean">true</all>
           <keys config:type="list">
              <keyid>...</keyid>
           </keys>
         </accept_non_trusted_gpg_key>
         <import_gpg_key>
           <all config:type="boolean">true</all>
           <keys config:type="list">
              <keyid>...</keyid>
           </keys>
         </import_gpg_key>
      </signature-handling>
    </listentry>
  </add_on_products>
</add-on>

1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
# File 'src/modules/AddOnProduct.rb', line 1806

def SetSignatureCallbacks(product)
  @current_addon = {}
  Builtins.foreach(@add_on_products) do |addon|
    next if Ops.get_string(addon, "product", "") != product
    @current_addon = deep_copy(addon) # remember the current addon for the Callbacks
    if Builtins.haskey(
      Ops.get_map(addon, "signature-handling", {}),
      "accept_unsigned_file"
    )
      Pkg.CallbackAcceptUnsignedFile(
        if Ops.get_boolean(
          addon,
          ["signature-handling", "accept_unsigned_file"],
          false
        )
          fun_ref(method(:AcceptUnsignedFile), "boolean (string, integer)")
        else
          fun_ref(method(:RejectUnsignedFile), "boolean (string, integer)")
        end
      )
    end
    if Builtins.haskey(
      Ops.get_map(addon, "signature-handling", {}),
      "accept_file_without_checksum"
    )
      Pkg.CallbackAcceptFileWithoutChecksum(
        if Ops.get_boolean(
          addon,
          ["signature-handling", "accept_file_without_checksum"],
          false
        )
          fun_ref(method(:AcceptFileWithoutChecksum), "boolean (string)")
        else
          fun_ref(method(:RejectFileWithoutChecksum), "boolean (string)")
        end
      )
    end
    if Builtins.haskey(
      Ops.get_map(addon, "signature-handling", {}),
      "accept_verification_failed"
    )
      Pkg.CallbackAcceptVerificationFailed(
        if Ops.get_boolean(
          addon,
          ["signature-handling", "accept_verification_failed"],
          false
        )
          fun_ref(
            method(:AcceptVerificationFailed),
            "boolean (string, map <string, any>, integer)"
          )
        else
          fun_ref(
            method(:RejectVerificationFailed),
            "boolean (string, map <string, any>, integer)"
          )
        end
      )
    end
    if Builtins.haskey(
      Ops.get_map(addon, "signature-handling", {}),
      "accept_unknown_gpg_key"
    )
      Pkg.CallbackAcceptUnknownGpgKey(
        fun_ref(
          method(:AcceptUnknownGpgKeyCallback),
          "boolean (string, string, integer)"
        )
      )
    end
    if Builtins.haskey(
      Ops.get_map(addon, "signature-handling", {}),
      "import_gpg_key"
    )
      Pkg.CallbackImportGpgKey(
        fun_ref(
          method(:ImportGpgKeyCallback),
          "boolean (map <string, any>, integer)"
        )
      )
    end
    raise Break
  end
  nil
end

#TmpExportFilenameObject

Returns the path where Add-Ons configuration is stored during the fist stage installation. This path reffers to the installed system.

See Also:

  • #187558

1610
1611
1612
# File 'src/modules/AddOnProduct.rb', line 1610

def TmpExportFilename
  Ops.add(Directory.vardir, "/exported_add_ons_configuration")
end

#UpdateInstSys(filename) ⇒ Boolean

Adapts the inst-sys from the tarball


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

def UpdateInstSys(filename)
  @src_cache_id = Ops.add(@src_cache_id, 1)
  tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir")))
  tmpdir = Builtins.sformat("%1/%2", tmpdir, @src_cache_id)
  out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat(
        "\n" \
          "/bin/mkdir %1;\n" \
          "cd %1;\n" \
          "/bin/tar -xvf %2;\n" \
          "/sbin/adddir %1 /;\n",
        tmpdir,
        filename
      )
    )
  )
  if Ops.get_integer(out, "exit", 0).nonzero?
    Builtins.y2error("Including installation image failed: %1", out)
    return false
  end
  Builtins.y2milestone("Including installation image succeeded")
  true
end

#UserSelectsRequiredAddOns(products) ⇒ Object


1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File 'src/modules/AddOnProduct.rb', line 1036

def UserSelectsRequiredAddOns(products)
  products = deep_copy(products)
  return [] if products.nil? || products == []

  ask_user_products = []
  ask_user_products_map = {}

  # key in ask_user_products_map
  id_counter = -1
  visible_string = ""

  # filter those that are selected by default (without 'ask_user')
  selected_products = Builtins.filter(products) do |one_product|
    next true if Ops.get_boolean(one_product, "ask_user", false) == false
    # wrong definition, 'url' is mandatory
    if !Builtins.haskey(one_product, "url")
      Builtins.y2error("No 'url' defined: %1", one_product)
      next false
    end
    # user is asked for the rest
    id_counter = Ops.add(id_counter, 1)
    # fill up internal map (used later when item selected)
    Ops.set(ask_user_products_map, id_counter, one_product)
    if Builtins.haskey(one_product, "name")
      visible_string = Builtins.sformat(
        _("%1, URL: %2"),
        Ops.get_string(one_product, "name", ""),
        Ops.get_string(one_product, "url", "")
      )
    elsif Builtins.haskey(one_product, "install_products")
      visible_string = Builtins.sformat(
        _("%1, URL: %2"),
        Builtins.mergestring(
          Ops.get_list(one_product, "install_products", []),
          ", "
        ),
        Ops.get_string(one_product, "url", "")
      )
    elsif Builtins.haskey(one_product, "path") &&
        Ops.get_string(one_product, "path", "/") != "/"
      visible_string = Builtins.sformat(
        _("URL: %1, Path: %2"),
        Ops.get_string(one_product, "url", ""),
        Ops.get_string(one_product, "path", "")
      )
    else
      visible_string = Builtins.sformat(
        _("URL: %1"),
        Ops.get_string(one_product, "url", "")
      )
    end
    # create items
    ask_user_products = Builtins.add(
      ask_user_products,
      Item(
        Id(id_counter),
        visible_string,
        Ops.get_boolean(one_product, "selected", false)
      )
    )
    false
  end

  ask_user_products = Builtins.sort(ask_user_products) do |x, y|
    Ops.less_than(Ops.get_string(x, 1, ""), Ops.get_string(y, 1, ""))
  end

  UI.OpenDialog(
    VBox(
      # TRANSLATORS: popup heading
      Left(Heading(Id(:search_heading), _("Additional Products"))),
      VSpacing(0.5),
      # TRANSLATORS: additional dialog information
      Left(
        Label(
          _(
            "The installation repository also contains the listed additional repositories.\n" \
              "Select the ones you want to use.\n"
          )
        )
      ),
      VSpacing(0.5),
      MinSize(
        70,
        16,
        MultiSelectionBox(
          Id(:products),
          _("Additional Products to Select"),
          ask_user_products
        )
      ),
      HBox(
        HStretch(),
        # push button label
        PushButton(Id(:ok), _("Add Selected &Products")),
        HSpacing(1),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )

  ret = UI.UserInput
  Builtins.y2milestone("User ret: %1", ret)

  # add also selected
  if ret == :ok
    selprods = Convert.convert(
      UI.QueryWidget(:products, :SelectedItems),
      from: "any",
      to:   "list <integer>"
    )
    Builtins.foreach(selprods) do |one_product|
      selected_products = Builtins.add(
        selected_products,
        Ops.get(ask_user_products_map, one_product, {})
      )
    end
  end

  UI.CloseDialog

  Builtins.y2milestone("Selected products: %1", selected_products)

  deep_copy(selected_products)
end