#!/bin/bash
# Crew installer.  curl -fsSL https://crew-deskmates.vercel.app/crew/get.sh | bash
#
# Why this exists: Crew is not notarised yet. A browser download gets tagged with
# com.apple.quarantine, which is what makes macOS warn you and demand a
# right-click → Open. curl does not tag what it fetches, so installing this way
# skips both. Nothing here needs sudo, Homebrew, or any tool macOS lacks.
set -euo pipefail

ZIP="https://crew-deskmates.vercel.app/crew/Crew.zip"
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT

echo "▸ downloading Crew…"
curl -fsSL "$ZIP" -o "$TMP/Crew.zip"
echo "  sha256 $(shasum -a 256 "$TMP/Crew.zip" | cut -d' ' -f1)"
echo "  (compare it with the one on the download page if you like)"

unzip -q "$TMP/Crew.zip" -d "$TMP"
[ -d "$TMP/Crew/Crew.app" ] || { echo "✗ that archive didn't contain Crew.app"; exit 1; }

echo "▸ installing to /Applications…"
pkill -9 -x Crew 2>/dev/null || true
rm -rf /Applications/Crew.app
cp -R "$TMP/Crew/Crew.app" /Applications/Crew.app

echo "▸ connecting to Claude Code…"
/Applications/Crew.app/Contents/MacOS/Crew --setup

open /Applications/Crew.app
echo
echo "Done 🐾  Crew is in your menu bar."
echo "Start a Claude Code chat and its creature walks in along the bottom."
echo "To remove it later:  /Applications/Crew.app/Contents/MacOS/Crew --uninstall && rm -rf /Applications/Crew.app"
