diff --git a/constants.py b/constants.py index 83fd03a..14d0ed2 100644 --- a/constants.py +++ b/constants.py @@ -29,14 +29,15 @@ DEVICES = { FLAVOURS = { 'barebone': { - 'packages': [] + 'packages': [], }, 'debug-shell': { - 'packages': ['hook-debug-shell'] + 'packages': ['hook-debug-shell'], }, 'gnome': { 'packages': ['gnome', 'archlinux-appstream-data', 'gnome-software-packagekit-plugin'], - 'post_cmds': ['systemctl enable gdm'] + 'post_cmds': ['systemctl enable gdm'], + 'size': 8, }, } diff --git a/flash.py b/flash.py index 316c44e..a34cd9a 100644 --- a/flash.py +++ b/flash.py @@ -8,6 +8,7 @@ import subprocess import click import tempfile from wrapper import enforce_wrap +from image import resize_fs BOOTIMG = FLASH_PARTS['BOOTIMG'] LK2ND = FLASH_PARTS['LK2ND'] @@ -58,21 +59,7 @@ def cmd_flash(what, location): shutil.copyfile(image_name, image_path) - result = subprocess.run([ - 'e2fsck', - '-fy', - image_path, - ]) - if result.returncode != 0: - raise Exception(f'Failed to e2fsck {image_path}') - - result = subprocess.run([ - 'resize2fs', - '-M', - image_path, - ]) - if result.returncode != 0: - raise Exception(f'Failed to resize2fs {image_path}') + resize_fs(image_path, shrink=True) if location.endswith('-file'): part_mount = '/mnt/kupfer/fs' diff --git a/image.py b/image.py index 92f163a..6c139d6 100644 --- a/image.py +++ b/image.py @@ -11,6 +11,24 @@ from wrapper import enforce_wrap from signal import pause +def resize_fs(image_path: str, shrink: bool = False): + result = subprocess.run([ + 'e2fsck', + '-fy', + image_path, + ]) + if result.returncode != 0: + msg = f'Failed to e2fsck {image_path}' + if shrink: + raise Exception(msg) + else: + logging.warning(msg) + + result = subprocess.run(['resize2fs'] + (['-MP'] if shrink else []) + [image_path]) + if result.returncode != 0: + raise Exception(f'Failed to resize2fs {image_path}') + + def get_device_and_flavour(profile: str = None) -> tuple[str, str]: #config.enforce_config_loaded() profile = config.get_profile(profile) @@ -120,12 +138,11 @@ def cmd_build(): result = subprocess.run([ 'fallocate', '-l', - '4G', + f"{FLAVOURS[flavour].get('size',4)}G", image_name, ]) if result.returncode != 0: - logging.fatal(f'Failed to allocate {image_name}') - exit(1) + raise Exception(f'Failed to allocate {image_name}') result = subprocess.run([ 'mkfs.ext4', @@ -134,8 +151,10 @@ def cmd_build(): image_name, ]) if result.returncode != 0: - logging.fatal(f'Failed to create ext4 filesystem on {image_name}') - exit(1) + raise Exception(f'Failed to create ext4 filesystem on {image_name}') + else: + resize_fs(image_path=image_name) + chroot_name = f'rootfs_{device}-{flavour}' rootfs_mount = get_chroot_path(chroot_name) mount_rootfs_image(image_name, rootfs_mount)