#!/bin/bash
# Installs Taploom for early buyers. curl downloads don't get the "downloaded from the internet"
# flag, so macOS opens the unsigned app without the Gatekeeper warning.
# Usage: curl -fsSL https://taploom.polodarb.com/install.sh | bash
set -euo pipefail

DMG_URL="https://dl.taploom.polodarb.com/early/Taploom.dmg"
APP="/Applications/Taploom.app"

tmp="$(mktemp -d)"
cleanup() {
  hdiutil detach "$tmp/mnt" -quiet 2>/dev/null || true
  rm -rf "$tmp"
}
trap cleanup EXIT

echo "Downloading Taploom..."
curl -fL --progress-bar "$DMG_URL" -o "$tmp/Taploom.dmg"

hdiutil attach "$tmp/Taploom.dmg" -nobrowse -readonly -quiet -mountpoint "$tmp/mnt"

if [ -d "$APP" ]; then
  osascript -e 'quit app "Taploom"' 2>/dev/null || true
  rm -rf "$APP"
fi

echo "Installing to /Applications..."
ditto "$tmp/mnt/Taploom.app" "$APP"

echo "Done. Opening Taploom."
open "$APP"
