#!/bin/bash
# cPanel setup — run in Terminal:
#
#   cd ~/gpstracker.amritduwal.com.np/gps_tracker_backend
#   source ~/virtualenv/gpstracker.amritduwal.com.np/3.10/bin/activate
#   bash deploy/cpanel_setup.sh
#
# Uses SQLite by default (recommended for shared cPanel hosting).
# Remove USE_POSTGRES from cPanel env vars if set — PG 10 on cPanel is too old for Django 5.
#
# Optional cPanel env vars:
#   DJANGO_DEBUG=False
#   DJANGO_SECRET_KEY=your-random-secret-key

set -e

echo "Installing Python packages..."
pip install -r requirements.txt

echo "Ensuring SQLite database is writable..."
touch db.sqlite3
chmod 664 db.sqlite3

echo "Running migrations..."
python manage.py migrate --noinput

echo "Collecting static files..."
python manage.py collectstatic --noinput

echo "Done. Restart: cPanel -> Setup Python App -> Restart"
echo "Database: $(pwd)/db.sqlite3"
