#!/bin/bash

./stop_pyai_server.sh

/bin/rm -f /tmp/pyai_server_socket
/bin/rm -f nohup.out

source $HOME/fwww/venv_fwww/bin/activate

pip install --upgrade pyOpenSSL
pip install --upgrade cryptography

pip show sentence-transformers
if (($? == 0 )); then
    echo "Found sentence-transformers pip package, OK"
else
    echo "Install sentence-transformers ..."
    python3 -m pip install -U sentence-transformers
    if (( $? != 0 )); then
        pip install -U sentence-transformers
        if (( $? != 0 )); then
            echo "Error: unable to install sentence-transformers"
            echo "Please make sure your Python3 environment is setup correctly"
            echo "Check your PYTHONPATH environment variable"
            exit 1
        fi
    fi
fi


nohup python3 pyai_server.py > ../log_root/pyai_server.log 2>&1  &

