wackman/applypatches.sh
2025-10-18 00:33:20 +02:00

47 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <profile>"
exit 1
fi
profile="$1"
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"
# Use a temporary file to capture exit status and output
temp_file=$(mktemp)
# Source the script and capture both stdout and stderr
if (source "$script") > "$temp_file" 2>&1; then
# Script succeeded - output with script name prefix
while IFS= read -r line; do
echo "[$script] $line"
done < "$temp_file"
echo -e "\033[0;32m=== Successfully applied: $script ======\033[0m"
else
exit_code=$?
# Script failed - output with script name prefix and error message
while IFS= read -r line; do
echo "[$script] $line"
done < "$temp_file"
echo -e "\033[0;31m=== Failed: $script (exit code: $exit_code) ===\033[0m"
fi
rm -f "$temp_file"
echo
done