#!/bin/bash

# Source files
SOURCE_HTACCESS="/var/www/html/brspace/www/.htaccess"
SOURCE_HTPASSWORD="/var/www/html/brspace/.htpasswd"

# Base directory containing all sites
BASE_DIR="/var/www/html"

# Find all directories with www subdirectory
for site_dir in "$BASE_DIR"/*/; do
    # Check if www directory exists
    if [ -d "${site_dir}www" ]; then
        echo "Processing: ${site_dir}"
        
        # Copy .htaccess to www directory
        if [ -f "$SOURCE_HTACCESS" ]; then
            cp "$SOURCE_HTACCESS" "${site_dir}www/.htaccess"
            echo "  ✓ Copied .htaccess"
        else
            echo "  ✗ Source .htaccess not found"
        fi
        
        # Copy .htpassword to site root directory
        if [ -f "$SOURCE_HTPASSWORD" ]; then
            cp "$SOURCE_HTPASSWORD" "${site_dir}.htpasswd"
            echo "  ✓ Copied .htpassword"
        else
            echo "  ✗ Source .htpassword not found"
        fi
    fi
done

echo "Done!"
