#!/usr/bin/env bash
# One-shot deploy / upgrade script for cPanel shells (run from the folder that contains `artisan`).
set -euo pipefail
PHP=${PHP:-php}
$PHP -v | head -1
[ -f .env ] || { cp .env.example .env; echo ">> .env created from .env.example — edit DB_* and secrets, then re-run."; exit 1; }
grep -q '^APP_KEY=base64' .env || $PHP artisan key:generate --force
$PHP artisan migrate --force
$PHP artisan db:seed --force                # roles, reference data, plans, first super admin (idempotent)
$PHP artisan hybrid:mirror                  # build / refresh the JSON fallback mirror
$PHP artisan storage:link || true
$PHP artisan config:cache && $PHP artisan route:cache && $PHP artisan view:cache
chmod -R ug+rwX storage bootstrap/cache
echo ">> Deployed. Add the cron line from deploy/cpanel/cron.txt and log in at /admin/login."
