#!/bin/sh
# Draco desktop GUI launcher.
#
# The GUI is cgo + webview and links a SPECIFIC webkit2gtk soname. Debian 12 ships 4.0; Debian
# 13 / Kali / Ubuntu 24.10+ ship only 4.1. Shipping one build meant the .deb installed happily
# (the Depends line accepts either library) and then died at exec on half the distros, with
# nothing able to report it. So pick the build that matches the library actually present.
for v in 41 40; do
  bin="/usr/lib/draco/draco-desktop-gtk$v"
  [ -x "$bin" ] || continue
  case "$v" in
    41) soname=libwebkit2gtk-4.1.so.0  ;;
    40) soname=libwebkit2gtk-4.0.so.37 ;;
  esac
  # ldconfig is authoritative and cheap; fall back to a direct probe if it is unavailable.
  if ldconfig -p 2>/dev/null | grep -q "$soname" || \
     [ -e "/usr/lib/$(uname -m)-linux-gnu/$soname" ]; then
    exec "$bin" "$@"
  fi
done
echo "draco-desktop: no usable WebKitGTK found (need libwebkit2gtk-4.1-0 or libwebkit2gtk-4.0-37)." >&2
echo "  Install one of them, e.g.:  sudo apt install libwebkit2gtk-4.1-0" >&2
exit 1
