#!/usr/bin/env bash
set -euo pipefail
# ===== Auto-generated by scripts/gen-pack-installers.mjs — do not edit =====
# Pack: Ideogram 4 (Ideogram Ultra)  (Linux / RunPod)
# Run from your ComfyUI root (the folder containing custom_nodes/ and models/).
[ -d custom_nodes ] || { echo "[ERROR] run from your ComfyUI root (custom_nodes/ not found)"; exit 1; }
# Resolve the ComfyUI python: its venv first, then portable embed, then \$PYTHON/python3.
# Installing requirements into the wrong interpreter is why nodes silently fail to load.
if [ -n "${PYTHON:-}" ]; then PY="$PYTHON";
elif [ -x ".venv/bin/python" ]; then PY=".venv/bin/python";
elif [ -x "venv/bin/python" ]; then PY="venv/bin/python";
elif [ -x "../python_embeded/python" ]; then PY="../python_embeded/python";
else PY="python3"; fi
echo "using python: $PY"

clone() { # folder url
  if [ ! -d "custom_nodes/$1" ]; then
    echo "  cloning $1"; git clone --depth 1 "$2" "custom_nodes/$1"
    if [ -f "custom_nodes/$1/requirements.txt" ]; then echo "  installing $1 requirements.txt"; "$PY" -m pip install -r "custom_nodes/$1/requirements.txt"; fi
  else echo "  $1 present - skip"; fi
}
grab() { # relpath url
  mkdir -p "$(dirname "$1")"
  if [ ! -f "$1" ]; then echo "  downloading $(basename "$1")"; curl -L -o "$1" "$2"; else echo "  $(basename "$1") present - skip"; fi
}

echo "-------- custom nodes --------"
clone "rgthree-comfy" "https://github.com/rgthree/rgthree-comfy"
clone "ComfyUI-KJNodes" "https://github.com/kijai/ComfyUI-KJNodes"
clone "ComfyUI_essentials" "https://github.com/cubiq/ComfyUI_essentials"

echo "-------- models --------"
grab "models/diffusion_models/ideogram4_fp8_scaled.safetensors" "https://huggingface.co/Comfy-Org/Ideogram-4/resolve/main/diffusion_models/ideogram4_fp8_scaled.safetensors?download=true"
grab "models/diffusion_models/ideogram4_unconditional_fp8_scaled.safetensors" "https://huggingface.co/Comfy-Org/Ideogram-4/resolve/main/diffusion_models/ideogram4_unconditional_fp8_scaled.safetensors?download=true"
grab "models/text_encoders/gemma4_e4b_it_fp8_scaled.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/gemma4_e4b_it_fp8_scaled.safetensors?download=true"
grab "models/text_encoders/qwen3vl_8b_fp8_scaled.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/qwen3vl_8b_fp8_scaled.safetensors?download=true"
grab "models/vae/flux2-vae.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/flux2-vae.safetensors?download=true"

echo "DONE. Restart ComfyUI, then load workflow.json."
