new commit
This commit is contained in:
parent
2d7dcc99ad
commit
eee4d3f035
@ -57,4 +57,69 @@ def run_command(command, env=None):
|
||||
except FileNotFoundError as e:
|
||||
logger.error(f"Error: Command not found: {command[0] if isinstance(command, list) else command}")
|
||||
logger.error(f"Details: {e}")
|
||||
raise
|
||||
|
||||
def run_command_in_target(rootfs_path, command, architecture, check=True, shell=False, cwd=None, env=None):
|
||||
"""
|
||||
Runs a command within the target root filesystem using chroot.
|
||||
Sets necessary environment variables for the target architecture.
|
||||
|
||||
Args:
|
||||
rootfs_path (str): Path to the target root filesystem directory.
|
||||
command (list): The command and its arguments as a list (command path should be relative to target root).
|
||||
architecture (str): The target architecture (e.g., 'aarch64').
|
||||
check (bool): If True, raise CalledProcessError if the command returns a non-zero exit code.
|
||||
shell (bool): If True, execute the command through the shell within the chroot.
|
||||
cwd (str, optional): The current working directory *within the chroot*. (Note: Requires shell=True or `cd` prefix).
|
||||
env (dict, optional): A dictionary of environment variables to set *inside the chroot*.
|
||||
XBPS_ARCH is set automatically.
|
||||
|
||||
Returns:
|
||||
subprocess.CompletedProcess: The result of the command execution.
|
||||
|
||||
Raises:
|
||||
subprocess.CalledProcessError: If check is True and the command fails.
|
||||
FileNotFoundError: If the chroot binary or the command within chroot is not found.
|
||||
ValueError: If rootfs_path is invalid.
|
||||
"""
|
||||
if not rootfs_path or not os.path.isdir(rootfs_path):
|
||||
logger.error(f"Invalid target root filesystem path for chroot: {rootfs_path}")
|
||||
raise ValueError(f"Invalid target root filesystem path for chroot: {rootfs_path}")
|
||||
|
||||
chroot_env_list = [f"XBPS_ARCH={architecture}"]
|
||||
if env:
|
||||
for key, value in env.items():
|
||||
if key != 'XBPS_ARCH':
|
||||
chroot_env_list.append(f"{key}={value}")
|
||||
|
||||
full_command = ["chroot", rootfs_path, "env"] + chroot_env_list + command
|
||||
|
||||
logger.info(f"Executing command IN TARGET ({rootfs_path}): {' '.join(full_command)}")
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
full_command,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=check,
|
||||
shell=shell,
|
||||
)
|
||||
|
||||
logger.debug(f"STDOUT:\n{result.stdout.strip()}")
|
||||
if result.stderr.strip():
|
||||
logger.debug(f"STDERR:\n{result.stderr.strip()}")
|
||||
|
||||
return result
|
||||
|
||||
except FileNotFoundError:
|
||||
logger.error(f"Command not found in target chroot or chroot binary failed: {command[0] if command else 'N/A'}. Ensure base system is correctly installed.")
|
||||
raise
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"Command failed in target with exit code {e.returncode}")
|
||||
logger.error(f"Command: {' '.join(e.cmd)}")
|
||||
logger.error(f"Stderr:\n{e.stderr.strip()}")
|
||||
logger.error(f"Stdout:\n{e.stdout.strip()}")
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"An unexpected error occurred during command execution in target: {e}")
|
||||
raise
|
@ -110,8 +110,6 @@ def reconfigure_system_in_chroot(rootfs_path, architecture, repositories_list, b
|
||||
result_dkms_check = run_command(check_dkms_cmd)
|
||||
if result_dkms_check.returncode == 0:
|
||||
logger.info("=> DKMS found. Forcing DKMS reconfiguration...")
|
||||
|
||||
# *** ADD LOGGING TO LIST DKMS PACKAGE FILES ***
|
||||
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)
|
||||
|
@ -248,10 +248,11 @@ def iso_builder_main(
|
||||
|
||||
logger.info("=> Starting system reconfiguration in chroot...")
|
||||
reconfigure_system_in_chroot(
|
||||
paths['ROOTFS'],
|
||||
architecture,
|
||||
host_arch,
|
||||
repositories,
|
||||
rootfs_path=paths['ROOTFS'],
|
||||
target_architecture=architecture,
|
||||
repositories_data=repositories,
|
||||
paths=paths,
|
||||
locale="en_US.UTF-8"
|
||||
)
|
||||
logger.info("=> System reconfiguration in chroot COMPLETE.")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user