#!/bin/bash
mode="dev"


if [[ $* =~ ^(prod)$ ]]; then 
	mode="prod"
fi

if [ $mode == "dev" ]; then
    echo "[Installing AURA ENGINE for Development]"
fi
if [ $mode == "prod" ]; then
    echo "[Installing AURA ENGINE for Production]"
fi


# Development and Production

echo "Installation OPAM Packages ..."
bash script/install-opam-packages.sh

echo "Installing Python Requirements ..."
python3.7 $(which pip3) install -r requirements.txt


# Development 

if [ $mode == "dev" ]; then

    echo "Create local 'logs' Folder ..."
    mkdir -p logs

    echo "Copy configuration to './configuration/engine.ini'"
    cp -n configuration/sample-development.engine.ini configuration/engine.ini

    echo "Installing Web Application Packages ..."
    bash script/install-web.sh
fi


# Production 

if [ $mode == "prod" ]; then

    echo "Create local 'tmp' Folder ..."
    mkdir -p tmp

    echo "Copy default Engine configuration to '/etc/aura/engine.ini'"
    cp -n configuration/sample-production.engine.ini /etc/aura/engine.ini

    echo "Copy default Gunicorn configuration to '/etc/aura/engine.ini'"
    cp -n configuration/sample.gunicorn.conf.py configuration/gunicorn.conf.py

    echo "Create Virtual Env for Gunicorn"
    virtualenv -p /usr/bin/python3.7 ../python-env
    source ../python-env/bin/activate

    echo "Install Requirements to Virtual Env"
    pip3 install -r requirements.txt
fi


echo 
echo "+++ Installation of AURA Engine finished! +++"
echo