#!/usr/bin/env bash
set -euo pipefail
APP_DIR="/home2/doctorlabs/jan-enterprises-erp"
PUBLIC_DIR="/home2/doctorlabs/public_html/jan.doctorlabs.in"
cd "$APP_DIR"
command -v php >/dev/null || { echo "PHP CLI is required"; exit 1; }
command -v composer >/dev/null || { echo "Composer is required in cPanel/WHM"; exit 1; }
composer install --no-dev --optimize-autoloader
[ -f .env ] || cp .env.example .env
if grep -q 'DB_PASSWORD=CHANGE_ME' .env; then
  echo "STOP: edit $APP_DIR/.env and set the real MySQL credentials before continuing."
  exit 2
fi
php artisan key:generate --force
php artisan migrate --seed --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
chmod -R 775 storage bootstrap/cache
mkdir -p "$PUBLIC_DIR"
echo "Application installed. Open https://jan.doctorlabs.in"
echo "Add cron: * * * * * cd $APP_DIR && php artisan schedule:run >> /dev/null 2>&1"
