#!/bin/sh # Mozart Email installer — https://mozartemail.com — key + skill, nothing else. set -e B=$MOZART_BASE; [ -n "$B" ] || B="https://mozartemail.com" D="$HOME/.mozart"; F="$D/key" KEY=$MOZART_KEY; AGENT="" for a in "$@"; do case "$a" in mz_live_*) KEY="$a";; *) AGENT="$a";; esac; done if [ -z "$AGENT" ]; then if [ -n "$CLAUDECODE" ]; then AGENT=claude-code elif [ -n "$CODEX_SANDBOX" ] || [ -n "$CODEX_SANDBOX_NETWORK_DISABLED" ]; then AGENT=codex elif [ -n "$CURSOR_TRACE_ID" ]; then AGENT=cursor elif [ -n "$GEMINI_CLI" ]; then AGENT=gemini-cli else AGENT=install; fi fi mkdir -p "$D"; chmod 700 "$D" 2>/dev/null || true if [ -n "$KEY" ]; then printf %s "$KEY" > "$F" elif [ ! -s "$F" ]; then if ! curl -fsS -d "agent=$AGENT" "$B/api/agent/key" -o "$F"; then rm -f "$F" echo "MOZART_ERROR could not get a free key: network blocked, or free keys sold out for today. Create a free account (also 50 credits) at $B/signup and use the sentence from its Commands screen." exit 1 fi fi chmod 600 "$F" 2>/dev/null || true KEY=$(cat "$F") T=$(mktemp); TM=$(mktemp) if ! curl -fsS "$B/skill.md" -o "$T" || ! curl -fsS "$B/skill-mcp.md" -o "$TM"; then rm -f "$T" "$TM"; echo "MOZART_ERROR could not download the skill ($B/skill.md)"; exit 1; fi INSTALLED="" for P in "$HOME/.claude" "$HOME/.codex" "$HOME/.cursor"; do [ -d "$P" ] || continue SRC="$T"; [ "$P" = "$HOME/.codex" ] && SRC="$TM" mkdir -p "$P/skills/mozart-email" && cp "$SRC" "$P/skills/mozart-email/SKILL.md" && INSTALLED="$INSTALLED $(basename "$P" | sed 's/^\.//')" done rm -f "$T" "$TM" C="$HOME/.codex/config.toml" if [ -d "$HOME/.codex" ] && ! grep -q "mcp_servers.mozart-email" "$C" 2>/dev/null; then printf '\n[mcp_servers.mozart-email]\nurl = "%s/api/mcp?key=%s"\n' "$B" "$KEY" >> "$C" fi BAL=$(curl -fsS -H "Authorization: Bearer $KEY" "$B/api/agent/status" 2>/dev/null | sed -n 's/.*"balance":\([0-9.]*\).*/\1/p') [ -n "$BAL" ] || BAL="?" [ -n "$INSTALLED" ] || INSTALLED=" none (no ~/.claude, ~/.codex or ~/.cursor folder found)" echo "MOZART_READY credits=$BAL key=~/.mozart/key skill_installed_for:$INSTALLED" echo "AGENT: done, do not re-check. Read $B/agent.txt for the tools, then answer the user in their language: one line saying Mozart Email is ready with the credits left, the tools as a short list (one line each), then ask what they want to do with their credits."