WIP: keyrings 2

This commit is contained in:
InsanePrawn 2023-04-17 18:56:24 +02:00
parent a982f8c966
commit 30c3fa77fd
4 changed files with 33 additions and 22 deletions

View file

@ -6,9 +6,9 @@ from typing import Optional
from config.state import config
from constants import Arch, KEYRINGS_KEY, KEYRINGS_LOCAL_KEY
from distro.repo_config import get_repo_config
from exec.cmd import CompletedProcess, run_cmd
from exec.file import makedir, remove_file
from repo_config import get_repo_config
from utils import extract_files_from_tar_generator, read_files_from_tar_recursive
from .distro import Distro, get_base_distro, get_kupfer_local, get_kupfer_https
@ -24,9 +24,9 @@ PKG_KEYRING_FOLDER = 'usr/share/pacman/keyrings/'
class DistroType(Enum):
BASE = auto
LOCAL = auto
REMOTE = auto
BASE = auto()
LOCAL = auto()
REMOTE = auto()
KEYRING_LOCATIONS: dict[DistroType, str] = {
@ -69,13 +69,15 @@ def init_keyring_gpg_dir(
remove_file(gpg_dir)
exists = False
lazy = lazy and exists
makedir(gpg_dir)
if not lazy:
run_cmd([get_pacman_key_binary(), '--init', '--gpgdir', gpg_dir])
results = {}
for name, val in keyring_dists.items():
dist_dir, dist_changed = val
if lazy and not dist_changed:
results[name] = False
continue
logging.info(f"Importing dir {dist_dir} into {gpg_dir}")
import_dist_keyring(gpg_dir, dist_dir)
results[name] = True
return results
@ -86,8 +88,7 @@ def import_dist_keyring(
dist_dir: str,
) -> CompletedProcess:
assert gpg_dir and dist_dir and config.runtime.script_source_dir
pacman_key = os.path.join(config.runtime.script_source_dir, 'bin', 'pacman-key-user')
r = run_cmd([pacman_key, '--populate-from', dist_dir, '--populate', '--gpgdir', gpg_dir])
r = run_cmd([get_pacman_key_binary(), '--populate-from', dist_dir, '--populate', '--gpgdir', gpg_dir])
assert isinstance(r, CompletedProcess)
return r
@ -117,6 +118,7 @@ def init_keyring_dist_dir(
elif distro_type == DistroType.REMOTE:
pkg_names = repo_config.get(KEYRINGS_KEY, None) or []
distro = get_kupfer_https(arch, scan=False)
logging.debug(f"Acquiring keyrings from {distro}: {pkg_names}")
dist_pkgs, changed = acquire_dist_pkgs(pkg_names, distro, base_dir)
if lazy and dist_pkgs and not changed and os.path.exists(dist_dir): # and keyring_is_created(arch, distro_type):
return {name: (val[0], False) for name, val in dist_pkgs.items()}
@ -169,6 +171,7 @@ def acquire_dist_pkgs(keyring_packages: list[str], distro: Distro, dist_dir: str
def extract_keyring_pkg(pkg_path: str, dest_path: str):
makedir(dest_path)
extract_files_from_tar_generator(
read_files_from_tar_recursive(pkg_path, PKG_KEYRING_FOLDER),
dest_path,
@ -186,3 +189,7 @@ def get_keyring_dist_path(base_dir: str) -> str:
def get_keyring_gpg_path(base_dir: str) -> str:
return os.path.join(base_dir, KEYRING_GPG_DIR)
def get_pacman_key_binary() -> str:
return os.path.join(config.runtime.script_source_dir, 'bin', 'pacman-key-user')