chroots: use path from config
Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
parent
63a9cf1218
commit
04cce26ca0
3 changed files with 43 additions and 37 deletions
32
chroot.py
32
chroot.py
|
@ -2,15 +2,16 @@ import logging
|
|||
import subprocess
|
||||
import os
|
||||
import shutil
|
||||
from config import config
|
||||
|
||||
|
||||
def create_chroot(
|
||||
chroot_path,
|
||||
packages=['base'],
|
||||
pacman_conf='/app/local/etc/pacman.conf',
|
||||
chroot_base_path='/chroot',
|
||||
extra_repos={},
|
||||
):
|
||||
def get_chroot_path(chroot_name, override_basepath: str = None) -> str:
|
||||
base_path = config.file['paths']['chroots'] if not override_basepath else override_basepath
|
||||
return os.path.join(base_path, chroot_name)
|
||||
|
||||
|
||||
def create_chroot(chroot_name, packages=['base'], pacman_conf='/app/local/etc/pacman.conf', extra_repos={}, chroot_base_path: str = None):
|
||||
chroot_path = get_chroot_path(chroot_name, override_basepath=chroot_base_path)
|
||||
pacman_conf_target = chroot_path + '/etc/pacman.conf'
|
||||
|
||||
os.makedirs(chroot_path + '/etc', exist_ok=True)
|
||||
|
@ -29,14 +30,19 @@ def create_chroot(
|
|||
'-yyuu',
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal('Failed to install system')
|
||||
exit(1)
|
||||
raise Exception('Failed to install chroot')
|
||||
return chroot_path
|
||||
|
||||
|
||||
def create_chroot_user(chroot_path):
|
||||
user = 'kupfer'
|
||||
password = '123456'
|
||||
groups = ['network', 'video', 'audio', 'optical', 'storage', 'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel']
|
||||
def create_chroot_user(
|
||||
chroot_name,
|
||||
chroot_base_path: str = None,
|
||||
user='kupfer',
|
||||
password='123456',
|
||||
groups=['network', 'video', 'audio', 'optical', 'storage', 'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel'],
|
||||
):
|
||||
chroot_path = get_chroot_path(chroot_name, override_basepath=chroot_base_path)
|
||||
|
||||
install_script = '\n'.join([
|
||||
f'if ! id -u "{user}" >/dev/null 2>&1; then',
|
||||
f' useradd -m {user}',
|
||||
|
|
33
image.py
33
image.py
|
@ -3,7 +3,7 @@ import os
|
|||
import subprocess
|
||||
import click
|
||||
from logger import logging
|
||||
from chroot import create_chroot, create_chroot_user
|
||||
from chroot import create_chroot, create_chroot_user, get_chroot_path
|
||||
from constants import DEVICES, FLAVOURS
|
||||
|
||||
|
||||
|
@ -23,21 +23,20 @@ def get_device_and_flavour() -> tuple[str, str]:
|
|||
return (device, flavour)
|
||||
|
||||
|
||||
def get_image_name(device, flavour):
|
||||
def get_image_name(device, flavour) -> str:
|
||||
return f'{device}-{flavour}-rootfs.img'
|
||||
|
||||
|
||||
def mount_rootfs_image(path):
|
||||
rootfs_mount = '/mnt/kupfer/rootfs'
|
||||
if not os.path.exists(rootfs_mount):
|
||||
os.makedirs(rootfs_mount)
|
||||
def mount_rootfs_image(image_path, mount_path):
|
||||
if not os.path.exists(mount_path):
|
||||
os.makedirs(mount_path)
|
||||
|
||||
def umount():
|
||||
subprocess.run(
|
||||
[
|
||||
'umount',
|
||||
'-lc',
|
||||
rootfs_mount,
|
||||
mount_path,
|
||||
],
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
@ -48,15 +47,13 @@ def mount_rootfs_image(path):
|
|||
'mount',
|
||||
'-o',
|
||||
'loop',
|
||||
path,
|
||||
rootfs_mount,
|
||||
image_path,
|
||||
mount_path,
|
||||
])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to loop mount {path} to {rootfs_mount}')
|
||||
logging.fatal(f'Failed to loop mount {image_path} to {mount_path}')
|
||||
exit(1)
|
||||
|
||||
return rootfs_mount
|
||||
|
||||
|
||||
def dump_bootimg(image_name: str) -> str:
|
||||
path = '/tmp/boot.img'
|
||||
|
@ -164,8 +161,9 @@ def cmd_build():
|
|||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to create ext4 filesystem on {image_name}')
|
||||
exit(1)
|
||||
|
||||
rootfs_mount = mount_rootfs_image(image_name)
|
||||
chroot_name = f'rootfs_{device}-{flavour}'
|
||||
rootfs_mount = get_chroot_path(chroot_name)
|
||||
mount_rootfs_image(image_name, rootfs_mount)
|
||||
|
||||
extra_repos = {
|
||||
'main': {
|
||||
|
@ -187,12 +185,12 @@ def cmd_build():
|
|||
}
|
||||
|
||||
create_chroot(
|
||||
rootfs_mount,
|
||||
chroot_name,
|
||||
packages=['base', 'base-kupfer'] + DEVICES[device] + FLAVOURS[flavour],
|
||||
pacman_conf='/app/local/etc/pacman.conf',
|
||||
extra_repos=extra_repos,
|
||||
)
|
||||
create_chroot_user(rootfs_mount)
|
||||
create_chroot_user(chroot_name)
|
||||
|
||||
|
||||
"""
|
||||
|
@ -204,7 +202,8 @@ def cmd_inspect():
|
|||
device, flavour = get_device_and_flavour()
|
||||
image_name = get_image_name(device, flavour)
|
||||
|
||||
rootfs_mount = mount_rootfs_image(image_name)
|
||||
rootfs_mount = get_chroot_path(f'rootfs_{device}-flavour')
|
||||
mount_rootfs_image(image_name, rootfs_mount)
|
||||
|
||||
logging.info(f'Inspect the rootfs image at {rootfs_mount}')
|
||||
|
||||
|
|
15
packages.py
15
packages.py
|
@ -116,15 +116,16 @@ def check_prebuilts():
|
|||
exit(1)
|
||||
|
||||
|
||||
def setup_chroot(chroot_path='/chroot/root'):
|
||||
logging.info('Initializing root chroot')
|
||||
def setup_build_chroot(arch='aarch64'):
|
||||
chroot_name = f'build_{arch}'
|
||||
logging.info('Initializing {arch} build chroot')
|
||||
extra_repos = {}
|
||||
for repo in REPOSITORIES:
|
||||
extra_repos[repo] = {
|
||||
'Server': f'file:///src/prebuilts/{repo}',
|
||||
}
|
||||
create_chroot(
|
||||
chroot_path,
|
||||
chroot_path = create_chroot(
|
||||
chroot_name,
|
||||
packages=['base-devel'],
|
||||
pacman_conf='/app/local/etc/pacman.conf',
|
||||
extra_repos=extra_repos,
|
||||
|
@ -135,7 +136,7 @@ def setup_chroot(chroot_path='/chroot/root'):
|
|||
'--root',
|
||||
chroot_path,
|
||||
'--arch',
|
||||
'aarch64',
|
||||
arch,
|
||||
'--config',
|
||||
chroot_path + '/etc/pacman.conf',
|
||||
])
|
||||
|
@ -466,7 +467,7 @@ def cmd_packages():
|
|||
|
||||
@click.command(name='build')
|
||||
@click.argument('paths', nargs=-1)
|
||||
def cmd_build(paths):
|
||||
def cmd_build(paths, arch='aarch64'):
|
||||
check_prebuilts()
|
||||
|
||||
paths = list(paths)
|
||||
|
@ -484,7 +485,7 @@ def cmd_build(paths):
|
|||
logging.info('Building %s', ', '.join(map(lambda x: x.path, need_build)))
|
||||
crosscompile = config.file['build']['crosscompile']
|
||||
for package in need_build:
|
||||
setup_chroot()
|
||||
setup_build_chroot(arch=arch)
|
||||
build_package(package, enable_crosscompile=crosscompile)
|
||||
add_package_to_repo(package)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue