#!/usr/bin/env bash
set -euo pipefail
# ===== Auto-generated by scripts/gen-pack-installers.mjs — do not edit =====
# Pack: Qwen-Image (20B T2I + WAN combo)  (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_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 "comfyui-vrgamedevgirl" "https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
clone "RES4LYF" "https://github.com/ClownsharkBatwing/RES4LYF"

echo "-------- models --------"
grab "models/text_encoders/Qwen2.5-VL-7B-Instruct-UD-Q4_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Qwen2.5-VL-7B-Instruct-UD-Q4_K_S.gguf"
grab "models/text_encoders/umt5-xxl-encoder-Q5_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/umt5-xxl-encoder-Q5_K_S.gguf"
grab "models/vae/qwen_image_vae.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/qwen_image_vae.safetensors"
grab "models/vae/wan_2.1_vae.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/wan_2.1_vae.safetensors"
grab "models/unet/Qwen_Image_Distill-Q4_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Qwen_Image_Distill-Q4_K_S.gguf"
grab "models/unet/Wan2.2-T2V-A14B-LowNoise-Q4_K_S.gguf" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Wan2.2-T2V-A14B-LowNoise-Q4_K_S.gguf"
grab "models/loras/Qwen-Image-Lightning-8steps-V1.0.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Qwen-Image-Lightning-8steps-V1.0.safetensors"
grab "models/loras/Qwen-Image-Lightning-4steps-V1.0.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Qwen-Image-Lightning-4steps-V1.0.safetensors"
grab "models/loras/Wan2.1_T2V_14B_FusionX_LoRA.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Wan2.1_T2V_14B_FusionX_LoRA.safetensors"
grab "models/loras/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors"
grab "models/upscale_models/4x-ClearRealityV1.pth" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/4x-ClearRealityV1.pth"
grab "models/upscale_models/RealESRGAN_x4plus_anime_6B.pth" "https://huggingface.co/Aitrepreneur/FLX/resolve/main/RealESRGAN_x4plus_anime_6B.pth"

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