#!/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 image-to-video  (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 --------"

echo "-------- pip (manifest extras) --------"
"$PY" -m pip install "imageio-ffmpeg"

echo "-------- models --------"
grab "models/checkpoints/ltx-2.3-22b-dev.safetensors" "https://huggingface.co/Lightricks/LTX-2.3/resolve/main/ltx-2.3-22b-dev.safetensors"
grab "models/text_encoders/gemma_3_12B_it_fp8_scaled.safetensors" "https://huggingface.co/Comfy-Org/ltx-2/resolve/main/split_files/text_encoders/gemma_3_12B_it_fp8_scaled.safetensors"
grab "models/loras/ltx_2.3_22b_distilled_1.1_lora_dynamic_fro09_avg_rank_111_bf16.safetensors" "https://huggingface.co/Comfy-Org/ltx-2.3/resolve/main/split_files/loras/ltx_2.3_22b_distilled_1.1_lora_dynamic_fro09_avg_rank_111_bf16.safetensors"
grab "models/loras/gemma-3-12b-it-abliterated_lora_rank64_bf16.safetensors" "https://huggingface.co/Comfy-Org/ltx-2/resolve/main/split_files/loras/gemma-3-12b-it-abliterated_lora_rank64_bf16.safetensors"
grab "models/latent_upscale_models/ltx-2.3-spatial-upscaler-x2-1.1.safetensors" "https://huggingface.co/Lightricks/LTX-2.3/resolve/main/ltx-2.3-spatial-upscaler-x2-1.1.safetensors"

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