diff --git a/src/lib/registration/releasever.rb b/src/lib/registration/releasever.rb new file mode 100644 index 000000000..ba597ebd2 --- /dev/null +++ b/src/lib/registration/releasever.rb @@ -0,0 +1,81 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) 2015 SUSE LLC, All Rights Reserved. +# +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, contact SUSE LLC. +# +# To contact SUSE about this file by physical or electronic mail, you may find +# current contact information at www.suse.com. +# ------------------------------------------------------------------------------ + +require "yast" +require "registration/sw_mgmt" + +require "uri" + +module Registration + # this class handles activating the new releasever value in the package management + class Releasever + include Yast::Logger + + # the placeholder used in the URL + RELEASEVER_ID = "$releasever" + + Yast.import "Pkg" + + attr_reader :version + + # constructor + # @param [String] version the new release version value + def initialize(version) + @version = version + end + + # activate the new releasever + def activate + log.info "Setting $releasever to: #{version}" + # export the settings + ENV["ZYPP_REPO_RELEASEVER"] = version + + repos = releasever_repos + return if repos.empty? + + refresh(repos) + # refresh the loaded packages + SwMgmt.sync_pool + end + + private + + # get the repositories which contain "$releasever" directory in the URL + # @return [Array] the repository list + def releasever_repos + repos = Yast::Pkg.SourceGetCurrent(true) + repos.select do |repo| + data = Pkg.SourceGeneralData(repo) + + url = URI(data["url"]) + url.path.split("/").include?(RELEASEVER_ID) + end + end + + # refresh the requested repositories + # @param [Array] repos the repositories to refresh + def refresh(repos) + repos.each do |repo| + log.info "Refreshing repository #{repo}" + Yast::Pkg.SourceForceRefreshNow(repo) + end + end + end +end diff --git a/src/lib/registration/sw_mgmt.rb b/src/lib/registration/sw_mgmt.rb index 774df67d1..97fe4e1c2 100644 --- a/src/lib/registration/sw_mgmt.rb +++ b/src/lib/registration/sw_mgmt.rb @@ -450,6 +450,14 @@ def self.products_from_repo(repo_id) end end + # synchronize the changes done by modifying the services or repositories, + # reinitialize the repositories and reload the available packages + def self.sync_pool + Yast::Pkg.SourceFinishAll + Yast::Pkg.SourceRestore + Yast::Pkg.SourceLoad + end + def self.get_release_type(product) if product["product_line"] oem_file = File.join(OEM_DIR, product["product_line"]) diff --git a/src/lib/registration/ui/migration_repos_workflow.rb b/src/lib/registration/ui/migration_repos_workflow.rb index d8b5f561a..7ff888f6a 100644 --- a/src/lib/registration/ui/migration_repos_workflow.rb +++ b/src/lib/registration/ui/migration_repos_workflow.rb @@ -17,6 +17,7 @@ require "registration/registration" require "registration/registration_ui" require "registration/migration_repositories" +require "registration/releasever" require "registration/sw_mgmt" require "registration/ui/migration_selection_dialog" require "registration/ui/migration_repos_selection_dialog" @@ -111,6 +112,9 @@ def run "select_migration_products" => { abort: :abort, cancel: :abort, + next: "update_releasever" + }, + "update_releasever" => { next: "register_migration_products" }, "register_migration_products" => { @@ -138,6 +142,7 @@ def run_sequence "find_products" => [->() { find_products }, true], "load_migration_products" => [->() { load_migration_products }, true], "select_migration_products" => ->() { select_migration_products }, + "update_releasever" => ->() { update_releasever }, "register_migration_products" => [->() { register_migration_products }, true], "activate_migration_repos" => [->() { activate_migration_repos }, true], "select_migration_repos" => ->() { select_migration_repos } @@ -255,9 +260,7 @@ def register_migration_products # synchronize the changes done by modifying the services, # reinitialize the repositories and reload the available packages - Yast::Pkg.SourceFinishAll - Yast::Pkg.SourceRestore - Yast::Pkg.SourceLoad + SwMgmt.sync_pool log.info "Registered services: #{registered_services}" :next @@ -309,6 +312,21 @@ def activate_migration_repos def select_migration_repos UI::MigrationReposSelectionDialog.run end + + # update the $releasever + def update_releasever + new_base = selected_migration.find(&:base) + + if new_base + log.info "Activating new releasever for base product: #{new_base}" + releasever = Releasever.new(new_base.version) + releasever.activate + else + log.info "The base system is not updated, skipping releasever update" + end + + :next + end end end end