new commit

This commit is contained in:
Manuel 2025-04-28 12:24:18 +00:00
parent eee4d3f035
commit ef20c72cb8

View File

@ -5,13 +5,9 @@ SPDX-FileCopyrightText: 2023-2025 PeppermintOS Team
SPDX-License-Identifier: GPL-3.0-or-later
This module provides a function to perform essential system reconfigurations within the chroot
environment of a Void Linux system. It is based on the `mklive.sh` script (specifically the
`install_packages()` function) and ensures that the base system is properly configured for the ISO.
The module handles tasks such as reconfiguring base files, setting the default locale,
reconfiguring DKMS (if installed), reconfiguring all packages, and optionally setting `dash`
as the system shell (`/bin/sh`).
This module provides a function to perform essential system reconfigurations within the
target root filesystem of a Void Linux system, executed from the host. It uses a chroot
helper for commands that require execution within the target environment.
Credits:
- PeppermintOS Team (peppermintosteam@proton.me) - Development and maintenance of the project.
@ -27,65 +23,58 @@ import sys
import subprocess
import logging
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, BASE_DIR)
try:
from builder.core.xbps_commands import xbps_commands
from builder.core.command_runner import run_command
from builder.core.command_runner import run_command_in_target
from builder.configs import logger_config
logger = logger_config.setup_logger('system_reconfigure')
except ImportError as e:
print(f"Error importing necessary modules: {e}. Ensure your environment is set up correctly.")
try:
basic_logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.ERROR)
basic_logger.error(f"Error importing necessary modules for system_reconfigure: {e}. Ensure your environment is set up correctly.")
except Exception:
print(f"Error importing necessary modules for system_reconfigure: {e}. Ensure your environment is set up correctly.")
sys.exit(1)
def reconfigure_system_in_chroot(rootfs_path, architecture, repositories_list, base_cache_dir, locale="en_US.UTF-8"):
def reconfigure_system_in_chroot(rootfs_path, target_architecture, repositories_data, paths, locale="en_US.UTF-8"):
"""
Performs essential reconfigurations... (Docstring updated)
Performs essential reconfigurations in the target root filesystem, executed from the host.
Uses run_command_in_target for commands requiring execution within the target environment.
Args:
rootfs_path (str): Path to the rootfs directory of the chroot.
architecture (str): Target architecture (e.g., 'x86_64').
repositories_list (list): List of repository dictionaries.
base_cache_dir (str): Base path to the XBPS cache directory.
rootfs_path (str): Path to the target root filesystem directory.
target_architecture (str): Target architecture (e.g., 'aarch64').
repositories_data (list): List of repository dictionaries. (Note: Not directly used by all commands in target).
paths (dict): Dictionary of build paths. (Needed for consistency or future use, though rootfs_path is explicit).
locale (str, optional): UTF-8 locale to be configured (default: 'en_US.UTF-8').
Raises:
subprocess.CalledProcessError: If a command executed in target fails.
FileNotFoundError: If the target rootfs or command is not found.
ValueError: If arguments are incorrect.
"""
logger.info("=> Starting Void Linux system reconfiguration in chroot...")
logger.info("=> Starting Void Linux system reconfiguration...")
xbps_repository_args = []
for repo_dict in repositories_list:
repo_url = repo_dict['uri']
xbps_repository_args.extend(["-R", repo_url])
architecture_cache_dir = os.path.join(base_cache_dir, architecture)
xbps_cachedir_args = ["-c", architecture_cache_dir]
if not rootfs_path or not os.path.isdir(rootfs_path):
logger.error(f"Invalid target root filesystem path: {rootfs_path}")
raise ValueError(f"Invalid target root filesystem path: {rootfs_path}")
package_list = []
initramfs_pkgs = []
logger.info("=> (Step 2) Assuming pseudo-filesystems are already mounted in the chroot.")
if package_list or initramfs_pkgs:
logger.info("=> (Step 3) Reconfiguring/Updating packages...")
reinstall_step_cmd = ["LANG=C"] + ["XBPS_ARCH=" + architecture] + [xbps_commands.XBPS_INSTALL_CMD] + ["-U"] + xbps_repository_args + xbps_cachedir_args + ["-y"] + package_list + initramfs_pkgs
command_str = " ".join(reinstall_step_cmd)
logger.info(f"=> Executing command [CHROOT: {rootfs_path}]: {command_str}")
else:
logger.info("=> (Step 3) Package list for reconfiguration/update is empty. Skipping step.")
logger.info("=> (Step 4) Forcing reconfiguration of base-files...")
logger.info("=> (Step 4) Forcing reconfiguration of base-files IN TARGET...")
reconfigure_base_files_cmd = [xbps_commands["XBPS_RECONFIGURE_CMD"], '-f', 'base-files']
command_str = " ".join(reconfigure_base_files_cmd)
logger.info(f"=> Executing command [CHROOT: {rootfs_path}]: {command_str}")
result = run_command(reconfigure_base_files_cmd)
result = run_command_in_target(rootfs_path, reconfigure_base_files_cmd, target_architecture)
if result.returncode != 0:
logger.warning(f"Warning: Reconfiguration of base-files returned an error, but proceeding. Error: {result.stderr.decode()}")
logger.warning(f"Warning: Reconfiguration of base-files in target returned an error ({result.returncode}), but proceeding.")
else:
logger.info("=> (Step 4) Reconfiguration of base-files COMPLETE.")
libc_locales_file = os.path.join(rootfs_path, 'etc', 'default', 'libc-locales')
if os.path.exists(libc_locales_file):
logger.info(f"=> (Step 5) Configuring UTF-8 locale in: {libc_locales_file}")
@ -105,60 +94,52 @@ def reconfigure_system_in_chroot(rootfs_path, architecture, repositories_list, b
else:
logger.info(f"=> (Step 5) Locale file {libc_locales_file} not found. Skipping locale configuration.")
logger.info("=> (Step 6) Checking and reconfiguring DKMS (if installed)...")
check_dkms_cmd = [xbps_commands["XBPS_QUERY_CMD"], '-r', rootfs_path, 'dkms']
result_dkms_check = run_command(check_dkms_cmd)
if result_dkms_check.returncode == 0:
logger.info("=> DKMS found. Forcing DKMS reconfiguration...")
list_dkms_files_cmd = [xbps_commands["XBPS_QUERY_CMD"], '-r', rootfs_path, '-f', 'dkms']
logger.info(f"=> Listing files installed by the dkms package inside the chroot...")
result_list_dkms_files = run_command(list_dkms_files_cmd)
if result_list_dkms_files.returncode == 0:
logger.debug(f"=> List of files from the dkms package:\n{result_list_dkms_files.stdout.strip()}")
else:
logger.warning(f"=> Failed to list files of the dkms package, but proceeding.")
reconfigure_dkms_cmd = ["env", "-i", xbps_commands["XBPS_RECONFIGURE_CMD"], '-r', rootfs_path, "dkms"]
command_str = " ".join(reconfigure_dkms_cmd)
logger.info(f"=> Executing command (ENV -i): {command_str}")
result_dkms_reconfig = run_command(reconfigure_dkms_cmd)
logger.info("=> (Step 6) Checking and reconfiguring DKMS (if installed) IN TARGET...")
check_dkms_cmd = [xbps_commands["XBPS_QUERY_CMD"], 'dkms']
try:
result_dkms_check = run_command_in_target(rootfs_path, check_dkms_cmd, target_architecture, check=False)
if result_dkms_check.returncode == 0:
logger.info("=> DKMS found in target. Forcing DKMS reconfiguration IN TARGET...")
reconfigure_dkms_cmd = [xbps_commands["XBPS_RECONFIGURE_CMD"], "dkms"]
result_dkms_reconfig = run_command_in_target(rootfs_path, reconfigure_dkms_cmd, target_architecture, check=False)
if result_dkms_reconfig.returncode != 0:
logger.warning(f"Warning: DKMS reconfiguration returned an error, but proceeding. Error: {result_dkms_reconfig.stderr.decode()}")
logger.warning(f"Warning: DKMS reconfiguration in target returned an error ({result_dkms_reconfig.returncode}), but proceeding.")
else:
logger.info("=> DKMS reconfiguration COMPLETE.")
else:
logger.info("=> DKMS not found in the chroot. Skipping DKMS reconfiguration.")
logger.info("=> DKMS not found in the target. Skipping DKMS reconfiguration.")
except FileNotFoundError:
logger.warning("Warning: xbps-query command not found in target chroot. Skipping DKMS check.")
logger.info("=> (Step 7) Reconfiguring all packages (-a)...")
reconfigure_all_cmd = [xbps_commands["XBPS_RECONFIGURE_CMD"]] + ["-a"]
command_str = " ".join(reconfigure_all_cmd)
logger.info(f"=> Executing command [CHROOT: {rootfs_path}]: {command_str}")
result_reconfigure_all = run_command(reconfigure_all_cmd)
logger.info("=> (Step 7) Reconfiguring all packages (-a) IN TARGET...")
reconfigure_all_cmd = [xbps_commands["XBPS_RECONFIGURE_CMD"], "-a"]
result_reconfigure_all = run_command_in_target(rootfs_path, reconfigure_all_cmd, target_architecture, check=False)
if result_reconfigure_all.returncode != 0:
logger.warning(f"Warning: Reconfiguration of all packages (-a) returned an error, but proceeding. Error: {result_reconfigure_all.stderr.decode()}")
logger.warning(f"Warning: Reconfiguration of all packages (-a) in target returned an error ({result_reconfigure_all.returncode}), but proceeding.")
else:
logger.info("=> Reconfiguration of all packages (-a) COMPLETE.")
logger.info("=> (Step 8) Checking and configuring dash as /bin/sh (if dash installed)...")
check_dash_cmd = [xbps_commands["XBPS_QUERY_CMD"], '-r', rootfs_path, "dash"]
cmd_env = os.environ.copy()
cmd_env['XBPS_ARCH'] = architecture
command_str = " ".join(check_dash_cmd)
logger.info(f"=> Executing command (XBPS_ARCH={architecture}): {command_str}")
result_dash_check = run_command(check_dash_cmd, env=cmd_env)
logger.info("=> (Step 8) Checking and configuring dash as /bin/sh (if dash installed) IN TARGET...")
check_dash_cmd = [xbps_commands["XBPS_QUERY_CMD"], "dash"]
try:
result_dash_check = run_command_in_target(rootfs_path, check_dash_cmd, target_architecture, check=False)
if result_dash_check.returncode == 0:
logger.info("=> Dash found. Setting dash as /bin/sh...")
set_dash_sh_cmd = [xbps_commands["XBPS_ALTERNATIVES_CMD"]] + ["-s", "dash"]
command_str = " ".join(set_dash_sh_cmd)
logger.info(f"=> Executing command [CHROOT: {rootfs_path}]: {command_str}")
result_dash_set = run_command(set_dash_sh_cmd)
logger.info("=> Dash found in target. Setting dash as /bin/sh IN TARGET...")
set_dash_sh_cmd = [xbps_commands["XBPS_ALTERNATIVES_CMD"], "-s", "dash"]
result_dash_set = run_command_in_target(rootfs_path, set_dash_sh_cmd, target_architecture, check=False)
if result_dash_set.returncode != 0:
logger.warning(f"Warning: Failed to set dash as /bin/sh, but proceeding. Error: {result_dash_set.stderr.decode()}")
logger.warning(f"Warning: Failed to set dash as /bin/sh in target ({result_dash_set.returncode}), but proceeding.")
else:
logger.info("=> Setting dash as /bin/sh COMPLETE.")
else:
logger.info("=> Dash not found in the chroot. Skipping configuration of dash as /bin/sh.")
logger.info("=> Dash not found in the target. Skipping configuration of dash as /bin/sh.")
except FileNotFoundError:
logger.warning("Warning: xbps-query or xbps-alternatives command not found in target chroot. Skipping dash configuration.")
logger.info("=> Void Linux system reconfiguration in chroot COMPLETE.")
logger.info("=> Void Linux system reconfiguration COMPLETE.")
logger.info("--------------------------------------------------------------------\n")