-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
|
||
|
||
require "yast" | ||
|
||
Yast.import "Pkg" | ||
|
||
module Installation | ||
class SelfupdateAddonFilter | ||
|
||
PROVIDES_INSTALLATION = "system-installation()".freeze | ||
|
||
# | ||
# Returns a filtering lambda function | ||
# Returns package name from the selected repository which should be used | ||
# in an update repository instead of applying to the ins-sys. | ||
# | ||
# @return [lambda] the filter | ||
# @param repo_id [Integer] the self-update repository ID | ||
# @return [Array<String>] the list of packages which should be used | ||
# in an addon repository | ||
# | ||
def self.filter | ||
# The "pkg" parameter is a single package from the Pkg.ResolvableDependencies() call | ||
lambda do |pkg| | ||
deps = pkg["deps"] || [] | ||
|
||
deps.any? do |d| | ||
# Example dependency: {"provides"=>"system-installation() = SLES"} | ||
d["provides"] && d["provides"].start_with?("system-installation()") | ||
end | ||
def self.packages(repo_id) | ||
|
||
# returns list like [["skelcd-control-SLED", :CAND, :NONE], | ||
# ["skelcd-control-SLES", :CAND, :NONE],...] | ||
skelcds = Yast::Pkg.PkgQueryProvides(PROVIDES_INSTALLATION) | ||
|
||
pkgs = skelcds.map{ |s| s.first}.uniq | ||
|
||
# there should not be present any other repository except the self update at this point, | ||
# but rather be safe than sorry... | ||
|
||
pkgs.select! do |pkg| | ||
props = Yast::Pkg.ResolvableProperties(pkg, :package, "") | ||
props.any?{|p| p["source"] == repo_id} | ||
end | ||
|
||
log.info "Found addon packages in the self update repository: #{pkgs}" | ||
|
||
pkgs | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
|
||
require "fileutils" | ||
require "uri" | ||
|
||
require "yast" | ||
require "installation/selfupdate_addon_filter" | ||
require "packages/package_downloader" | ||
|
||
Yast.import "Directory" | ||
Yast.import "Pkg" | ||
|
||
module Installation | ||
class SelfupdateAddonRepo | ||
extend Yast::Logger | ||
|
||
REPO_PATH = File.join(Yast::Directory.vardir, "self_update_addon").freeze | ||
|
||
# | ||
# Create an addon repository from the self-update repository | ||
# containing specific packages. The repository is a plaindir type | ||
# and does not contain any metadata. | ||
# | ||
# @param repo_id [Integer] repo_id repository ID | ||
# @param path [String] path where to download the packages | ||
# | ||
# @return [Boolean] true if a repository has been created, | ||
# false when no addon package was found in the self update repository | ||
# | ||
def self.copy_packages(repo_id, path = REPO_PATH) | ||
pkgs = Installation::SelfupdateAddonFilter.packages(repo_id) | ||
return false if pkgs.empty? | ||
|
||
log.info("Addon packages to download: #{pkgs}") | ||
|
||
::FileUtils.mkdir_p(path) | ||
|
||
pkgs.each do |pkg| | ||
downloader = Packages::PackageDownloader.new(repo_id, pkg["name"]) | ||
log.info("Downloading package #{pkg["name"]}...") | ||
downloader.download(File.join(path, pkg["name"]) | ||
end | ||
|
||
log.debug { "Downloaded packages: #{Dir["#{path}/*"]}" } | ||
|
||
true | ||
end | ||
|
||
def self.present?(path = REPO_PATH) | ||
# the directory exists and is not empty | ||
ret = File.exist?(path) && !Dir.empty?(path) | ||
log.info("Repository #{path} exists: #{ret}") | ||
ret | ||
end | ||
|
||
def self.create_repo(path = REPO_PATH) | ||
# create a plaindir repository, there is no package metadata | ||
ret = Yast::Pkg.SourceCreateType("dir://#{URI.escape(path)}", "", "Plaindir") | ||
log.info("Created self update addon repo: #{ret}") | ||
ret | ||
end | ||
|
||
end | ||
end |