#!/bin/sh
TARGET="$HOME/AI"

if ! which uv >/dev/null 2>&1; then
	curl -LsSf https://astral.sh/uv/install.sh | sh
	echo "Installed... uv! Restart script!" >&2
	exit 1
fi

if ! which git >/dev/null 2>&1; then
	echo "git must be available!" >&2
	exit 2
fi

if ! [ -d "$TARGET" ]; then
	git clone https://github.com/Comfy-Org/ComfyUI.git "$TARGET/ComfyUI"
	cd "$TARGET/ComfyUI/custom_nodes"
	#git clone https://github.com/ltdrdata/ComfyUI-Manager.git
	#git clone https://github.com/rgthree/rgthree-comfy.git
	git clone https://github.com/city96/ComfyUI-GGUF.git
	git clone https://github.com/liusida/ComfyUI-Login.git
fi

if [ -d "$TARGET/ComfyUI/models/" ]; then
	cd "$TARGET/ComfyUI/models"
	if ! [ -f checkpoints/v1-5-pruned-emaonly-fp16.safetensors ]; then
		curl --output-dir checkpoints -JLOR https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors
	fi
	if ! [ -f diffusion_models/flux-2-klein-4b-fp8.safetensors ]; then
		curl --output-dir diffusion_models -JLOR https://huggingface.co/black-forest-labs/FLUX.2-klein-4b-fp8/resolve/main/flux-2-klein-4b-fp8.safetensors
	fi
	if ! [ -f text_encoders/qwen_3_4b.safetensors ]; then
		curl --output-dir text_encoders -JLOR https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/text_encoders/qwen_3_4b.safetensors
	fi
	if ! [ -f vae/flux2-vae.safetensors ]; then
		curl --output-dir vae -JLOR https://huggingface.co/Comfy-Org/flux2-dev/resolve/main/split_files/vae/flux2-vae.safetensors
	fi
else
	echo "Error: No model directory!" >&2
	exit 3
fi
#tput bel
