chroot/build: add mount_gpg()

This commit is contained in:
InsanePrawn 2024-04-02 12:23:52 +02:00
parent 871c4f27c7
commit 07436a0ad2

View file

@ -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)