From 07436a0ad2b0988e8455ffd12fc18dfb9c6df1c7 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Tue, 2 Apr 2024 12:23:52 +0200 Subject: [PATCH] chroot/build: add mount_gpg() --- chroot/build.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/chroot/build.py b/chroot/build.py index 40b123d..b33000e 100644 --- a/chroot/build.py +++ b/chroot/build.py @@ -1,3 +1,4 @@ +import atexit import logging import os import subprocess @@ -7,6 +8,7 @@ from typing import ClassVar, Optional from config.state import config from constants import Arch, GCC_HOSTSPECS, CROSSDIRECT_PKGS, CHROOT_PATHS from distro.distro import get_kupfer_local +from distro.gpg import GPG_HOME_DIR from exec.cmd import run_root_cmd from exec.file import makedir, remove_file, root_makedir, root_write_file, symlink @@ -159,6 +161,25 @@ class BuildChroot(Chroot): )) return results + def mount_gpg(self, fail_if_mounted: bool = False, schedule_gpg_kill: bool = True) -> str: + res = self.mount( + absolute_source=config.get_path('gpg'), + relative_destination=CHROOT_PATHS['gpg'].lstrip('/'), + fail_if_mounted=fail_if_mounted, + ) + if schedule_gpg_kill: + atexit.register(self.kill_gpg_agent) + return res + + def get_gpg_home(self, host_path: bool = False) -> str: + gpg_home = os.path.join(CHROOT_PATHS['gpg']. GPG_HOME_DIR) + if host_path: + gpg_home = self.get_path(gpg_home) + return gpg_home + + def kill_gpg_agent(self) -> subprocess.CompletedProcess: + res = self.run_cmd(["timeout", "2s", "gpgconf", "--kill", "gpg-agent"], inner_env={"GNUPGHOME": self.get_gpg_home()}) + logging.debug(f"GPG agent killed: {res.returncode=}, {res.stdout=}, {res.stderr}") def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> BuildChroot: name = build_chroot_name(arch)