Skip to content

Commit

Permalink
Refresh Addons
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 15, 2018
1 parent 6e1513d commit e625dd7
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/lib/registration/ui/offline_migration_workflow.rb
Expand Up @@ -27,6 +27,7 @@ class OfflineMigrationWorkflow
Yast.import "Installation"
Yast.import "Wizard"
Yast.import "Pkg"
Yast.import "AddOnProduct"

# the constructor
def initialize
Expand All @@ -52,19 +53,19 @@ def main
if Registration.is_registered?
log.info("Restoring the previous registration")
rollback
restore_installation_repos
end

return :back
else
backup_installation_repos
end

# run the main registration migration
ui = migration_repos

rollback if ui == :rollback

# refresh the add-on records
update_addon_records

# go back in the upgrade workflow after rollback or abort,
# maybe the user justelected a wrong partition to upgrade
ui = :back if ui == :abort || ui == :rollback
Expand All @@ -78,6 +79,7 @@ def main
def rollback
Yast::WFM.CallFunction("registration_sync")

# cleanup the copied credentials file
if Yast::Stage.initial && File.exist?(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
log.info("Removing #{SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE}...")
File.delete(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
Expand All @@ -88,22 +90,26 @@ def migration_repos
Yast::WFM.CallFunction("inst_migration_repos", [{ "enable_back" => true }])
end

def backup_installation_repos
ids = Yast::Pkg.SourceGetCurrent(false)
@@repos_backup = ids.map { |r| Yast::Pkg.SourceGeneralData(r) }
end

def restore_installation_repos
return unless @@repos_backup
Yast::Pkg.SourceFinishAll
Yast::Pkg.TargetFinish
Yast::Pkg.TargetInitialize("/")

@@repos_backup.each { |r| Yast::Pkg.RepositoryAdd(r) }
# update the repository IDs in the AddOnProduct records
def update_addon_records
Yast::AddOnProduct.add_on_products.each do |addon|
url = addon["media_url"]
dir = addon["product_dir"]
log.info("Refreshing repository ID for addon #{addon["product"]} (#{url})")

new_id = Yast::Pkg.SourceGetCurrent(false).find do |repo|
data = Yast::Pkg.SourceGeneralData(repo)
# the same URL and product dir?
data["url"] == url && data["product_dir"] == dir
end

Yast::Pkg.SourceLoad
Yast::Pkg.TargetFinish
Yast::Pkg.TargetInitialize(Yast::Installation.destdir)
if new_id
log.info("Updating ID: #{addon["media"]} -> #{new_id}")
addon["media"] = new_id
else
log.warn("Addon not found 😦")
end
end
end
end
end
Expand Down

0 comments on commit e625dd7

Please sign in to comment.