#!/bin/sh
# usage: ./check.sh <mc version>
MC="$1"
[ -z "$MC" ] && { echo "usage: $0 <mc version>"; exit 1; }

MODS="
https://modrinth.com/mod/c2me-fabric
https://modrinth.com/mod/clumps
https://modrinth.com/mod/ferrite-core
https://modrinth.com/mod/krypton
https://modrinth.com/mod/lithium
https://modrinth.com/mod/scalablelux
https://modrinth.com/mod/servercore
https://modrinth.com/mod/vmp-fabric
https://modrinth.com/mod/appleskin
https://modrinth.com/mod/fallingtree
https://modrinth.com/plugin/magnetic
https://modrinth.com/mod/fabric-language-kotlin
https://modrinth.com/mod/yacl
https://modrinth.com/mod/map-distance-fix
https://modrinth.com/mod/rightclickharvest
https://modrinth.com/mod/jamlib
https://modrinth.com/datapack/veinminer
https://modrinth.com/plugin/voxy-server-side
https://modrinth.com/mod/welcome-message
https://modrinth.com/mod/collective
https://modrinth.com/mod/xaeros-minimap
https://modrinth.com/mod/xaeros-world-map
https://modrinth.com/mod/servux
https://modrinth.com/mod/spark
https://modrinth.com/plugin/tabtps
https://modrinth.com/datapack/no-enderman-grief
"

# pulls the first (newest) value of a JSON field out of $res
field() { echo "$res" | grep -o "\"$1\":\"[^\"]*\"" | head -1 | cut -d'"' -f4; }

for url in $MODS; do
  m="${url##*/}"
  res=$(curl -sG "https://api.modrinth.com/v2/project/$m/version" \
    -H "User-Agent: FatherOfAlways/mc-compat-check" \
    --data-urlencode "game_versions=[\"$MC\"]" \
    --data-urlencode 'loaders=["fabric"]')
  case "$res" in
    "[]")  echo "MISSING  $m" ;;
    "["*)  extra=""
           # comment out any line below to hide that field
           # extra="$extra $(field version_number)"
           # extra="$extra ($(field version_type))"
           echo "OK       $m$extra" ;;
    *)     echo "ERROR    $m  (bad slug, or the request failed)" ;;
  esac
done