2021-10-01 18:25:42 +02:00
|
|
|
import click
|
2021-08-06 02:21:50 +02:00
|
|
|
import logging
|
2021-08-06 05:24:06 +02:00
|
|
|
import os
|
2021-10-24 04:32:47 +02:00
|
|
|
|
2021-09-13 04:19:13 +02:00
|
|
|
from config import config
|
2021-10-01 18:25:42 +02:00
|
|
|
from wrapper import enforce_wrap
|
|
|
|
|
2022-02-18 06:46:05 +01:00
|
|
|
from .abstract import Chroot
|
|
|
|
from .base import get_base_chroot
|
2022-02-18 06:32:04 +01:00
|
|
|
from .build import get_build_chroot, BuildChroot
|
|
|
|
from .helpers import get_chroot_path
|
2021-10-19 06:40:30 +02:00
|
|
|
|
2022-02-17 21:49:24 +01:00
|
|
|
# export Chroot class
|
|
|
|
Chroot = Chroot
|
2021-10-24 04:32:47 +02:00
|
|
|
|
2021-10-04 14:36:39 +02:00
|
|
|
|
2021-10-01 18:25:42 +02:00
|
|
|
@click.command('chroot')
|
|
|
|
@click.argument('type', required=False, default='build')
|
|
|
|
@click.argument('arch', required=False, default=None)
|
2021-10-02 06:35:51 +02:00
|
|
|
def cmd_chroot(type: str = 'build', arch: str = None, enable_crossdirect=True):
|
2022-02-13 19:57:04 +01:00
|
|
|
"""Open a shell in a chroot"""
|
2021-10-01 18:25:42 +02:00
|
|
|
chroot_path = ''
|
|
|
|
if type not in ['base', 'build', 'rootfs']:
|
|
|
|
raise Exception('Unknown chroot type: ' + type)
|
|
|
|
|
|
|
|
enforce_wrap()
|
2022-02-18 06:32:04 +01:00
|
|
|
chroot: Chroot
|
2021-10-01 18:25:42 +02:00
|
|
|
if type == 'rootfs':
|
|
|
|
if arch:
|
|
|
|
name = 'rootfs_' + arch
|
|
|
|
else:
|
2021-10-19 06:40:30 +02:00
|
|
|
raise Exception('"rootfs" without args not yet implemented, sorry!')
|
2021-10-01 18:25:42 +02:00
|
|
|
# TODO: name = config.get_profile()[...]
|
2022-02-18 06:32:04 +01:00
|
|
|
chroot_path = get_chroot_path(name)
|
2021-10-01 18:25:42 +02:00
|
|
|
if not os.path.exists(chroot_path):
|
|
|
|
raise Exception(f"rootfs {name} doesn't exist")
|
|
|
|
else:
|
|
|
|
if not arch:
|
2022-02-18 06:32:04 +01:00
|
|
|
# TODO: arch = config.get_profile()[...]
|
2021-10-01 18:25:42 +02:00
|
|
|
arch = 'aarch64'
|
2021-10-19 06:40:30 +02:00
|
|
|
if type == 'base':
|
2022-01-28 19:04:23 +01:00
|
|
|
chroot = get_base_chroot(arch)
|
2022-02-18 06:32:04 +01:00
|
|
|
if not os.path.exists(chroot.get_path('/bin')):
|
2022-02-17 19:37:50 +01:00
|
|
|
chroot.initialize()
|
2021-10-19 06:40:30 +02:00
|
|
|
chroot.initialized = True
|
|
|
|
elif type == 'build':
|
2022-02-18 06:32:04 +01:00
|
|
|
build_chroot: BuildChroot = get_build_chroot(arch, activate=True)
|
|
|
|
chroot = build_chroot # type safety
|
|
|
|
if not os.path.exists(build_chroot.get_path('/bin')):
|
|
|
|
build_chroot.initialize()
|
|
|
|
build_chroot.initialized = True
|
|
|
|
build_chroot.mount_pkgbuilds()
|
2021-10-19 06:40:30 +02:00
|
|
|
if config.file['build']['crossdirect'] and enable_crossdirect:
|
2022-02-18 06:32:04 +01:00
|
|
|
build_chroot.mount_crossdirect()
|
2021-10-19 06:40:30 +02:00
|
|
|
else:
|
|
|
|
raise Exception('Really weird bug')
|
|
|
|
|
2022-01-28 19:04:23 +01:00
|
|
|
chroot.activate()
|
2021-10-19 06:40:30 +02:00
|
|
|
logging.debug(f'Starting shell in {chroot.name}:')
|
|
|
|
chroot.run_cmd('bash', attach_tty=True)
|