#!/usr/bin/env bash

# omarchy:summary=Install MongoDB Compass, the MongoDB GUI
# omarchy:requires-sudo=true

# Based: Flathub carries Compass for amd64; the arm64 build is the Flatpak
# bundle Based publishes, since Flathub has none. macOS takes the cask.

set -eo pipefail

app_id=com.mongodb.Compass

echo "Installing MongoDB Compass..."

case $(omarchy-os) in
darwin)
  omarchy-pkg-add mongodb-compass cask=mongodb-compass
  ;;
*)
  case $(dpkg --print-architecture) in
  arm64)
    if ! omarchy-pkg-flatpak-present "$app_id"; then
      tmp=$(mktemp -d)
      trap 'rm -rf "$tmp"' EXIT
      curl -fL --progress-bar https://s3.eu-west-3.amazonaws.com/public.bitspur.com/binaries/compass/mongodb-compass-aarch64.flatpak -o "$tmp/compass.flatpak"
      sudo flatpak install --system -y "$tmp/compass.flatpak"
    fi
    ;;
  *)
    omarchy-pkg-add mongodb-compass flatpak=$app_id
    ;;
  esac
  ;;
esac
