#!/bin/sh
PYTHON=$HOME/dist/bin/python3
[ -x $PYTHON ] || PYTHON=python3
VENV=venv-linux
OPTIONS="--listen"
#OPTIONS="$OPTIONS --lowvram"
OPTIONS="$OPTIONS --cpu"
while :; do
	git pull --rebase
	if [ -d $VENV ]; then
		eval $PYTHON -m venv --upgrade $VENV
	else
		eval $PYTHON -m venv $VENV
	fi
	eval . $VENV/bin/activate
	# pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126
	# pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu126
 	pip install -r requirements.txt
	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
