#!/usr/bin/env bash
#
# Render the AppStream metainfo for the GeoLibre desktop app.
#
# It gives the app a name, description, screenshots, and a release history in
# software centers (the Fedora COPR package ships it). Only the <release> entry
# changes per version, so this script stamps the version and date and emits the
# rest verbatim.
#
# Usage:
#   VERSION=1.5.0 DATE=2026-06-20 scripts/render-linux-metainfo.sh > org.geolibre.desktop.metainfo.xml
#
# DATE is the release date (YYYY-MM-DD); both VERSION and DATE are required.
set -euo pipefail

: "${VERSION:?Set VERSION to the release version, e.g. 1.5.0}"
: "${DATE:?Set DATE to the release date, e.g. 2026-06-20}"

[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "VERSION does not look like a semver string" >&2; exit 1; }
[[ "$DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] || { echo "DATE must be YYYY-MM-DD" >&2; exit 1; }
# Reject syntactically valid but impossible dates (e.g. 2026-13-40). `date -d`
# is GNU coreutils; these scripts run on Linux/CI (on macOS, use coreutils).
date -u -d "$DATE" +%F >/dev/null 2>&1 || { echo "DATE is not a valid calendar date" >&2; exit 1; }

cat <<XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by scripts/render-linux-metainfo.sh; CI regenerates it per release. -->
<component type="desktop-application">
  <id>org.geolibre.desktop</id>
  <metadata_license>CC0-1.0</metadata_license>
  <project_license>MIT</project_license>
  <name>GeoLibre Desktop</name>
  <summary>Lightweight, cloud-native GIS platform</summary>

  <description>
    <p>
      GeoLibre is a lightweight, cloud-native desktop GIS for visualizing and
      analyzing geospatial data, built on MapLibre with deck.gl for 3D and
      large point-cloud overlays.
    </p>
    <p>
      It loads vector and raster files, web services, ArcGIS layers, MBTiles,
      3D Tiles, and cloud-native formats such as GeoParquet, FlatGeobuf,
      PMTiles, and COG, converting local data in the browser with DuckDB-WASM
      Spatial. Projects are saved in an open .geolibre.json format, and the app
      is extensible through a plugin ecosystem.
    </p>
    <p>Highlights:</p>
    <ul>
      <li>Add data from files, web services, databases, and cloud catalogs</li>
      <li>Vector and raster processing tools, with an optional Python sidecar</li>
      <li>A SQL workspace for DuckDB Spatial, and a docked Jupyter notebook</li>
      <li>Offline basemap downloads, story maps, and multi-user collaboration</li>
    </ul>
  </description>

  <launchable type="desktop-id">org.geolibre.desktop.desktop</launchable>

  <url type="homepage">https://geolibre.app/</url>
  <url type="bugtracker">https://github.com/opengeos/GeoLibre/issues</url>
  <url type="vcs-browser">https://github.com/opengeos/GeoLibre</url>

  <developer id="app.geolibre">
    <name>GeoLibre</name>
  </developer>

  <categories>
    <category>Science</category>
    <category>Geoscience</category>
    <category>Geography</category>
  </categories>

  <keywords>
    <keyword>GIS</keyword>
    <keyword>geospatial</keyword>
    <keyword>map</keyword>
    <keyword>MapLibre</keyword>
    <keyword>raster</keyword>
    <keyword>vector</keyword>
  </keywords>

  <screenshots>
    <screenshot type="default">
      <image>https://files.opengeos.org/GeoLibre-demo.webp</image>
      <caption>3D Tiles rendered on a MapLibre map in GeoLibre</caption>
    </screenshot>
  </screenshots>

  <content_rating type="oars-1.1" />

  <releases>
    <release version="${VERSION}" date="${DATE}">
      <url type="details">https://github.com/opengeos/GeoLibre/releases/tag/v${VERSION}</url>
    </release>
  </releases>
</component>
XML
