#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
PHP_BIN=${PHP_BIN:-php}
if [ "$#" -ne 3 ]; then echo 'Usage: sh deployment/install.sh tenant-slug "Company Name" admin@example.com'; exit 1; fi
[ -f .env ] || { echo 'Create .env from .env.production.example first.'; exit 1; }
"$PHP_BIN" -r 'if (PHP_VERSION_ID < 80300) { fwrite(STDERR, "PHP 8.3 or newer is required. Select the hosting PHP CLI path.\n"); exit(1); }'
umask 077
mkdir -p storage/app/private storage/app/public storage/framework/cache/data storage/framework/sessions storage/framework/views storage/framework/testing storage/logs bootstrap/cache
"$PHP_BIN" artisan config:clear
"$PHP_BIN" artisan zentrik:keys:initialize
"$PHP_BIN" artisan migrate --force
"$PHP_BIN" artisan zentrik:storage:verify
"$PHP_BIN" artisan zentrik:install "$1" "$2" "$3"
"$PHP_BIN" artisan config:cache
"$PHP_BIN" artisan view:cache
printf '%s
' 'Set the web document root to public/, enable host HTTPS and configure the cron entry in docs/HOSTING.md.'
