fix: harden OmniRoute bootstrap cleanup
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-08 10:58:59 -06:00
parent fe6a5bf141
commit e69d24e1b8
1 changed files with 12 additions and 31 deletions

View File

@ -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}")"