#!/usr/bin/env bash

# omarchy:summary=Install AnythingLLM, the local RAG desktop app
# omarchy:requires-sudo=true

# Based: AnythingLLM is not on Flathub, so its community Flatpak bundle is
# fetched and installed system-wide, as the former dev tooling did; macOS
# takes the cask.

set -eo pipefail

version=1.8.1-r2
app_id=com.useanything.AnythingLLMDesktop

echo "Installing AnythingLLM..."

case $(omarchy-os) in
darwin)
  omarchy-pkg-add anythingllm cask=anythingllm
  ;;
*)
  if ! omarchy-pkg-flatpak-present "$app_id"; then
    tmp=$(mktemp -d)
    trap 'rm -rf "$tmp"' EXIT
    curl -fL --progress-bar "https://github.com/zaro/anything-llm-flatpak/releases/download/$version/AnythingLLM.flatpak" -o "$tmp/AnythingLLM.flatpak"
    sudo flatpak install --system -y "$tmp/AnythingLLM.flatpak"
  fi
  ;;
esac
