#!/bin/bash

# RuralPoint - cPanel Deployment Script
# This script helps you deploy your Django application to cPanel

echo "🚀 Starting RuralPoint deployment to cPanel..."

# Step 1: Install dependencies
echo "📦 Installing Python dependencies..."
pip install -r requirements.txt

# Step 2: Create necessary directories
echo "📁 Creating necessary directories..."
mkdir -p logs
mkdir -p media
mkdir -p staticfiles

# Step 3: Set environment variables (update these with your actual values)
echo "🔧 Setting up environment variables..."
export SECRET_KEY="(W6B1[bCEAu,1wA[dz7^"
export DB_NAME="acbptxvs_ruralpoint_system"
export DB_USER="acbptxvs_phin"
export DB_PASSWORD="5;)8.H8aTG8%p_]"
export DB_HOST="localhost"
export DB_PORT="3306"

# Step 4: Run database migrations
echo "🗄️ Running database migrations..."
python manage.py makemigrations
python manage.py migrate

# Step 5: Create cache table
echo "💾 Creating cache table..."
python manage.py createcachetable

# Step 6: Collect static files
echo "📂 Collecting static files..."
python manage.py collectstatic --noinput

# Step 7: Create superuser (uncomment if needed)
# echo "👤 Creating superuser..."
# python manage.py createsuperuser

# Step 8: Load sample data (uncomment if needed)
# echo "📊 Loading sample data..."
# python manage.py load_sample_data

# Step 9: Set proper permissions
echo "🔐 Setting file permissions..."
chmod 755 .
chmod 644 *.py
chmod 644 .htaccess
chmod -R 755 staticfiles/
chmod -R 755 media/
chmod -R 755 logs/

echo "✅ Deployment completed successfully!"
echo "🌐 Your application should now be accessible at your domain"
echo "📧 Don't forget to configure your email settings in settings_production.py"
echo "🔒 Remember to change the SECRET_KEY in production!" 