Class: Yast::AddOnProductClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) AcceptedLicenseAndInfoFile(src_id)

Show /media.1/info.txt 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.

Returns:

  • (Boolean)

    whether the license has been accepted



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

def AcceptedLicenseAndInfoFile(src_id)
  ret = ProductLicense.AskAddOnLicenseAgreement(src_id)
  if ret == nil
    return nil
  elsif ret == :abort || ret == :back
    Builtins.y2milestone("License confirmation failed")
    return false
  end
  true
end

- (Object) AcceptFileWithoutChecksum(file)



1967
1968
1969
1970
# File '../../src/modules/AddOnProduct.rb', line 1967

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

- (Object) AcceptNonTrustedGpgKeyCallback(key)



2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
# File '../../src/modules/AddOnProduct.rb', line 2046

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

- (Object) AcceptUnknownGpgKeyCallback(filename, keyid, repo)



2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
# File '../../src/modules/AddOnProduct.rb', line 2000

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

- (Object) AcceptUnsignedFile(file, repo)



1949
1950
1951
1952
1953
1954
1955
1956
# File '../../src/modules/AddOnProduct.rb', line 1949

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

- (Object) AcceptVerificationFailed(file, key, repo)



1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
# File '../../src/modules/AddOnProduct.rb', line 1977

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

- (Object) add_rename(old_name, new_name)



2185
2186
2187
2188
2189
2190
2191
2192
# File '../../src/modules/AddOnProduct.rb', line 2185

def add_rename(old_name, new_name)
  # already known
  return if renamed?(old_name, new_name)

  log.info "Adding product rename: '#{old_name}' => '#{new_name}'"
  @product_renames[old_name] = [] unless @product_renames[old_name]
  @product_renames[old_name] << new_name
end

- (Object) AddOnMode(source_id)

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.

Parameters:

  • source_id (Fixnum)
  • string

    “installation” or “update” according the current state



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

- (Boolean) AddPreselectedAddOnProducts(filelist)

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>
			<!-- 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>
		</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" ]
 ]

Parameters:

  • filelist (Array<Hash{String => String>})

    list of maps describing one or several add_on_products files

Returns:

  • (Boolean)

    true on exit

See Also:

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


1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
# File '../../src/modules/AddOnProduct.rb', line 1642

