mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-14 03:49:48 +03:00
Refactor the install code to stop using loop devices and instead create and manipulate a disk image directly. Both ext4 and vfat have mechanisms for formatting and populating partitions at an offset inside an image, other filesystems likely do as well but so far have not been implemented or tested. With this "pmbootstrap install" works for standard EFI disk images (e.g. QEMU, X64 or trailblazer) entirely rootless. Since the creation of the disk images happens in the same user namespace as everything else, the resulting disk images have correct ownership and permissions even though from the host perspective they are all subuids. This gets image building working properly *for the default case*. We can now build disk images! In particular, we can build disk images with a 4k sector size even on a host with a 512 byte sector size (or block size in the filesystem). This is surprisingly hard for some reason since not all libfdisk tools have the right flags. Thankfully sfdisk does. In addition, we now generate UUIDs ourselves, to break the loop between generating fstab and running mkfs (since we also populate the disk image /with/ mkfs, we need to already know the UUID when we run it...). Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
77 lines
1.7 KiB
Python
77 lines
1.7 KiB
Python
# Copyright 2024 Caleb Connolly
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
"""Global runtime context"""
|
|
|
|
from pathlib import Path
|
|
from typing import overload, Literal
|
|
|
|
from .config import Config
|
|
|
|
|
|
class Context:
|
|
details_to_stdout: bool = False
|
|
quiet: bool = False
|
|
command_timeout: float = 900
|
|
force: bool = False
|
|
log: Path
|
|
|
|
# assume yes to prompts
|
|
assume_yes: bool = False
|
|
|
|
# Operate offline
|
|
offline: bool = False
|
|
|
|
# The pmbootstrap subcommand
|
|
command: str = ""
|
|
|
|
## FIXME: build options, should not be here ##
|
|
# disable cross compilation and use QEMU
|
|
cross: bool = False
|
|
no_depends: bool = False
|
|
ignore_depends: bool = False
|
|
ccache: bool = False
|
|
go_mod_cache: bool = False
|
|
|
|
# Disk image sector size (not filesystem block size!)
|
|
sector_size: int | None = None
|
|
|
|
config: Config
|
|
|
|
def __init__(self, config: Config):
|
|
self.log = config.work / "log.txt"
|
|
self.config = config
|
|
|
|
|
|
__context: Context
|
|
|
|
|
|
@overload
|
|
def get_context(allow_failure: Literal[False] = ...) -> Context: ...
|
|
|
|
|
|
@overload
|
|
def get_context(allow_failure: Literal[True] = ...) -> Context | None: ...
|
|
|
|
|
|
def get_context(allow_failure: bool = False) -> Context | None:
|
|
"""Get immutable global runtime context."""
|
|
global __context
|
|
|
|
# We must defer this to first call to avoid
|
|
# circular imports.
|
|
if "__context" not in globals():
|
|
if allow_failure:
|
|
return None
|
|
raise RuntimeError("Context not loaded yet")
|
|
return __context
|
|
|
|
|
|
def set_context(context: Context) -> None:
|
|
"""Set global runtime context."""
|
|
global __context
|
|
|
|
if "__context" in globals():
|
|
raise RuntimeError("Context already loaded")
|
|
|
|
__context = context
|