wackman/applypatches.sh
2025-10-20 14:50:25 +02:00

44 lines
No EOL
1.1 KiB
Bash
Executable file

#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <profile>"
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"
echo "$script" >> $dir/patches
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