HarborGuard_HarborGuard/scripts/execute-patch-commands.sh
brandon a04bbc2f5a Implement robust patch command execution to prevent quote escaping issues
- Changed command format from single line with && to newline-separated commands
- Updated PatchExecutorTarUnshare.ts to generate simpler commands without complex nesting
- Modified both buildah scripts to read and execute commands line by line
- Created execute-patch-commands.sh helper script for cleaner execution
- Split complex apt-get commands into simpler individual operations
- Process packages individually for better error handling and debugging

This robust approach completely avoids shell quote escaping issues by:
1. Writing commands to a file with newline separation
2. Reading and executing each command individually
3. Using parameter substitution instead of complex eval operations
2025-09-29 22:17:00 -04:00

36 lines
939 B
Bash
Executable File

#!/bin/bash
# Robust script to execute patch commands
# This script is designed to be sourced or executed with proper variable substitution
set -e
# Arguments
MOUNTPOINT="$1"
COMMANDS_FILE="$2"
if [ -z "$MOUNTPOINT" ] || [ -z "$COMMANDS_FILE" ]; then
echo "Usage: $0 MOUNTPOINT COMMANDS_FILE"
exit 1
fi
if [ ! -f "$COMMANDS_FILE" ]; then
echo "Error: Commands file not found: $COMMANDS_FILE"
exit 1
fi
echo "Executing patch commands for mountpoint: $MOUNTPOINT"
# Read the commands file line by line and execute each command
# This approach avoids shell quote parsing issues
while IFS= read -r line || [ -n "$line" ]; do
if [ -n "$line" ]; then
# Replace $mountpoint placeholder with actual mountpoint
cmd="${line//\$mountpoint/$MOUNTPOINT}"
echo "Executing: $cmd"
eval "$cmd" || {
echo "Warning: Command failed, continuing: $cmd"
}
fi
done < "$COMMANDS_FILE"
echo "All patch commands executed"