#!/bin/bash
# Fix permissions for Google Drive credentials file

CREDENTIALS_FILE="/var/www/html/wordpress6/secure/google-drive-credentials.json"
SECURE_DIR="/var/www/html/wordpress6/secure"

echo "Fixing permissions for credentials file..."

# Set directory permissions (web server needs execute to access)
sudo chown www-data:www-data "$SECURE_DIR"
sudo chmod 750 "$SECURE_DIR"

# Set file permissions (readable by web server)
sudo chown www-data:www-data "$CREDENTIALS_FILE"
# Try 640 first (readable by owner and group), if that doesn't work, use 644
sudo chmod 640 "$CREDENTIALS_FILE"  # Read for owner and group
# If still having issues, uncomment the line below:
# sudo chmod 644 "$CREDENTIALS_FILE"  # Readable by all (less secure but more compatible)

echo ""
echo "Verification:"
echo "Directory:"
ls -ld "$SECURE_DIR"
echo ""
echo "File:"
ls -la "$CREDENTIALS_FILE"

echo ""
echo "✓ Permissions fixed!"
echo ""
echo "Note: File is now readable by www-data (web server user)"

