lib/rubygems-requirements-system/platform/fedora.rb in rubygems-requirements-system-0.0.2 vs lib/rubygems-requirements-system/platform/fedora.rb in rubygems-requirements-system-0.0.3
- old
+ new
@@ -29,28 +29,100 @@
def target?(platform)
platform == "fedora"
end
+ def valid_system_package?(package)
+ return true unless package.start_with?("module:")
+
+ action, target = parse_module_system_package(package)
+ case action
+ when "enable", "disable"
+ else
+ return false
+ end
+ return false if target.nil?
+
+ true
+ end
+
+ def valid_system_repository?(repository)
+ baseurl = repository["baseurl"]
+ return false if baseurl.nil?
+ return false if baseurl.empty?
+
+ true
+ end
+
def default_system_packages(packages)
packages.collect {|package| "pkgconfig(#{package.id})"}
end
private
+ def parse_module_system_package(package)
+ # "module: disable: postgresql" ->
+ # ["module", "disable", "postgresql"]
+ _, action, target = package.split(/:\s*/, 3)
+ [action, target]
+ end
+
def install_command_line(package)
+ if package.is_a?(SystemRepository)
+ install_command_line_repository(package)
+ elsif package.start_with?("module:")
+ install_command_line_module(package)
+ else
+ install_command_line_package(package)
+ end
+ end
+
+ def install_command_line_repository(repository)
+ temporary_file_base_name = [
+ "rubygems-requirements-system-fedora-#{repository.id}",
+ ".repo",
+ ]
+ repo = create_temporary_file(temporary_file_base_name)
+ repo.puts("[#{repository.id}]")
+ {
+ "name" => resolve_value_template(repository["name"]),
+ "baseurl" => resolve_value_template(repository["baseurl"]),
+ "enabled" => "1",
+ "gpgcheck" => repository["gpgkey"] ? "1" : "0",
+ "gpgkey" => resolve_value_template(repository["gpgkey"]),
+ }.each do |key, value|
+ next if value.nil?
+ repo.puts("#{key}=#{value}")
+ end
+ repo.close
+ FileUtils.chmod("go+r", repo.path)
+ [
+ "cp",
+ repo.path,
+ "/etc/yum.repos.d/#{repository.id}.repo",
+ ]
+ end
+
+ def install_command_line_module(package)
+ action, target = parse_module_system_package(package)
+ ["dnf", "-y", "module", action, target]
+ end
+
+ def install_command_line_package(package)
if package.start_with?("https://")
- package = resolve_package_url_template(package)
+ package = resolve_value_template(package)
end
- ["dnf", "install", "-y", package]
+ ["dnf", "-y", "install", package]
end
def need_super_user_priviledge?
true
end
- def resolve_package_url_template(package_url_template)
+ def resolve_value_template(template)
+ return nil if template.nil?
+
os_release = OSRelease.new
- package_url_template % {
+ template % {
distribution: os_release.id,
major_version: major_version.to_s,
version: os_release.version_id,
}
end