#!/usr/bin/env sh set -eu cd "$(dirname "$0")" PHILL_OLLAMA_HOST="${PHILL_OLLAMA_HOST:-http://127.0.0.1:11435}" echo "[PhillSwarm] Using OLLAMA_HOST=$PHILL_OLLAMA_HOST" export OLLAMA_HOST="$PHILL_OLLAMA_HOST" if command -v python3 >/dev/null 2>&1; then PYTHON_BIN="python3" elif command -v python >/dev/null 2>&1; then PYTHON_BIN="python" else echo "[PhillSwarm] ERROR: python3 or python is required." >&2 exit 1 fi if ! "$PYTHON_BIN" - <<'PY' >/dev/null 2>&1 import urllib.request urllib.request.urlopen("http://127.0.0.1:11435/api/tags", timeout=2).read() PY then echo "[PhillSwarm] Starting bridge..." nohup "$PYTHON_BIN" launch_ollama_bridge.py --model . --port 11435 > state/ollama_bridge_live.out.log 2> state/ollama_bridge_live.err.log & fi echo "[PhillSwarm] Waiting for bridge..." i=0 while [ "$i" -lt 30 ]; do if "$PYTHON_BIN" - <<'PY' >/dev/null 2>&1 import urllib.request urllib.request.urlopen("http://127.0.0.1:11435/api/tags", timeout=2).read() PY then break fi i=$((i + 1)) sleep 1 done if [ "$i" -ge 30 ]; then echo "[PhillSwarm] ERROR: bridge did not become ready at $PHILL_OLLAMA_HOST" >&2 exit 1 fi echo "[PhillSwarm] Bridge ready." echo "[PhillSwarm] Testing Ollama CLI..." ollama list SHELL_RC="" case "${SHELL:-}" in */zsh) SHELL_RC="$HOME/.zshrc" ;; */bash) SHELL_RC="$HOME/.bashrc" ;; esac if [ -n "$SHELL_RC" ]; then LINE="export OLLAMA_HOST=$PHILL_OLLAMA_HOST" if [ -f "$SHELL_RC" ]; then if ! grep -F "$LINE" "$SHELL_RC" >/dev/null 2>&1; then printf '\n# PhillSwarm full-runtime Ollama bridge\n%s\n' "$LINE" >> "$SHELL_RC" echo "[PhillSwarm] Added OLLAMA_HOST to $SHELL_RC" fi else printf '# PhillSwarm full-runtime Ollama bridge\n%s\n' "$LINE" > "$SHELL_RC" echo "[PhillSwarm] Created $SHELL_RC with OLLAMA_HOST" fi fi echo "" echo "[PhillSwarm] Setup complete. Open a new terminal, then use:" echo " ollama run phillswarm-4b:full" echo "" echo "[PhillSwarm] In this terminal you can use it now:" echo " OLLAMA_HOST=$PHILL_OLLAMA_HOST ollama run phillswarm-4b:full \"What is 2+2?\""