#!/bin/sh
# Fake Grok CLI shared by two servers. `update` replaces its own file the way an npm global
# reinstall does: the path is missing for a few seconds, then comes back at a newer version.
SELF="$0"
LOG="$(dirname "$SELF")/../calls.log"
echo "$(date +%T.%N) pid=$$ $*" >> "$LOG"
case "$1" in
  --version) echo "grok 0.1.0"; exit 0 ;;
  update)
    cp "$SELF" "$SELF.new"
    sed -i 's/grok 0.1.0/grok 99.0.0/' "$SELF.new"
    rm -f "$SELF"
    sleep 4
    mv "$SELF.new" "$SELF"
    chmod +x "$SELF"
    echo "updated"; exit 0 ;;
  models) echo "You are not logged in"; exit 0 ;;
  *) exit 1 ;;
esac