def AddPreselectedAddOnProducts(filelist)
  filelist = deep_copy(filelist)
  if filelist == nil || filelist == []
    Builtins.y2milestone(
      "No add-on products defined on the media or by inst-sys"
    )
    return true
  end

  base_url = GetBaseProductURL()
  Builtins.y2milestone("Base URL: %1", URL.HidePassword(base_url))

  # Processes all add_on_products files found
  Builtins.foreach(filelist) do |add_on_products_file|
    filename = Ops.get(add_on_products_file, "file", "")
    type = Ops.get(add_on_products_file, "type", "")
    add_products = []
    # new xml format
    if type == "xml"
      add_products = ParseXMLBasedAddOnProductsFile(filename, base_url) 
      # old fallback
    elsif type == "plain"
      add_products = ParsePlainAddOnProductsFile(filename, base_url)
    else
      Builtins.y2error("Unsupported type: %1", type)
      next false
    end
    repo_id = -1
    Builtins.y2milestone("Adding products: %1", add_products)
    Builtins.foreach(add_products) do |one_product|
      url = Ops.get_string(one_product, "url", "")
      pth = Ops.get_string(one_product, "path", "")
      priority = Ops.get_integer(one_product, "priority", -1)
      prodname = Ops.get_string(one_product, "name", "")
      # Check URL and setup network if required or prompt to insert CD/DVD
      parsed = URL.Parse(url)
      scheme = Builtins.tolower(Ops.get_string(parsed, "scheme", ""))
      # check if network needs to be configured
      if Builtins.contains(
          ["http", "https", "ftp", "nfs", "cifs", "slp"],
          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
      if Builtins.contains(["cd", "dvd"], scheme)
        # if the CD/DVD product is known just try if it's there
        # and ask if not
        if prodname != ""
          found = false

          while !found
            repo_id = AddRepo(url, pth, priority)
            next false if repo_id == nil

            prod2 = Pkg.SourceProductData(repo_id)
            if Ops.get_string(prod2, "label", "") == prodname
              found = true
            else
              Builtins.y2milestone(
                "Removing repo %1: Add-on found: %2, expected: %3",
                repo_id,
                Ops.get_string(prod2, "label", ""),
                prodname
              )
              Pkg.SourceDelete(repo_id)

              # ask for a different medium
              url = AskForCD(url, prodname)
              next false if url == nil
            end
          end
        else
          result = AskForCD(url, prodname)
          next false if result == nil

          repo_id = AddRepo(result, pth, priority)
          next false if repo_id == nil
        end
      else
        # a non CD/DVD repository
        repo_id = AddRepo(url, pth, priority)
        next false if repo_id == nil
      end
      if !AcceptedLicenseAndInfoFile(repo_id)
        Builtins.y2warning("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)
      Builtins.y2milestone(
        "Repository (%1) product data: %2",
        repo_id,
        prod
      )
      InstallProductsFromRepository(
        Ops.get_list(one_product, "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
      }
      if Ops.greater_than(priority, -1)
        Ops.set(new_add_on_product, "priority", priority)
      end
      @add_on_products = Builtins.add(@add_on_products, new_add_on_product)
    end
  end

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

  true
end

- (Object) AddRepo(url, pth, priority)

Add a new repository

Parameters:

  • url

    repo url

  • pth

    product path

  • priority

Returns:

  • integer repository ID



1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
# File '../../src/modules/AddOnProduct.rb', line 1543

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)
  Ops.set(new_repo, "priority", priority) if Ops.greater_than(priority, -1)

  Builtins.y2milestone(
    "Adding Repository: %1, product path: %2",
    URL.HidePassword(url),
    pth
  )
  new_repo_id = Pkg.RepositoryAdd(new_repo)

  if new_repo_id == nil || Ops.less_than(new_repo_id, 0)
    Builtins.y2error("Unable to add product: %1", URL.HidePassword(url))
    # TRANSLATORS: error message, %1 is replaced with product URL
    Report.Error(
      Builtins.sformat(
        _("Unable to add product %1."),
        URL.HidePassword(url)
      )
    )
    return nil
  end

  # download metadata, build repo cache
  Pkg.SourceRefreshNow(new_repo_id)
  # load resolvables to zypp pool
  Pkg.SourceLoad

  new_repo_id
end

- (Object) AnyPatternInRepo



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

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

- (Object) AskForCD(url, product_name)

Ask for a product medium

Returns:

  • nil if aborted, otherwise URL with the selected CD device



1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File '../../src/modules/AddOnProduct.rb', line 1498

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

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

  # 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

- (Object) CheckProductDependencies(products)



1213
1214
1215
1216
1217
# File '../../src/modules/AddOnProduct.rb', line 1213

def CheckProductDependencies(products)
  products = deep_copy(products)
  # TODO check the dependencies of the product
  true
end

- (Object) CleanModeConfigSources



1893
1894
1895
1896
1897
1898
# File '../../src/modules/AddOnProduct.rb', line 1893

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

  nil
end

- (Object) CleanY2Update

Remove the /y2update directory from the system



525
526
527
528
529
# File '../../src/modules/AddOnProduct.rb', line 525

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

  nil
end

- (Object) ClearRegistrationRequest(src_id)



709
710
711
712
713
714
715
716
717
718
719
720
721
# File '../../src/modules/AddOnProduct.rb', line 709

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

- (Object) DeselectProductPatterns(src_id)

See also SelectProductPatterns()



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

def DeselectProductPatterns(src_id)
  # bnc #458297
  # Using PackagesProposal to deselect the patterns itself
  PackagesProposal.SetResolvables(
    PackagesProposalAddonID(src_id),
    :pattern,
    []
  )

  if Stage.initial
    Builtins.y2milestone(
      "Initial stage, using PackagesProposal to deselect patterns"
    )
    return true
  end

  patterns_to_deselect = Ops.get(@patterns_preselected_by_addon, src_id, [])

  if Builtins.size(patterns_to_deselect) == 0
    Builtins.y2milestone("There's no pattern to be deselected")
    return true
  end

  ret = true

  Builtins.foreach(patterns_to_deselect) do |one_pattern|
    if !Pkg.ResolvableNeutral(one_pattern, :pattern, true)
      Builtins.y2error(
        "Cannot deselect pattern: %1, reason: %2",
        one_pattern,
        Pkg.LastError
      )
      ret = false
    end
  end

  ret
end

- (Object) Disintegrate(srcid)

Opposite to Integrate()

Parameters:

  • srcid (Fixnum)

    integer the ID of the repository



1172
1173
1174
1175
1176
1177
1178
# File '../../src/modules/AddOnProduct.rb', line 1172

def Disintegrate(srcid)
  DeselectProductPatterns(srcid)

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

  nil
end

- (Symbol) DoInstall

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

Parameters:

  • string

    src_id

Returns:

  • (Symbol)

    the result symbol from wizard sequencer



908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
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
971
972
973
974
975
976
977
# File '../../src/modules/AddOnProduct.rb', line 908

def DoInstall
  # Display /media.1/info.txt 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 #302398: PATTERNS keyword in content file
  HandleProductPATTERNS(@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

- (Object) DoInstall_NoControlFile



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

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

- (Object) DoInstall_WithControlFile(control)



634
635
636
637
638
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
# File '../../src/modules/AddOnProduct.rb', line 634

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

- (Hash) Export

Returns map describing all used add-ons.

Structure:

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>

Returns:

  • (Hash)


1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
# File '../../src/modules/AddOnProduct.rb', line 1798

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

- (String) GetAbsoluteURL(base_url, url)

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:password@ftp://www.example.org/dir/",
  "relurl://./Product_CD1/"
) -> "username:password@ftp://www.example.org/dir/Product_CD1/"

Parameters:

  • base_url (String)
  • string

    relative_url

Returns:

  • (String)

    absolute_url



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

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)

    if 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
  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

- (Object) GetBaseProductURL



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

def GetBaseProductURL
  @base_product_url
end

- (String) GetCachedFileFromSource(src_id, media, filename, sod, optional)

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);

