1# shellcheck shell=bash2# resolve-bin.sh — which product binary a wrapper runs, and whether it is3# new enough. Sourced (never executed) by compose.sh, unit.sh, e2e.sh,4# live.sh and export.sh; sets RC to the binary's path.5#6# Resolution order: $GRAPHOS_FACTORY_CORE_BIN, then the graphos-factory-core link7# bootstrap.sh installs beside the product binary in its cache8# ($GRAPHOS_FACTORY_CORE_CACHE/bin, default9# ~/.cache/graphos-factory-core/<owner>-<repo>/bin, see cache.sh), then10# graphos-factory-core on PATH. The first hit is used — and the cache wins over11# PATH, so a binary a long-ago bootstrap left there shadows a newer one on12# PATH. That is why the version is checked here and never assumed.13#14
44 echo "$_sf_layer: the product binary is not installed (no graphos-factory-core link in the cache or on PATH) — run your skill's scripts/bootstrap.sh" >&2
45 exit 127
46fi
47
48_sf_want="${GRAPHOS_FACTORY_CORE_VERSION:-}"
49_sf_pin_from=GRAPHOS_FACTORY_CORE_VERSION
50# Else cache.sh's pin: crate/Cargo.toml in a checkout, release.env in a copy.
55_sf_have="$("$RC" version 2>/dev/null | sed -n 's/^[a-z][a-z0-9-]* \([0-9][^ ]*\).*/\1/p' | head -1 || true)"
56
57_sf_refuse() {
58 echo "$_sf_layer: FAIL — $1" >&2
59 echo "$_sf_layer: rebuild the cache with scripts/bootstrap.sh --build (or bootstrap.sh to download), or point GRAPHOS_FACTORY_CORE_BIN at a current binary" >&2
60 exit 78
61}
62
63# 0 when version $1 is older than $2, 1 when not, 2 when either is unreadable.
64# Pre-release and build suffixes (-edge, +sha) are ignored.
71 case "$_sf_x$_sf_y" in *[!0-9]*) return 2 ;; esac
72 if [ "$((10#$_sf_x))" -lt "$((10#$_sf_y))" ]; then return 0; fi
73 if [ "$((10#$_sf_x))" -gt "$((10#$_sf_y))" ]; then return 1; fi
74 done
75 return 1
76}
77
78if [ -z "$_sf_have" ]; then
79 _sf_refuse "$RC (from $_sf_from) does not report a version (\`$RC version\` printed nothing usable)"
80fi
81if [ -z "$_sf_want" ]; then
82 echo "graphos-factory-core: $_sf_layer runs $RC (from $_sf_from), version $_sf_have — WARNING: no pin to check it against (no crate/Cargo.toml or release.env beside the scripts, GRAPHOS_FACTORY_CORE_VERSION unset)" >&2