#!/bin/sh
which uv >/dev/null 2>&1 || exit
PYTHON_VER=3.13
VENV=venv-linux-$PYTHON_VER
OPTIONS="--listen"
OPTIONS="$OPTIONS --lowvram"
#OPTIONS="$OPTIONS --cpu"
OPTIONS="$OPTIONS --use-sage-attention"
while :; do
	git pull --rebase
	if [ -d $VENV ]; then
		uv venv $VENV -p $PYTHON_VER --allow-existing
	else
		uv venv $VENV -p $PYTHON_VER
	fi
	. $VENV/bin/activate
	uv pip install pip
	pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu130
	# pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu130
	pip install -r requirements.txt
	pip install sageattention
	find custom_nodes -mindepth 1 -maxdepth 1 -type d|while read n; do
		if [ -d $n ]; then
			echo $n
			cd $n
			[ -d .git ] && git pull --rebase
			[ -r requirements.txt ] && pip install -r requirements.txt
			cd -
		fi
	done
	python main.py $OPTIONS
done
