Sign part 2
This commit is contained in:
@@ -3,6 +3,7 @@ require_relative "db"
|
||||
require_relative "repomanage"
|
||||
require_relative "mock"
|
||||
require_relative "utilities"
|
||||
require "digest"
|
||||
|
||||
PROJECTS_STRUCTURE = {
|
||||
:REPO => "repo",
|
||||
@@ -371,4 +372,86 @@ class ProjectsActions
|
||||
end
|
||||
@error
|
||||
end
|
||||
|
||||
def sign_project(prj_id, key_path, password, url, tpl_dir)
|
||||
@error = nil
|
||||
proj_path = get_project_path(prj_id)
|
||||
sign_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:SIGNED])
|
||||
repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||
repo_sign = RepoManager.new(sign_repo_path)
|
||||
repo_key = RepoManagerKeys.new(key_path)
|
||||
if password.nil?
|
||||
password = repo_key.check_password_exists
|
||||
end
|
||||
if password.nil?
|
||||
@error = "Не указан пароль для подписи"
|
||||
else
|
||||
repo_lock = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS], ".repolock")
|
||||
sign_lock = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS], ".signlock")
|
||||
prj = @db.proj(prj_id)
|
||||
if repo_key.check_key_exists
|
||||
File.open(sign_lock, File::RDWR | File::CREAT) do |s|
|
||||
s.flock(File::LOCK_EX)
|
||||
File.open(repo_lock, File::RDWR | File::CREAT) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
rpm_list = get_rpms_list(repo_path)
|
||||
if prj[:public] == 0
|
||||
rpm_list = rpm_list.reject do |item|
|
||||
block = false
|
||||
block = true if item =~ /\.src\.rpm$/ || item =~ /SRPMS/ || item =~ /Debug/ || item =~ /(debuginfo.+rpm$)|(debugsource.+rpm$)/
|
||||
block
|
||||
end
|
||||
end
|
||||
rpm_signed_list = get_rpms_list(sign_repo_path)
|
||||
rpm_list = rpm_list.select do |item|
|
||||
sign_repo_path_rpm = File.join(sign_repo_path, item)
|
||||
unless File.exist?(sign_repo_path_rpm)
|
||||
file_path_full = File.join(repo_path, item)
|
||||
unless File.exist?(File.dirname(sign_repo_path_rpm))
|
||||
FileUtils.mkdir_p(File.dirname(sign_repo_path_rpm))
|
||||
end
|
||||
FileUtils.cp_r(file_path_full, File.dirname(sign_repo_path_rpm), verbose: false, remove_destination: false)
|
||||
sha256 = Digest::SHA256.file(file_path_full)
|
||||
rpm_info = @db.get_rpm_info_by_hash(sha256.hexdigest)
|
||||
unless rpm_info.nil?
|
||||
@db.update_rpm_sign(rpm_info[:id], sign_repo_path_rpm)
|
||||
end
|
||||
repo_key.sign_package(sign_repo_path_rpm, password)
|
||||
end
|
||||
end
|
||||
repo_url = "http://localhost/"
|
||||
if prj[:remote_address].nil? || prj[:remote_address].strip == ""
|
||||
repo_url = url
|
||||
else
|
||||
repo_url = prj[:remote_address]
|
||||
end
|
||||
if repo_url[-1] != "/"
|
||||
repo_url = repo_url + "/"
|
||||
end
|
||||
repo_sign.repoview(repo_url, prj[:projname], tpl_dir)
|
||||
repo_sign.create_repo
|
||||
end
|
||||
end
|
||||
else
|
||||
@error = "Ключ для подписи отсутствует"
|
||||
end
|
||||
end
|
||||
@error
|
||||
end
|
||||
|
||||
def set_address(prj_id, address)
|
||||
@error = nil
|
||||
if address.nil?
|
||||
address = ""
|
||||
else
|
||||
address = address.strip
|
||||
end
|
||||
@db.set_project_address(prj_id, address)
|
||||
@error
|
||||
end
|
||||
|
||||
def get_sign_path(id)
|
||||
path = get_project_path(id)
|
||||
File.join(path, PROJECTS_STRUCTURE[:SIGNED])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user