#!/bin/bash

# Script to fix directory permissions for web deployment
# Usage: ./fix_site_permissions.sh /path/to/directory

if [ $# -eq 0 ]; then
    echo "Error: No directory path provided"
    echo "Usage: $0 /path/to/directory"
    exit 1
fi

DIR_PATH="$1"

# Create directory if it doesn't exist
if [ ! -d "$DIR_PATH" ]; then
    echo "Directory does not exist. Creating: $DIR_PATH"
    mkdir -p "$DIR_PATH"
fi

# Set ownership to www-data:www-data
echo "Setting ownership to www-data:www-data..."
chown -R www-data:www-data "$DIR_PATH"

# Set permissions to 775
echo "Setting permissions to 775..."
chmod -R 775 "$DIR_PATH"

echo "Permissions fixed successfully!"
echo "Current status:"
ls -ld "$DIR_PATH"
