From e69d24e1b8937c7605a75b69b26eef841503ddc0 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 8 Oct 2026 10:58:59 -0600 Subject: [PATCH] fix: harden OmniRoute bootstrap cleanup --- infra/ai-stack/bootstrap-omniroute.sh | 43 ++++++++------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/infra/ai-stack/bootstrap-omniroute.sh b/infra/ai-stack/bootstrap-omniroute.sh index 324d567..00be7a0 100644 --- a/infra/ai-stack/bootstrap-omniroute.sh +++ b/infra/ai-stack/bootstrap-omniroute.sh @@ -9,6 +9,7 @@ PORT="${LAB_OMNIROUTE_PORT:-20128}" BASE_URL="${LAB_AI_STACK_OMNIROUTE_BASE_URL:-http://127.0.0.1:${PORT}}" OPENROUTER_URL="${LAB_AI_STACK_OPENROUTER_URL:-https://openrouter.ai/api/v1}" NVIDIA_URL="${LAB_AI_STACK_NVIDIA_URL:-https://integrate.api.nvidia.com/v1}" +OMNIROUTE_BOOTSTRAP_TMP_DIR="" if [[ ! -s "${ENV_FILE}" ]]; then echo "Missing ${ENV_FILE}; run seed-secrets.sh first." >&2 @@ -20,33 +21,14 @@ env_value() { awk -F= -v key="${key}" '$1 == key { sub(/^[^=]*=/, ""); print; found = 1 } END { exit found ? 0 : 1 }' "${ENV_FILE}" } -json_value() { - local expr="$1" - python3 - "${expr}" <<'PY' -import json -import sys - -expr = sys.argv[1] -try: - data = json.load(sys.stdin) -except Exception: - sys.exit(1) - -for key in expr.split("."): - if isinstance(data, dict): - data = data.get(key) - else: - data = None - if data is None: - sys.exit(1) - -if isinstance(data, (dict, list)): - print(json.dumps(data)) -else: - print(data) -PY +cleanup() { + if [[ -n "${OMNIROUTE_BOOTSTRAP_TMP_DIR}" && -d "${OMNIROUTE_BOOTSTRAP_TMP_DIR}" ]]; then + rm -rf "${OMNIROUTE_BOOTSTRAP_TMP_DIR}" + fi } +trap cleanup EXIT + wait_for_omniroute() { local status @@ -212,7 +194,7 @@ upsert_provider() { } main() { - local password openrouter_key nvidia_key tmp_dir cookie_jar headers_file body_file auth_header + local password openrouter_key nvidia_key cookie_jar headers_file body_file auth_header password="$(env_value INITIAL_PASSWORD)" openrouter_key="$(env_value OPENROUTER_API_KEY 2>/dev/null || true)" @@ -220,11 +202,10 @@ main() { wait_for_omniroute - tmp_dir="$(mktemp -d)" - trap 'rm -rf "${tmp_dir}"' EXIT - cookie_jar="${tmp_dir}/cookies.txt" - headers_file="${tmp_dir}/headers.txt" - body_file="${tmp_dir}/body.json" + OMNIROUTE_BOOTSTRAP_TMP_DIR="$(mktemp -d)" + cookie_jar="${OMNIROUTE_BOOTSTRAP_TMP_DIR}/cookies.txt" + headers_file="${OMNIROUTE_BOOTSTRAP_TMP_DIR}/headers.txt" + body_file="${OMNIROUTE_BOOTSTRAP_TMP_DIR}/body.json" login_omniroute "${password}" "${cookie_jar}" "${body_file}" "${headers_file}" auth_header="$(extract_auth_header "${body_file}")"