mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
chroot.py: fixes
This commit is contained in:
parent
4643cc499a
commit
4cc0235329
1 changed files with 16 additions and 7 deletions
23
chroot.py
23
chroot.py
|
@ -84,6 +84,7 @@ def get_chroot(
|
||||||
) -> Chroot:
|
) -> Chroot:
|
||||||
global chroots
|
global chroots
|
||||||
if default and name not in chroots:
|
if default and name not in chroots:
|
||||||
|
logging.debug(f'Adding chroot {name} to chroot map')
|
||||||
chroots[name] = default
|
chroots[name] = default
|
||||||
elif fail_if_exists:
|
elif fail_if_exists:
|
||||||
raise Exception(f'chroot {name} already exists')
|
raise Exception(f'chroot {name} already exists')
|
||||||
|
@ -148,6 +149,7 @@ class Chroot:
|
||||||
self.path = os.path.join(config.get_path('chroots'), name) if not path_override else path_override
|
self.path = os.path.join(config.get_path('chroots'), name) if not path_override else path_override
|
||||||
self.copy_base = copy_base
|
self.copy_base = copy_base
|
||||||
self.extra_repos |= extra_repos
|
self.extra_repos |= extra_repos
|
||||||
|
self.base_packages = base_packages
|
||||||
if initialize:
|
if initialize:
|
||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
|
@ -233,6 +235,7 @@ class Chroot:
|
||||||
])
|
])
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception(f'Failed to initialize chroot "{self.name}"')
|
raise Exception(f'Failed to initialize chroot "{self.name}"')
|
||||||
|
self.initialized = True
|
||||||
|
|
||||||
def mount(
|
def mount(
|
||||||
self,
|
self,
|
||||||
|
@ -249,7 +252,7 @@ class Chroot:
|
||||||
if os.path.ismount(absolute_destination):
|
if os.path.ismount(absolute_destination):
|
||||||
if fail_if_mounted:
|
if fail_if_mounted:
|
||||||
raise Exception(f'{self.name}: {absolute_destination} is already mounted')
|
raise Exception(f'{self.name}: {absolute_destination} is already mounted')
|
||||||
logging.warning(f'{self.name}: {absolute_destination} already mounted. Skipping.')
|
logging.debug(f'{self.name}: {absolute_destination} already mounted. Skipping.')
|
||||||
else:
|
else:
|
||||||
if makedir and os.path.isdir(absolute_source):
|
if makedir and os.path.isdir(absolute_source):
|
||||||
os.makedirs(absolute_destination, exist_ok=True)
|
os.makedirs(absolute_destination, exist_ok=True)
|
||||||
|
@ -307,8 +310,10 @@ class Chroot:
|
||||||
inner_env: dict[str, str] = {},
|
inner_env: dict[str, str] = {},
|
||||||
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
||||||
attach_tty: str = False,
|
attach_tty: str = False,
|
||||||
capture_output: str = False) -> subprocess.CompletedProcess:
|
capture_output: str = False,
|
||||||
self.activate()
|
fail_inactive: bool = True) -> subprocess.CompletedProcess:
|
||||||
|
if not self.active and fail_inactive:
|
||||||
|
raise Exception(f'Chroot {self.name} is inactive, not running command! Hint: pass `fail_inactive=False`')
|
||||||
if outer_env is None:
|
if outer_env is None:
|
||||||
outer_env = os.environ.copy()
|
outer_env = os.environ.copy()
|
||||||
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in inner_env.items()]
|
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in inner_env.items()]
|
||||||
|
@ -409,7 +414,7 @@ class Chroot:
|
||||||
rustc = os.path.join(native_chroot.path, 'usr/lib/crossdirect', target_arch, 'rustc')
|
rustc = os.path.join(native_chroot.path, 'usr/lib/crossdirect', target_arch, 'rustc')
|
||||||
if os.path.exists(rustc):
|
if os.path.exists(rustc):
|
||||||
logging.debug('Disabling crossdirect rustc')
|
logging.debug('Disabling crossdirect rustc')
|
||||||
os.unlink()
|
os.unlink(rustc)
|
||||||
|
|
||||||
os.makedirs(native_mount, exist_ok=True)
|
os.makedirs(native_mount, exist_ok=True)
|
||||||
logging.debug(f'Mounting {native_chroot.name} to {native_mount}')
|
logging.debug(f'Mounting {native_chroot.name} to {native_mount}')
|
||||||
|
@ -417,11 +422,15 @@ class Chroot:
|
||||||
return native_mount
|
return native_mount
|
||||||
|
|
||||||
def mount_pkgbuilds(self, fail_if_mounted: bool = False) -> str:
|
def mount_pkgbuilds(self, fail_if_mounted: bool = False) -> str:
|
||||||
packages = config.get_path('pkgbuilds')
|
pkgbuilds = config.get_path('pkgbuilds')
|
||||||
return self.mount(absolute_source=packages, relative_destination=packages.lstrip('/'), fail_if_mounted=fail_if_mounted)
|
return self.mount(absolute_source=pkgbuilds, relative_destination=pkgbuilds.lstrip('/'), fail_if_mounted=fail_if_mounted)
|
||||||
|
|
||||||
def mount_pacman_cache(self, fail_if_mounted: bool = False) -> str:
|
def mount_pacman_cache(self, fail_if_mounted: bool = False) -> str:
|
||||||
return self.mount(os.path.join(config.get_path('pacman'), self.arch), 'var/cache/pacman/pkg', fail_if_mounted=fail_if_mounted)
|
arch_cache = os.path.join(config.get_path('pacman'), self.arch)
|
||||||
|
rel_target = os.path.join('var/cache/pacman', self.arch)
|
||||||
|
for dir in [arch_cache, self.get_path(rel_target)]:
|
||||||
|
os.makedirs(dir, exist_ok=True)
|
||||||
|
return self.mount(arch_cache, rel_target, fail_if_mounted=fail_if_mounted)
|
||||||
|
|
||||||
def mount_packages(self, fail_if_mounted: bool = False) -> str:
|
def mount_packages(self, fail_if_mounted: bool = False) -> str:
|
||||||
packages = config.get_path('packages')
|
packages = config.get_path('packages')
|
||||||
|
|
Loading…
Add table
Reference in a new issue