Parameters:

  • src_id (Fixnum)
  • media (Fixnum)
  • filename (String)
  • sod (String)

    (“signed” or “digested”)

  • optional (Boolean)

    (false if mandatory)

Returns:

  • (String)

    path to a cached file



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

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) != 0
      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

- (String) GetMode

Returns the current add-on installation mode.

Returns:

  • (String)

    current mode

See Also:

  • #SetMode()


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

def GetMode
  @_inst_mode
end

- (Object) HandleProductPATTERNS(srcid)



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File '../../src/modules/AddOnProduct.rb', line 1119

def HandleProductPATTERNS(srcid)
  # FATE #302398: PATTERNS keyword in content file
  content_file = GetCachedFileFromSource(
    srcid,
    1,
    "/content",
    "signed",
    true
  )

  if content_file == nil
    Builtins.y2warning("Add-On %1 doesn't have a content file", srcid)
  else
    SelectProductPatterns(content_file, srcid)
  end

  nil
end

- (Object) Import(settings)



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

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

- (Object) ImportGpgKeyCallback(key, repo)



2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
# File '../../src/modules/AddOnProduct.rb', line 2023

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

- (Boolean) InstallProductsFromRepository(prods_to_install, src)

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

Parameters:

Returns:

  • (Boolean)

    if successful



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
1488
1489
1490
# File '../../src/modules/AddOnProduct.rb', line 1458

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

- (Boolean) Integrate(srcid)

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

Parameters:

  • srcid (Fixnum)

    integer the ID of the repository

Returns:

  • (Boolean)

    true on success



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File '../../src/modules/AddOnProduct.rb', line 1142

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

  # Updating inst-sys
  y2update = GetCachedFileFromSource(
    srcid, # optional
    1,
    "/y2update.tgz",
    "digested",
    true
  )

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

  # FATE #302398: PATTERNS keyword in content file
  HandleProductPATTERNS(srcid)

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

  true
end

- (Object) IntegrateY2Update(src_id)



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

def IntegrateY2Update(src_id)
  binaries = GetCachedFileFromSource(
    src_id, # optional
    1,
    "/y2update.tgz",
    "digested",
    true
  )
  # 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) != 0
      # 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

