#!/usr/bin/env bash
set -euo pipefail
# ===== Auto-generated by scripts/gen-pack-installers.mjs — do not edit =====
# Pack: Z-Image Turbo XY-Plot (LoRA comparison)  (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 "ComfyUI_tinyterraNodes" "https://github.com/TinyTerra/ComfyUI_tinyterraNodes"
clone "ComfyUI_UltimateSDUpscale" "https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
clone "ComfyUI_essentials" "https://github.com/cubiq/ComfyUI_essentials"
clone "wlsh_nodes" "https://github.com/wallish77/wlsh_nodes"
clone "RES4LYF" "https://github.com/ClownsharkBatwing/RES4LYF"

echo "-------- models --------"
grab "models/text_encoders/Qwen3-4B-UD-Q6_K_XL.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Qwen3-4B-UD-Q6_K_XL.gguf"
grab "models/vae/z-image-ae.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/ae.safetensors"
grab "models/unet/z_image_turbo-Q8_0.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/z_image_turbo-Q8_0.gguf"

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