#!/bin/bash if [ $# -eq 0 ]; then echo "Usage: $0 " exit 1 fi profile="$1" source .config source ./profiles/$profile/metadata dir="/tmp/wacca/$profile" PATCHES_DIR="./patches" [ ! -d "$PATCHES_DIR" ] && { echo "Error: $PATCHES_DIR not found"; exit 1; } # Change to patches directory and process files in numerical order cd "$PATCHES_DIR" || exit 1 # Use ls with version sort to handle numbers correctly (1,2,3,10,50,etc.) for script in $(ls -1v 2>/dev/null); do [ -f "$script" ] && [ -r "$script" ] || continue echo -e "\033[0;34m=== Applying: $script ===\033[0m" # Create a named pipe for real-time output pipe=$(mktemp -u) mkfifo "$pipe" # Execute the script with real-time output if (source "$script" 2>&1 | while IFS= read -r line; do echo "[$script] $line" done); then echo -e "\033[0;32m=== Successfully applied: $script ======\033[0m" else exit_code=$? echo -e "\033[0;31m=== Failed: $script (exit code: $exit_code) ===\033[0m" fi # Clean up the pipe rm -f "$pipe" echo done