#!/bin/bash
# shellcheck disable=SC2090,SC2086,SC2089,SC1091
PROJECT_PATH="$HOME/projects/repo"

# Parse command-line options
if ! OPTIONS=$(getopt -o p: --long project_path: -n 'parse-options' -- "$@"); then
	echo "launch_tensorboard_s3.sh: Error parsing options" >&2
	exit 1
fi

eval set -- "$OPTIONS"

while true; do
	case "$1" in
	-p | --project_path)
		PROJECT_PATH="$2"
		shift 2
		;;
	--)
		shift
		break
		;;
	*)
		break
		;;
	esac
done

#! Check if at least one arguments are passed
if [[ $# -lt 1 ]]; then
	echo "launch_tensorboard_s3.sh: Illegal number of parameters."
	echo "Usage: launch_tensorboard_s3.sh <root_path>"
	exit 1
fi
echo "PROJECT_PATH=$PROJECT_PATH"
#! Moving to the project folder
cd "$PROJECT_PATH" || exit
# GIT_LFS_SKIP_SMUDGE is necessary to avoid downloading large files
GIT_LFS_SKIP_SMUDGE=true uv sync -q
# shellcheck disable=SC1091
. "$VIRTUAL_ENV"/bin/activate

#! Launch tensorboard
uv run tensorboard --load_fast true --logdir "$PROJECT_PATH"/tensorboard_logs_copy

#! ssh -L <local_port>:<forward_to_host>:<port_on_forward_to_host> -N <username>@<node_name>.anonymous.
#! ssh -L 6006:localhost:6006 -N anonymous
