#!/usr/bin/env bash set -euo pipefail ROOT_OVERRIDE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" export ROOT_OVERRIDE # shellcheck disable=SC1091 source "${ROOT_OVERRIDE}/scripts/common.sh" init_log bootstrap-native acquire_lock jr-sql-ai-native-model.lock print_header "bootstrap-native: START" need_cmd curl need_cmd python load_env need_cmd "$OLLAMA_BIN" check_for_legacy_docker_ollama [[ -n "$BASE_MODEL" ]] || fail "BASE_MODEL is empty" 50 log "bootstrap-native: ensuring local Ollama runtime is ready at ${OLLAMA_URL}" ensure_ollama_ready "$OLLAMA_API_MAX_WAIT" "$OLLAMA_API_START_WAIT" || fail "Ollama API not reachable at ${OLLAMA_URL}" 51 ok "bootstrap-native: Ollama API reachable" if fetch_version >/dev/null 2>&1; then ok "bootstrap-native: Ollama version endpoint reachable" fi pull_configured_models tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT render_modelfile "$tmp" log "bootstrap-native: building expert model ${EXPERT_MODEL}" ollama_cmd create "${EXPERT_MODEL}" -f "$tmp" verify_models_available ok "bootstrap-native: base and expert models are available" warmup_sqlai print_footer "bootstrap-native: END status=OK log=${LOG_FILE}"