#!/usr/bin/env bash
# Install Inter and IBM Plex Mono into this folder and the system.
# Safe to run repeatedly.

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

echo "==> Fetching Inter latest..."
INTER_URL=$(curl -s https://api.github.com/repos/rsms/inter/releases/latest \
  | grep "browser_download_url.*Inter.*\.zip" \
  | head -1 \
  | cut -d '"' -f 4)
curl -L -o inter.zip "$INTER_URL"
unzip -o -q inter.zip -d Inter/
rm inter.zip

echo "==> Fetching IBM Plex Mono..."
PLEX_URL=$(curl -s https://api.github.com/repos/IBM/plex/releases/latest \
  | grep "browser_download_url.*IBM-Plex-Mono.zip\|browser_download_url.*TrueType.zip" \
  | head -1 \
  | cut -d '"' -f 4)
curl -L -o plex.zip "$PLEX_URL"
unzip -o -q plex.zip -d IBMPlexMono/
rm plex.zip

echo ""
echo "Done. Fonts in:"
echo "  $SCRIPT_DIR/Inter"
echo "  $SCRIPT_DIR/IBMPlexMono"
echo ""
echo "To install system-wide on macOS:"
echo "  cp Inter/*.ttf ~/Library/Fonts/"
echo "  cp IBMPlexMono/*.ttf ~/Library/Fonts/"
echo ""
echo "To install system-wide on Linux:"
echo "  mkdir -p ~/.local/share/fonts"
echo "  cp Inter/*.ttf IBMPlexMono/*.ttf ~/.local/share/fonts/"
echo "  fc-cache -f -v"
