- 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__
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""Fedora/Rocky/Alma backend — uses dnf --installroot."""
|
|
|
|
from pathlib import Path
|
|
|
|
from .base import Distro
|
|
|
|
|
|
class Fedora(Distro):
|
|
name = "fedora"
|
|
host_deps = ["dnf", "squashfs-tools", "xorriso", "mtools", "dosfstools"]
|
|
|
|
GROUPS = {
|
|
"fedora": "@core",
|
|
"rocky": "@core",
|
|
"almalinux": "@core",
|
|
}
|
|
|
|
def __init__(self, family: str = "fedora"):
|
|
self.family = family
|
|
|
|
def bootstrap(self, rootfs: Path, config: dict) -> None:
|
|
release = config.get("suite", "40")
|
|
group = self.GROUPS.get(self.family, "@core")
|
|
|
|
cmd = [
|
|
"dnf",
|
|
"--installroot", str(rootfs),
|
|
"-y",
|
|
f"--releasever={release}",
|
|
"install",
|
|
group,
|
|
"kernel",
|
|
"grub2-efi-x64",
|
|
*config.get("base_packages", []),
|
|
]
|
|
self._run(cmd)
|
|
|
|
def install_packages(self, rootfs: Path, packages: list[str]) -> None:
|
|
if not packages:
|
|
return
|
|
self._run_chroot(rootfs, ["dnf", "-y", "install", *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, ["grub2-install", "--target=i386-pc", "/dev/sda"])
|
|
self._run_chroot(rootfs, ["grub2-install", "--target=x86_64-efi", "--efi-directory=/boot/efi"])
|
|
self._run_chroot(rootfs, ["grub2-mkconfig", "-o", "/boot/grub2/grub.cfg"])
|