#!/usr/bin/env bash # One-shot local installer for the prospector operator app: dependencies, env # files, database + migrations, and a production build of the API + web panel. # Idempotent — safe to re-run after a pull. # # scripts/install.sh full setup # scripts/install.sh --launch setup, then open the app (Chrome PWA window) # ./run install (preferred entrypoint) # # Flags / env: # --launch run scripts/app.sh at the end # SKIP_DB=1 skip database creation + migrations # PSQL=/path use a specific psql binary set -euo pipefail . "$(dirname "${BASH_SOURCE[0]}")/lib.sh" LAUNCH=0 [[ "${1:-}" == "--launch" ]] && LAUNCH=1 echo -e "${BLUE}prospector${NC} — local installer" echo "" # 1. Preflight ──────────────────────────────────────────────────────────────── info "checking prerequisites" command -v node >/dev/null 2>&1 || die "node not found (need Node 20+). Install: brew install node" command -v npm >/dev/null 2>&1 || die "npm not found." node_major="$(node -p 'process.versions.node.split(".")[0]')" [[ "$node_major" -ge 20 ]] || warn "Node $(node -v) detected; 20+ recommended." ok "node $(node -v)" # 2. Dependencies (root install also covers the web workspace) ───────────────── info "installing dependencies (root + web workspace)" ( cd "$REPO_ROOT" && npm install ) ok "dependencies installed" # 3. Env files (create from sane localhost defaults if absent) ───────────────── if [[ ! -f "$REPO_ROOT/.env.local" ]]; then info "creating .env.local (localhost defaults)" cat > "$REPO_ROOT/.env.local" <<'ENV' NODE_ENV=development PROSPECTOR_API_PORT=3210 PROSPECTOR_DB_HOST=127.0.0.1 PROSPECTOR_DB_PORT=5432 PROSPECTOR_DB_NAME=prospector PROSPECTOR_DB_USER=postgres PROSPECTOR_DB_PASSWORD= PROSPECTOR_DB_SSL=false PROSPECTOR_DB_POOL_MAX=10 PROSPECTOR_SERVICE_TOKEN=devtoken PEOPLE_BASE_URL=http://127.0.0.1:3061 PEOPLE_SERVICE_TOKEN=devtoken MACSYNC_BASE_URL=http://127.0.0.1:9999 MACSYNC_SERVICE_TOKEN=dummy MACSYNC_DEVICE_ID=dummy MRNUMBER_BASE_URL=http://127.0.0.1:9999 MRNUMBER_SERVICE_TOKEN=dummy ENV ok "wrote .env.local — review DB credentials before first run" else ok ".env.local present (left untouched)" fi if [[ ! -f "$REPO_ROOT/web/.env.local" ]]; then info "creating web/.env.local" # Keep the panel's proxy token in sync with the API's service token. load_env cat > "$REPO_ROOT/web/.env.local" <