#!/usr/bin/env bash
set -euo pipefail
# ===== Auto-generated by scripts/gen-pack-installers.mjs — do not edit =====
# Pack: LTX-2.3 — LTX-2.3 LoRA XY-plot grid  (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 "ComfyUI-GGUF" "https://github.com/city96/ComfyUI-GGUF"
clone "rgthree-comfy" "https://github.com/rgthree/rgthree-comfy"
clone "ComfyUI-Easy-Use" "https://github.com/yolain/ComfyUI-Easy-Use"
clone "ComfyUI-KJNodes" "https://github.com/kijai/ComfyUI-KJNodes"
clone "RES4LYF" "https://github.com/ClownsharkBatwing/RES4LYF"
clone "ComfyUI-LTXVideo" "https://github.com/Lightricks/ComfyUI-LTXVideo"
clone "ComfyUI-Custom-Scripts" "https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
clone "ComfyUI-VideoHelperSuite" "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"
clone "ComfyUI-WanVideoWrapper" "https://github.com/kijai/ComfyUI-WanVideoWrapper"
clone "ComfyUI-Impact-Pack" "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
clone "Comfyui_TTP_Toolset" "https://github.com/TTPlanetPig/Comfyui_TTP_Toolset"
clone "ComfyMath" "https://github.com/evanspearman/ComfyMath"
clone "WhatDreamsCost-ComfyUI" "https://github.com/WhatDreamsCost/WhatDreamsCost-ComfyUI"

echo "-------- models --------"
grab "models/text_encoders/ltx-2.3_text_projection_bf16.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3_text_projection_bf16.safetensors?download=true"
grab "models/text_encoders/gemma_3_12B_it_fp4_mixed.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/gemma_3_12B_it_fp4_mixed.safetensors?download=true"
grab "models/vae/LTX23_audio_vae_bf16.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/LTX23_audio_vae_bf16.safetensors?download=true"
grab "models/vae/LTX23_video_vae_bf16.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/LTX23_video_vae_bf16.safetensors?download=true"
grab "models/unet/ltx-2.3-22b-dev-Q4_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3-22b-dev-Q4_K_S.gguf?download=true"
grab "models/unet/ltx-2.3-22b-dev-Q5_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3-22b-dev-Q5_K_S.gguf?download=true"
grab "models/unet/ltx-2.3-22b-dev-Q8_0.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3-22b-dev-Q8_0.gguf?download=true"
grab "models/latent_upscale_models/ltx-2.3-spatial-upscaler-x2-1.1.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3-spatial-upscaler-x2-1.1.safetensors?download=true"
grab "models/loras/ltx-2.3-22b-distilled-lora-384-1.1.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2.3-22b-distilled-lora-384-1.1.safetensors?download=true"
grab "models/loras/ltx-2-19b-ic-lora-detailer.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ltx-2-19b-ic-lora-detailer.safetensors?download=true"

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