- (Object) main



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

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 "Language"
  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 "PackageCallbacks"
  Yast.import "PackagesProposal"
  Yast.import "SourceManager"

  # 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 = {}

  # product renames needed for detecting the product update
  # this mapping can be updated by SCC registration server,
  # this is the static default for offline updates
  # mapping: <old_name> => [ <new_name> ]
  @product_renames = {
    "SUSE_SLES"  => [ "SLES" ],
    # SLED or Workstation extension
    "SUSE_SLED"  => [ "SLED", "sle-we" ],
    "sle-haegeo" => [ "sle-ha-geo" ],
    "sle-hae"    => [ "sle-ha" ]
  }

end

- (Object) PackagesProposalAddonID(src_id)



979
980
981
# File '../../src/modules/AddOnProduct.rb', line 979

def PackagesProposalAddonID(src_id)
  Builtins.sformat("Add-On-Product-ID:%1", src_id)
end

- (Array<Hash>) ParsePlainAddOnProductsFile(parse_file, base_url)

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]
  ]

Parameters:

  • parse_file (String)
  • base_url (String)

Returns:

  • (Array<Hash>)

    of products to add

See Also:

  • #303675


1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File '../../src/modules/AddOnProduct.rb', line 1239

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)),
    " \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) if Ops.get(elements, 0) != nil
    elements = Builtins.remove(elements, 0) if 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

- (Object) ParseXMLBasedAddOnProductsFile(parse_file, base_url)



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

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

- (Object) PrepareForRegistration(src_id)

Checks whether the content file of the add-on has a flag REGISTERPRODUCT set to “true” or “yes”. If it has, product is added into list of pruducts that need registration. Cached content file is used if possible.

Parameters:

  • integer

    source id



772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
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
817
818
819
820
821
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
# File '../../src/modules/AddOnProduct.rb', line 772

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

  if WorkflowManager.IncorporateControlFileOptions(control_file) == true
    # FATE #305578: Add-On Product Requiring Registration
    if WorkflowManager.WorkflowRequiresRegistration(src_id)
        Builtins.y2milestone("REGISTERPRODUCT (require_registration) defined in control file")
        @addons_requesting_registration << deep_copy(src_id)
        return nil
    end
  end


  tmpdir = Ops.add(
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    "/add-on-content-files/"
  )

  # create directory if doesn't exist
  if !FileUtils.Exists(tmpdir)
    run = Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat("/bin/mkdir -p '%1'", tmpdir)
      )
    )
    if run != 0
      Builtins.y2error("Cannot create directory %1", tmpdir)
      return nil
    end
  end

  # use cached file if possible
  contentfile = Builtins.sformat("%1content-%2", tmpdir, src_id)
  if FileUtils.Exists(contentfile)
    Builtins.y2milestone("Using cached contentfile %1", contentfile)
  else
    Builtins.y2milestone("Checking contentfile from repository")
    sourcefile = GetCachedFileFromSource(
      src_id,
      1,
      "/content",
      "signed",
      true
    )
    if sourcefile == nil
      Builtins.y2warning("Cannot obtain content file!")
      return nil
    end
    # copying content file
    run = Convert.to_integer(
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat(
          "/bin/cp '%1' '%2'",
          String.Quote(sourcefile),
          String.Quote(contentfile)
        )
      )
    )
    if run != 0
      Builtins.y2error("Cannot copy '%1' to '%2'", sourcefile, contentfile)
      return nil
    end
  end

  # registering agent for the current content file
  SCR.RegisterAgent(
    path(".addon.content"),
    term(
      :ag_ini,
      term(
        :IniAgent,
        contentfile,
        {
          "options"  => ["read_only", "global_values", "flat"],
          "comments" => ["^#.*", "^[ \t]*$"],
          "params"   => [
            {
              "match" => [
                "^[ \t]*([a-zA-Z0-9_.]+)[ \t]*(.*)[ \t]*$",
                "%s %s"
              ]
            }
          ]
        }
      )
    )
  )
  register_product = Convert.to_string(
    SCR.Read(path(".addon.content.REGISTERPRODUCT"))
  )
  SCR.UnregisterAgent(path(".addon.content"))

  # evaluating REGISTERPRODUCT flag, default (nil == false)
  Builtins.y2milestone(
    "RegisterProduct flag for repository %1 is %2",
    src_id,
    register_product
  )
  if register_product == "yes" || register_product == "true"
    @addons_requesting_registration = Builtins.add(
      @addons_requesting_registration,
      src_id
    )
  end

  nil
