#!/bin/bash
export PYTHONPATH=$PYTHONPATH:$MIDASSYS/python

# go to dir of this file
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR

# check for --test flag, which additionally installs what's needed to run the test suite
install_test=false
for arg in "$@"; do
    if [ "$arg" == "--test" ]; then
        install_test=true
    fi
done

# create virtual env
if [ ! -d "./venv" ]; then
    echo "Creating python virtual environment" 
    python3 -m venv venv
fi

# start virtual env
source venv/bin/activate

# install dependencies
echo "Installing dependencies"
python3 -m ensurepip --upgrade
pip install -r requirements.txt

# install test dependencies and the browser playwright drives
if [ "$install_test" = true ]; then
    echo "Installing test dependencies"
    pip install -r tests/requirement_test.txt
    playwright install firefox
fi

# run setup
echo "Run setup"
python3 run_scheduler.py --setup

echo "Finished"
