#!/bin/sh
PYTHON=python3
VENV=venv-linux
OPTIONS="--enable-manager"
OPTIONS="$OPTIONS --preview-method auto"
OPTIONS="$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
	. $VENV/bin/activate
	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 -r manager_requirements.txt
	pip install matrix-nio
	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