end

- (Boolean) ProcessRegistration

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

Returns:

  • (Boolean)

    if requested



727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File '../../src/modules/AddOnProduct.rb', line 727

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

- (Object) ReadTmpExportFilename

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

See Also:

  • #187558


1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
# File '../../src/modules/AddOnProduct.rb', line 1911

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

- (Object) RegisterAddOnProduct(src_id)

Calls registration client if needed.

Parameters:

  • integer

    source id



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File '../../src/modules/AddOnProduct.rb', line 885

def RegisterAddOnProduct(src_id)
  # FATE #305578: Add-On Product Requiring Registration
  # or check the content file
  if WorkflowManager.WorkflowRequiresRegistration(src_id) || Builtins.contains(@addons_requesting_registration, src_id)
    Builtins.y2milestone("Repository ID %1 requests registration", src_id)
    # TODO FIXME: user needs to manually select the addon to register,
    # pass the addon so it could be pre-selected
    WFM.CallFunction("inst_scc", [])
  else
    Builtins.y2milestone(
      "Repository ID %1 doesn't need registration",
      src_id
    )
  end

  nil
end

- (Object) ReIntegrateFromScratch

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



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
1207
1208
1209
1210
1211
# File '../../src/modules/AddOnProduct.rb', line 1181

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

- (Object) RejectFileWithoutChecksum(file)



1972
1973
1974
1975
# File '../../src/modules/AddOnProduct.rb', line 1972

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

- (Object) RejectUnsignedFile(file, repo)



1958
1959
1960
1961
1962
1963
1964
1965
# File '../../src/modules/AddOnProduct.rb', line 1958

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

- (Object) RejectVerificationFailed(file, key, repo)



1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
# File '../../src/modules/AddOnProduct.rb', line 1988

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

- (Object) RemoveRegistrationFlag(src_id)

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



747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File '../../src/modules/AddOnProduct.rb', line 747

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

- (Boolean) renamed?(old_name, new_name)

Returns:

  • (Boolean)


2181
2182
2183
# File '../../src/modules/AddOnProduct.rb', line 2181

def renamed?(old_name, new_name)
  @product_renames[old_name] && @product_renames[old_name].include?(new_name)
end

- (Object) RereadAllSCRAgents

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

See Also:

  • #239055, #245508


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

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

- (Object) SelectProductPatterns(content_file, src_id)

See also DeselectProductPatterns()



984
985
986
987
988
989
990
991
992
993
994
995
996
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
1035
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
# File '../../src/modules/AddOnProduct.rb', line 984

def SelectProductPatterns(content_file, src_id)
  if !FileUtils.Exists(content_file)
    Builtins.y2error("No such file: %1", content_file)
    return false
  end

  contentmap = Convert.to_map(SCR.Read(path(".content_file"), content_file))

  # no PATTERNS defined
  if !Builtins.haskey(contentmap, "PATTERNS")
    Builtins.y2milestone(
      "Add-On doesn't have any required patterns (PATTERNS in content)"
    )
    return true
  end

  # parsing PATTERNS
  patterns_to_select = Builtins.splitstring(
    Ops.get_string(contentmap, "PATTERNS", ""),
    "\t "
  )
  patterns_to_select = Builtins.filter(patterns_to_select) do |one_pattern|
    one_pattern != nil && one_pattern != ""
  end

  if Builtins.size(patterns_to_select) == 0
    Builtins.y2error(
      "Erroneous PATTERNS: %1",
      Ops.get_string(contentmap, "PATTERNS", "")
    )
    return false
  end

  Builtins.y2milestone(
    "Add-On requires these PATTERNS: %1",
    patterns_to_select
  )
  # clear/set
  Ops.set(@patterns_preselected_by_addon, src_id, [])

  # bnc #458297
  # Using PackagesProposal to select the patterns itself
  PackagesProposal.SetResolvables(
    PackagesProposalAddonID(src_id),
    :pattern,
    patterns_to_select
  )

  if Stage.initial
    Builtins.y2milestone("Using PackagesProposal to select Add-On patterns")
    return true
  end

  ret = true

  Builtins.foreach(patterns_to_select) do |one_pattern|
    pattern_properties = Pkg.ResolvableProperties(one_pattern, :pattern, "")
    already_selected = false
    Builtins.foreach(pattern_properties) do |one_pattern_found|
      patt_status = Ops.get_symbol(one_pattern_found, "status", :unknown)
      # patern is already selected
      if patt_status == :installed || patt_status == :selected
        already_selected = true
        raise Break
      end
    end
    if already_selected
      Builtins.y2milestone(
        "Pattern %1 is already installed/selected",
        one_pattern
      )
      next
    end
    if !Pkg.ResolvableInstall(one_pattern, :pattern)
      Builtins.y2error(
        "Cannot select pattern: %1, reason: %2",
        one_pattern,
        Pkg.LastError
      )
      ret = false
    else
      Ops.set(
        @patterns_preselected_by_addon,
        src_id,
        Builtins.add(
          Ops.get(@patterns_preselected_by_addon, src_id, []),
          one_pattern
        )
      )
    end
  end

  ret
