- 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.3 KiB
Python
64 lines
2.3 KiB
Python
"""Alpine Linux backend — uses apk with --root."""
|
|
|
|
from pathlib import Path
|
|
|
|
from .base import Distro
|
|
|
|
|
|
class Alpine(Distro):
|
|
name = "alpine"
|
|
host_deps = ["apk-tools", "squashfs-tools", "xorriso", "mtools", "dosfstools"]
|
|
|
|
MIRROR = "https://dl-cdn.alpinelinux.org/alpine/latest-stable"
|
|
|
|
def bootstrap(self, rootfs: Path, config: dict) -> None:
|
|
mirror = config.get("mirror", self.MIRROR)
|
|
branch = config.get("suite", "edge")
|
|
init = config.get("init", "openrc")
|
|
|
|
cmd = [
|
|
"apk",
|
|
"-X", f"{mirror}/{branch}/main",
|
|
"-U",
|
|
"--allow-untrusted",
|
|
"--root", str(rootfs),
|
|
"--initdb",
|
|
"add",
|
|
"alpine-base",
|
|
"apk-tools",
|
|
"linux-lts",
|
|
"linux-firmware",
|
|
init,
|
|
*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, ["apk", "add", *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, ["adduser", "-D", "-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, ["adduser", name, group])
|
|
|
|
init = config.get("init", "openrc")
|
|
for svc in config.get("services", []):
|
|
self._run_chroot(rootfs, ["rc-update", "add", svc, "default"])
|
|
|
|
def install_bootloader(self, rootfs: Path, config: dict) -> None:
|
|
self._run_chroot(rootfs, ["apk", "add", "grub", "grub-efi", "os-prober"])
|
|
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, ["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])
|