- any distro from any distro (debian, ubuntu, arch, artix, void, alpine, fedora) - YAML config for distro, arch, init, packages, users, services, bootloader - each distro backend knows how to bootstrap itself - squashfs + xorriso for ISO generation - sexy CLI with banner and colored output - examples for Artix+Euri and Project Horizon
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""Rootfs builder — creates the root filesystem."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from .distros import get as get_distro
|
|
|
|
|
|
def build(config: dict, output: Path) -> Path:
|
|
"""Build a rootfs and return its path."""
|
|
distro_name = config["distro"]
|
|
distro_cls = get_distro(distro_name)
|
|
|
|
# artix vs arch
|
|
if distro_name in ("artix",):
|
|
distro = distro_cls(family="artix")
|
|
elif distro_name in ("debian", "ubuntu"):
|
|
distro = distro_cls(family=distro_name)
|
|
elif distro_name in ("fedora", "rocky", "almalinux"):
|
|
distro = distro_cls(family=distro_name)
|
|
else:
|
|
distro = distro_cls()
|
|
|
|
rootfs = Path(tempfile.mkdtemp(prefix="mklive-"))
|
|
print(f"\n\033[1;36m==>\033[0m \033[1mBuilding rootfs in {rootfs}\033[0m")
|
|
|
|
# 1. bootstrap
|
|
print(f"\033[1;36m==>\033[0m \033[1m[1/4] Bootstrapping {distro_name}...\033[0m")
|
|
distro.bootstrap(rootfs, config)
|
|
|
|
# 2. install packages
|
|
pkgs = config.get("packages", [])
|
|
if pkgs:
|
|
print(f"\033[1;36m==>\033[0m \033[1m[2/4] Installing {len(pkgs)} packages...\033[0m")
|
|
distro.install_packages(rootfs, pkgs)
|
|
else:
|
|
print(f"\033[1;36m==>\033[0m \033[1m[2/4] No extra packages to install\033[0m")
|
|
|
|
# 3. configure
|
|
print(f"\033[1;36m==>\033[0m \033[1m[3/4] Configuring base system...\033[0m")
|
|
distro.configure_base(rootfs, config)
|
|
|
|
# 4. bootloader
|
|
print(f"\033[1;36m==>\033[0m \033[1m[4/4] Installing bootloader...\033[0m")
|
|
distro.install_bootloader(rootfs, config)
|
|
|
|
return rootfs
|
|
|
|
|
|
def cleanup(rootfs: Path) -> None:
|
|
"""Remove the temporary rootfs."""
|
|
shutil.rmtree(rootfs, ignore_errors=True)
|