end

- (Object) SetBaseProductURL(url)



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

- (Object) SetMode(new_mode)

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.

Parameters:

  • new_mode (String)

    (“installation” or “update”)

See Also:

  • #GetMode();


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

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

- (Object) SetRepoUrlAlias(url, _alias, name)

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.



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

def SetRepoUrlAlias(url, _alias, 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 != nil && _alias != ""
    url_p = URL.Parse(url)
    params = URL.MakeMapFromParams(Ops.get_string(url_p, "query", ""))
    new_alias = ""

    if _alias != nil && _alias != ""
      new_alias = _alias
      Builtins.y2milestone("Using repository alias: '%1'", new_alias)
    else
      # no alias present in the URL, use the product name
      if 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
    end

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

  url
end

- (Object) SetSignatureCallbacks(product)



2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
# File '../../src/modules/AddOnProduct.rb', line 2101

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(
        Ops.get_boolean(
          addon,
          ["signature-handling", "accept_unsigned_file"],
          false
        ) ?
          fun_ref(method(:AcceptUnsignedFile), "boolean (string, integer)") :
          fun_ref(method(:RejectUnsignedFile), "boolean (string, integer)")
      )
    end
    if Builtins.haskey(
        Ops.get_map(addon, "signature-handling", {}),
        "accept_file_without_checksum"
      )
      Pkg.CallbackAcceptFileWithoutChecksum(
        Ops.get_boolean(
          addon,
          ["signature-handling", "accept_file_without_checksum"],
          false
        ) ?
          fun_ref(method(:AcceptFileWithoutChecksum), "boolean (string)") :
          fun_ref(method(:RejectFileWithoutChecksum), "boolean (string)")
      )
    end
    if Builtins.haskey(
        Ops.get_map(addon, "signature-handling", {}),
        "accept_verification_failed"
      )
      Pkg.CallbackAcceptVerificationFailed(
        Ops.get_boolean(
          addon,
          ["signature-handling", "accept_verification_failed"],
          false
        ) ?
          fun_ref(
            method(:AcceptVerificationFailed),
            "boolean (string, map <string, any>, integer)"
          ) :
          fun_ref(
            method(:RejectVerificationFailed),
            "boolean (string, map <string, any>, integer)"
          )
      )
    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

- (Object) TmpExportFilename

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

See Also:

  • #187558


1904
1905
1906
# File '../../src/modules/AddOnProduct.rb', line 1904

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

- (Boolean) UpdateInstSys(filename)

Adapts the inst-sys from the tarball

Parameters:

  • filename (String)

    string the filename with the tarball to use to the update

Returns:

  • (Boolean)

    true on success



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

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) != 0
    Builtins.y2error("Including installation image failed: %1", out)
    return false
  end
  Builtins.y2milestone("Including installation image succeeded")
  true
end

- (Object) UserSelectsRequiredAddOns(products)



1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
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
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
# File '../../src/modules/AddOnProduct.rb', line 1278

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(
      HBox(
        HSquash(MarginBox(0.5, 0.2, Icon.Simple("yast-addon"))),
        # 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.\nSelect 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