#!/usr/bin/env bash

# omarchy:summary=Install Charles, the web debugging proxy
# omarchy:requires-sudo=true

# Based: Charles publishes its own signed apt repository and no Flatpak, so
# Debian adds that source, as the former dev tooling did; macOS takes the
# cask. Trusting the root certificate stays a manual step on both.

set -eo pipefail

echo "Installing Charles..."

case $(omarchy-os) in
darwin)
  omarchy-pkg-add charles cask=charles
  ;;
*)
  if omarchy-pkg-missing charles-proxy5; then
    sudo install -d -m 755 /etc/apt/keyrings
    curl -fsSL https://www.charlesproxy.com/packages/apt/charles-repo.asc | sudo tee /etc/apt/keyrings/charles-repo.asc >/dev/null
    echo "deb [signed-by=/etc/apt/keyrings/charles-repo.asc] https://www.charlesproxy.com/packages/apt/ charles-proxy main" | sudo tee /etc/apt/sources.list.d/charles.list >/dev/null
    sudo apt-get update
  fi
  omarchy-pkg-add charles-proxy5
  ;;
esac
