#!/usr/bin/env bash set -e echo "========================================================" echo " Tala Cognitive Engine Room - Native macOS Installer" echo "========================================================" echo "" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" ROOT_DIR="$SCRIPT_DIR" # 1. Preflight bash "$ROOT_DIR/scripts/doctor.sh" DOCTOR_EXIT=$? if [ $DOCTOR_EXIT -eq 2 ]; then echo -e "\033[31mDoctor found critical issues (e.g., port conflicts). Please resolve them before running the installer.\033[0m" exit 1 elif [ $DOCTOR_EXIT -eq 1 ]; then echo -e "\033[33mDoctor found missing dependencies. Attempting to install them...\033[0m" fi # 2. Dependencies via Homebrew echo "[2/6] Checking Dependencies via Homebrew..." if ! command -v brew &> /dev/null; then echo -e "\033[33mHomebrew is not installed. Tala can install it with the official Homebrew installer.\033[0m" read -p "Install Homebrew now? (Y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]] && [[ -n $REPLY ]]; then echo -e "\033[31mHomebrew is required for automatic macOS dependency installation: https://brew.sh/\033[0m" exit 1 fi /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" if [ -x "/opt/homebrew/bin/brew" ]; then eval "$(/opt/homebrew/bin/brew shellenv)" elif [ -x "/usr/local/bin/brew" ]; then eval "$(/usr/local/bin/brew shellenv)" fi fi install_if_missing() { local cmd="$1" local brew_pkg="$2" local friendly_name="$3" if command -v "$cmd" &> /dev/null; then echo -e " - \033[32m$friendly_name is already installed.\033[0m" else echo -e " - \033[33mInstalling $friendly_name via brew...\033[0m" brew install "$brew_pkg" echo -e " - \033[32m$friendly_name installed!\033[0m" fi } install_if_missing "node" "node@20" "Node.js" if ! command -v node &> /dev/null; then export PATH="$(brew --prefix node@20)/bin:$PATH" fi install_if_missing "uv" "uv" "Python (uv)" if ! command -v python3 &> /dev/null && ! command -v python &> /dev/null; then echo -e " - \033[33mPython runtime not found. Installing Python 3.11 via uv...\033[0m" uv python install 3.11 echo -e " - \033[32mPython runtime is available through uv.\033[0m" else echo -e " - \033[32mPython runtime is already available.\033[0m" fi install_if_missing "psql" "postgresql@16" "PostgreSQL" if ! command -v psql &> /dev/null; then export PATH="$(brew --prefix postgresql@16)/bin:$PATH" fi # Ensure Postgres service is running echo " - Ensuring PostgreSQL service is running..." brew services start postgresql@16 >/dev/null 2>&1 || true # 3. Bootstrap Database echo "[3/6] Bootstrapping Database..." sleep 2 # give postgres a second to start if it was just installed bash "$ROOT_DIR/scripts/bootstrap-db.sh" "tala" "tala" "tala" # 4. Generate .env safely echo "[4/6] Checking Configuration..." ENV_PATH="$ROOT_DIR/.env" if [ -f "$ENV_PATH" ]; then echo -e " - \033[33m.env file already exists. Skipping generation to prevent silent overwrite.\033[0m" else echo -e " - \033[33m.env will be generated by first-run setup.\033[0m" fi # 5. First-run setup echo "[5/6] Running First-Run Setup..." cd "$ROOT_DIR" uv run python scripts/first_run.py --self-test echo "[6/6] Final Checks" echo -e "========================================================" echo -e " \033[32mInstallation Complete!\033[0m" echo -e " \033[32mRun Tala by executing: ./scripts/start-tala.sh\033[0m" echo -e "========================================================"