# -*- coding: utf-8 -*- """ SPDX-FileCopyrightText: 2023-2025 PeppermintOS Team (peppermintosteam@proton.me) SPDX-License-Identifier: GPL-3.0-or-later This module is responsible for installing common packages into the root filesystem (rootfs) of the PeppermintOS build. It reads the list of packages to be installed from a YAML file and uses the XBPS package manager to perform the installation. The module handles loading package lists based on categories defined in the YAML file and configures the XBPS command with the appropriate rootfs path, cache directory, and repository URLs for the target architecture. Credits: - PeppermintOS Team (peppermintosteam@proton.me) - Development and maintenance of the project. License: This code is distributed under the GNU General Public License version 3 or later (GPL-3.0-or-later). For more details, please refer to the LICENSE file included in the project or visit: https://www.gnu.org/licenses/gpl-3.0.html """ import yaml import logging import sys import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, BASE_DIR) try: from builder.core.command_runner import run_command from builder.core.xbps_commands import xbps_commands from builder.configs import logger_config # Import the logger_config module from builder.core.bootstrap.paths import paths logger = logger_config.setup_logger('packages_install') # Pass the 'packages_install' argument except ImportError as e: print(f"Error importing necessary modules: {e}. Ensure your environment is set up correctly.") sys.exit(1) def install_common_packages_rootfs_yaml(rootfs_path, package_yaml_file, arch): """ Installs common packages into the rootfs by reading the package lists from a YAML file. Args: rootfs_path (str): Path to the rootfs directory. package_yaml_file (str): Path to the YAML file containing the common package lists. arch (str): Architecture (e.g., 'x86_64'). """ logger = logging.getLogger(__name__) # Initialize logger here logger.info(f"=> Installing common packages into ROOTFS using YAML: {package_yaml_file}") try: with open(package_yaml_file, 'r') as f: common_packages_config = yaml.safe_load(f) # Load the YAML except FileNotFoundError: logger.error(f"Package YAML file not found: {package_yaml_file}") return except yaml.YAMLError as e: logger.error(f"Error reading the YAML file: {package_yaml_file} - {e}") return total_package_list = [] package_categories = [ 'accessibility_packages', 'core_packages', 'xorg_packages', 'firmware_packages', 'shared_packages', 'installer_packages' ] for category in package_categories: if category in common_packages_config: # Check if the category exists in the YAML category_packages = common_packages_config[category] if isinstance(category_packages, list): # Check if it's a list total_package_list.extend(category_packages) # Add to the total list else: logger.warning(f"Category '{category}' in {package_yaml_file} is not a list of packages. Ignoring.") else: logger.warning(f"Category '{category}' not found in {package_yaml_file}. Ignoring.") if not total_package_list: logger.warning("No common package lists found in the YAML. Proceeding without installing common packages.") return # *** LOAD REPOSITORY CONFIGURATION FROM YAML *** repos_yaml_file = paths['REPOS_YAML_FILE'] try: with open(repos_yaml_file, 'r') as f: repo_data = yaml.safe_load(f) except FileNotFoundError: logger.error(f"Repository YAML file not found: {repos_yaml_file}") return except yaml.YAMLError as e: logger.error(f"Error reading the repository YAML file: {repos_yaml_file} - {e}") return repositories = repo_data.get('repositories', []) xbps_install_command = [ xbps_commands["XBPS_INSTALL_CMD"], '-S', '-y', '-r', rootfs_path, '-c', os.path.join(paths["ISO_CACHE_DIR"], arch) # Add the -c flag and the path to the cache directory ] for repo_dict in repositories: if arch in repo_dict.get('architectures', []): # Add repositories only for the target architecture repo_url = repo_dict['uri'] xbps_install_command.extend(['-R', repo_url]) xbps_install_command.extend(total_package_list) command_str = " ".join(xbps_install_command) # For more readable logging logger.info(f"=> Generated XBPS_INSTALL_CMD for common packages: {command_str}") try: logger.info(f"=> Executing XBPS_INSTALL_CMD for common packages [TARGETED AT: {rootfs_path}]") run_command(xbps_install_command) logger.info(f"=> Installation of common packages into ROOTFS completed.") except Exception as e: logger.error(f"Error executing XBPS_INSTALL_CMD for common packages: {e}") raise