106 lines
3.0 KiB
Python
106 lines
3.0 KiB
Python
"""Portage configuration management."""
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
from .utils import info, success, error
|
|
|
|
|
|
def copy_portage_config(
|
|
source_dir: Path,
|
|
mount_root: Path | None = None,
|
|
) -> None:
|
|
"""Copy Portage configuration files to the new system."""
|
|
if mount_root is None:
|
|
mount_root = Path("/mnt/gentoo")
|
|
|
|
info("=== Copying Portage Configuration ===")
|
|
|
|
portage_dst = mount_root / "etc/portage"
|
|
etc_dst = mount_root / "etc"
|
|
|
|
# Source directories
|
|
portage_src = source_dir / "portage"
|
|
|
|
# Check if already configured (idempotency check)
|
|
make_conf = portage_dst / "make.conf"
|
|
if make_conf.exists():
|
|
info("Portage configuration already exists, updating...")
|
|
|
|
# Files to copy directly to /etc/portage/
|
|
portage_files = ["make.conf"]
|
|
|
|
# Directories to copy to /etc/portage/
|
|
portage_dirs = [
|
|
"package.accept_keywords",
|
|
"package.use",
|
|
"package.mask",
|
|
"package.env",
|
|
"package.license",
|
|
"env",
|
|
"sets",
|
|
]
|
|
|
|
# Directories to copy to /etc/ (from source_dir root, not portage/)
|
|
etc_dirs = ["dracut.conf.d"]
|
|
|
|
# Copy portage files (from portage/ subdir)
|
|
for filename in portage_files:
|
|
src = portage_src / filename
|
|
if src.exists():
|
|
dst = portage_dst / filename
|
|
shutil.copy2(src, dst)
|
|
success(f"Copied {filename}")
|
|
else:
|
|
error(f"Warning: {filename} not found in {portage_src}")
|
|
|
|
# Copy portage directories (from portage/ subdir, merge don't destroy)
|
|
for dirname in portage_dirs:
|
|
src = portage_src / dirname
|
|
if src.is_dir():
|
|
dst = portage_dst / dirname
|
|
shutil.copytree(src, dst, dirs_exist_ok=True)
|
|
success(f"Copied {dirname}/")
|
|
|
|
# Copy etc directories (from source_dir root, merge don't destroy)
|
|
for dirname in etc_dirs:
|
|
src = source_dir / dirname
|
|
if src.is_dir():
|
|
dst = etc_dst / dirname
|
|
shutil.copytree(src, dst, dirs_exist_ok=True)
|
|
success(f"Copied {dirname}/")
|
|
|
|
print()
|
|
success("=== Portage configuration copied ===")
|
|
|
|
|
|
def copy_user_config(
|
|
source_dir: Path,
|
|
mount_root: Path | None = None,
|
|
username: str = "damien",
|
|
) -> None:
|
|
"""Copy user configuration files."""
|
|
if mount_root is None:
|
|
mount_root = Path("/mnt/gentoo")
|
|
|
|
info("=== Copying User Configuration ===")
|
|
|
|
home_dir = mount_root / "home" / username
|
|
|
|
# Files to copy to home directory
|
|
user_files = [".zshrc", "starship.toml"]
|
|
|
|
for filename in user_files:
|
|
src = source_dir / filename
|
|
if src.exists():
|
|
if filename == "starship.toml":
|
|
dst = home_dir / ".config" / filename
|
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
else:
|
|
dst = home_dir / filename
|
|
shutil.copy2(src, dst)
|
|
success(f"Copied {filename}")
|
|
|
|
print()
|
|
success("=== User configuration copied ===")
|