Files
euri-mklive/euri_mklive/distros/debian.py
T
c-ludenberg 5c65baeb27 fix: syntax errors in all backends, wrong import path, entry point
- fix f-string escape bug in all 5 backends (user password handling)
- fix void.py import: from ..dinit (not .dinit — dinit.py is at package root)
- fix pyproject.toml entry point: cli:cli not cli:main
- add .gitignore for __pycache__
2026-08-26 20:39:42 +02:00

69 lines
2.5 KiB
Python

"""Debian/Ubuntu backend — uses debootstrap."""
from pathlib import Path
from .base import Distro
class Debian(Distro):
name = "debian"
host_deps = ["debootstrap", "squashfs-tools", "xorriso", "mtools", "dosfstools"]
SUITES = {
"debian": "bookworm",
"ubuntu": "noble",
}
MIRRORS = {
"debian": "http://deb.debian.org/debian",
"ubuntu": "http://archive.ubuntu.com/ubuntu",
}
def __init__(self, family: str = "debian"):
self.family = family
def bootstrap(self, rootfs: Path, config: dict) -> None:
suite = config.get("suite", self.SUITES.get(self.family, "bookworm"))
mirror = config.get("mirror", self.MIRRORS.get(self.family))
variant = config.get("variant", "minbase")
cmd = [
"debootstrap",
"--variant", variant,
"--include", ",".join(config.get("base_packages", ["base-files", "apt"])),
"--arch", config.get("arch", "amd64"),
suite,
str(rootfs),
mirror,
]
self._run(cmd)
def install_packages(self, rootfs: Path, packages: list[str]) -> None:
if not packages:
return
self._run_chroot(rootfs, ["apt-get", "update"])
self._run_chroot(rootfs, ["apt-get", "install", "-y", *packages])
def configure_base(self, rootfs: Path, config: dict) -> None:
hostname = config.get("hostname", "euri")
(rootfs / "etc/hostname").write_text(f"{hostname}\n")
for user in config.get("users", []):
name = user["name"]
shell = user.get("shell", "/bin/bash")
self._run_chroot(rootfs, ["useradd", "-m", "-s", shell, name])
if "password" in user:
pw = user["password"]
self._run_chroot(rootfs, ["bash", "-c", f"echo '{name}:{pw}' | chpasswd"])
for group in user.get("groups", []):
self._run_chroot(rootfs, ["usermod", "-aG", group, name])
for svc in config.get("services", []):
self._run_chroot(rootfs, ["systemctl", "enable", svc])
def install_bootloader(self, rootfs: Path, config: dict) -> None:
self._run_chroot(rootfs, ["apt-get", "install", "-y", "grub-pc", "grub-efi-amd64"])
self._run_chroot(rootfs, ["grub-install", "--target=i386-pc", "/dev/sda"])
self._run_chroot(rootfs, ["grub-install", "--target=x86_64-efi", "--efi-directory=/boot/efi"])
self._run_chroot(rootfs, ["update-grub"])