#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")/.."

command -v php >/dev/null || { echo "PHP is required." >&2; exit 1; }
command -v composer >/dev/null || { echo "Composer 2 is required." >&2; exit 1; }

if [[ ! -f .env ]]; then
  cp .env.example .env
fi

composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan key:generate --force
mkdir -p storage/app/private storage/app/public storage/framework/{cache/data,sessions,views} storage/logs bootstrap/cache
chmod -R ug+rwX storage bootstrap/cache
php artisan storage:link || true

echo "Dependencies are installed. Configure DB_* in .env, then open /install."
