#!/bin/bash # Path to your notice file NOTICE_FILE="./NOTICE" # Check if notice file exists if [ ! -f "$NOTICE_FILE" ]; then echo "Error: $NOTICE_FILE not found!" exit 1 fi # Find all .cpp, .hpp, .h, and .cc files # Excluding the .git directory find . -type d -name ".git" -prune -o -type d -name "build" -prune -o -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -o -name "*.cc" \) -print | while read -r file; do # Check if the file already contains a specific keyword from your notice # to avoid double-prepending (e.g., "Copyright") if grep -q "Copyright" "$file"; then echo "Skipping $file (License already exists)" else echo "Adding notice to $file" # Create a temp file: notice + newline + original content { cat "$NOTICE_FILE"; echo ""; cat "$file"; } > "$file.tmp" && mv "$file.tmp" "$file" fi done echo "Done!"