#!/bin/bash

# File Permissions Script for cPanel Laravel Deployment
# Run this script via SSH after uploading files to cPanel

echo "=========================================="
echo "Setting File Permissions for cPanel"
echo "=========================================="

# Navigate to project directory
cd ~/public_html/igen-backend || exit 1

# Set directory permissions
echo "Setting directory permissions to 755..."
find . -type d -exec chmod 755 {} \;

# Set file permissions
echo "Setting file permissions to 644..."
find . -type f -exec chmod 644 {} \;

# Special permissions for storage directory
echo "Setting storage directory permissions to 775..."
chmod -R 775 storage
chmod -R 775 bootstrap/cache

# Ensure storage and cache are writable
echo "Ensuring storage and cache are writable..."
chmod -R 775 storage/logs
chmod -R 775 storage/framework
chmod -R 775 storage/app/public
chmod -R 775 bootstrap/cache

# Set ownership to current user
echo "Setting ownership..."
chown -R $(whoami):$(whoami) .
chown -R $(whoami):$(whoami) storage
chown -R $(whoami):$(whoami) bootstrap/cache

echo "=========================================="
echo "File permissions set successfully!"
echo "=========================================="
