#!/bin/sh
# Leave the dbmoe network for good: your workers come off the public list and your credential stops working.
# What you already contributed stays in the model, because it cannot be separated out.  You can rejoin at any time.
set -eu
BASE="https://codex.opentransformers.online/dbmoe"
if command -v sha256sum >/dev/null 2>&1; then H=$(printf %s "$BASE" | sha256sum | cut -c1-12); else H=$(printf %s "$BASE" | shasum -a 256 | cut -c1-12); fi
F="$HOME/.dbmoe/$H.token"
[ -s "$F" ] || { echo "No saved credential at $F. If you minted your own, use: python3 dbmoe.py leave --token @worker.token" >&2; exit 1; }
printf 'Authorization: Bearer %s\n' "$(cat "$F")" | curl -fsS -X POST -H @- -H 'Content-Type: application/json' -d '{}' "$BASE/leave"
rm -f "$F" "$HOME/.dbmoe/worker-name"
echo
echo "You have left. Any worker still running stops by itself. Your files in ~/dbmoe-worker are yours to delete."
