#!/bin/bash

# Laravel Production Deployment Script for cPanel
# Run this script after uploading files to cPanel

echo "=========================================="
echo "Laravel Production Deployment Script"
echo "=========================================="

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

# 1. Install dependencies
echo "Step 1: Installing Composer dependencies..."
composer install --no-dev --optimize-autoloader --no-interaction

# 2. Set permissions
echo "Step 2: Setting file permissions..."
chmod -R 755 storage
chmod -R 755 bootstrap/cache
chown -R $(whoami):$(whoami) storage
chown -R $(whoami):$(whoami) bootstrap/cache

# 3. Create storage link
echo "Step 3: Creating storage link..."
php artisan storage:link

# 4. Clear and cache configuration
echo "Step 4: Optimizing Laravel..."
php artisan config:clear
php artisan config:cache
php artisan route:clear
php artisan route:cache
php artisan view:clear
php artisan view:cache
php artisan optimize

# 5. Clear application cache
echo "Step 5: Clearing application cache..."
php artisan cache:clear

echo "=========================================="
echo "Deployment completed successfully!"
echo "=========================================="
