#!/bin/sh
# The iamar world host's command (docs/WORLD_HOST.md "Commands"): ./iamar-world-host <install|login|add|remove|check|start|stop|status> ...
# Runs on the Node in ./node (setup.sh --fetch) or an installed Node of the pinned major (setup.sh).
here=$(cd "$(dirname "$0")" && pwd)
if [ -x "$here/node/bin/node" ]; then exec "$here/node/bin/node" "$here/app/host/world_host/cli.js" "$@"; fi
major=$(awk '$1=="version"{split($2,v,".");print v[1]}' "$here/NODE_PIN")
if command -v node >/dev/null 2>&1; then
  have=$(node --version 2>/dev/null | sed 's/^v//')
  [ "${have%%.*}" = "$major" ] && exec node "$here/app/host/world_host/cli.js" "$@"
fi
echo "iamar-world-host: no Node $major found: run $here/setup.sh first" >&2
exit 3
