#!/bin/bash
# Transcribe installer. Downloads the app, installs it to /Applications,
# and clears the download quarantine so the bundled engine can run.
set -e
DOMAIN="https://transcribe.heliconsolutions.net"
BLUE='\033[1;34m'; GRN='\033[1;32m'; NC='\033[0m'

printf "${BLUE}Transcribe${NC}  installing...\n"

# Apple Silicon check
if [ "$(uname -m)" != "arm64" ]; then
  echo "This build needs an Apple Silicon Mac (M1 or newer)."; exit 1
fi

TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
printf "  downloading app...\n"
curl -fsSL "$DOMAIN/Transcribe.zip" -o "$TMP/Transcribe.zip"

printf "  installing to /Applications...\n"
rm -rf /Applications/Transcribe.app
ditto -x -k "$TMP/Transcribe.zip" /Applications/

# Clear quarantine so the bundled whisper engine is not killed by Gatekeeper.
xattr -dr com.apple.quarantine /Applications/Transcribe.app 2>/dev/null || true

printf "${GRN}  done.${NC} opening Transcribe...\n"
printf "  (first launch downloads the speech model once, about 650 MB)\n"
open /Applications/Transcribe.app
