#!/bin/bash
# Script to set up Google Drive API credentials file permissions

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

# Check if file exists
if [ ! -f "$CREDENTIALS_FILE" ]; then
    echo "Error: Credentials file not found at $CREDENTIALS_FILE"
    echo "Please download the JSON file from Google Cloud Console first."
    exit 1
fi

# Set ownership to web server user
echo "Setting ownership to www-data:www-data..."
sudo chown www-data:www-data "$CREDENTIALS_FILE"

# Set secure permissions (read/write for owner only)
echo "Setting permissions to 600 (read/write owner only)..."
sudo chmod 600 "$CREDENTIALS_FILE"

# Verify the changes
echo ""
echo "Verification:"
ls -la "$CREDENTIALS_FILE"

echo ""
echo "✓ Credentials file permissions set successfully!"
echo "File: $CREDENTIALS_FILE"
echo "Owner: www-data:www-data"
echo "Permissions: 600 (read/write owner only)"

