Sign part 2

This commit is contained in:
alexey
2025-03-21 23:15:46 +03:00
parent c6a89e7be1
commit e6d3a90231
17 changed files with 485 additions and 12 deletions

View File

@@ -3,6 +3,9 @@ $LOAD_PATH.unshift File.expand_path(".", "locallibs/ruby-rpm-ffi/lib")
require "rpm"
require_relative "runner"
require "ptools"
require "fileutils"
require "erb"
class RPMReader
def get_rpm_info(path_to_rpm)
@@ -29,9 +32,29 @@ class RepoManagerKeys
key_file = File.join(@path, "public", "mockgui-gpg-key")
File.exist?(key_file)
end
end
#rpm --define "_gpg_sign_cmd_extra_args --pinentry-mode loopback --passphrase 1234" --addsign bayrepo-neuro-farm-0.1-2.x86_64.rpm
def check_password_exists()
passwd = nil
passwd_file = File.join(@path, "save")
if File.exist?(passwd_file)
unless File.binary?(passwd_file)
passwd = File.readlines(passwd_file).first.strip
end
end
passwd
end
def get_publick_key()
File.join(@path, "public", "mockgui-gpg-key")
end
def sign_package(rpm_path, password)
cmd_args = %Q(/usr/bin/rpm --define "_gpg_sign_cmd_extra_args --pinentry-mode loopback --passphrase #{password}" --addsign "#{rpm_path}" 2>/dev/null)
cmd = Runner.new(cmd_args)
cmd.run
cmd.exit_status
end
end
class RepoManager
attr :path, :error, :last_status, :last_pid
@@ -60,4 +83,53 @@ class RepoManager
def get_rpm_info(path_to_rpm)
@reader.get_rpm_info(path_to_rpm)
end
def repoview(url, repo_name, template_dir)
rpm_list = get_rpms_list(@path)
result = {}
rpm_list.each do |item|
full_rpm_path = File.join(@path, item)
info = @reader.get_rpm_info(full_rpm_path)
dirName = File.dirname(item)
fileName = File.basename(item)
if result[dirName].nil?
result[dirName] = []
end
pkg_info = {}
pkg_info[:fname] = fileName
pkg_info[:stat] = File.stat(full_rpm_path).ctime
if info[:error].nil?
pkg_info[:chlog] = info[:pkginfo].changelog.first(5)
else
pkg_info[:chlog] = []
end
result[dirName] << pkg_info
end
repo_name = repo_name
repo_url = url
pkg_num = rpm_list.length
repo_data = []
data_keys = []
result.each_pair do |key, value|
result[key.to_s].sort_by! { |item| item[:fname] }
data_keys << key.to_s
end
data_keys.sort!
data_keys.each do |item|
repo_data << result[item]
end
tpl_file = File.join(template_dir, "template.erb")
template = File.read(tpl_file)
renderer = ERB.new(template)
result_html = renderer.result(binding)
boots_trap_css = File.join(template_dir, "bootstrap.min.css")
boots_trap_js = File.join(template_dir, "bootstrap.bundle.min.js")
index_html = File.join(@path, "index.html")
File.open(index_html, "w") do |f|
f.write(result_html)
end
FileUtils.cp_r(boots_trap_css, @path, verbose: false, remove_destination: true)
FileUtils.cp_r(boots_trap_js, @path, verbose: false, remove_destination: true)
end
end