#!/usr/bin/env bash

echo "Starting local setup"

if [ -x "$(command -v elixir)" ]
then
    echo "SUCCESS: Elixir is installed!"
else
    echo "WARNING: Elixir is not installed!"
    echo "Please install Elixir: https://elixir-lang.org/install.html"
fi

if [ -x "$(command -v node)" ]
then
    echo "SUCCESS: Node.js is installed"
else
    echo "WARNING: Node.js not installed!"
    echo "Please install Node.js: https://nodejs.org"
fi

if [ -x "$(command -v pip3)" ]
then
    echo "SUCCESS: Python and Pip are installed"
else
    echo "WARNING: Python and/or Pip are not installed!"
    echo "Please install Python via your package manager or from source"
fi

if [ -x "$(command -v ffmpeg)" ]
then
    echo "SUCCESS: ffmpeg is installed"
else
    echo "WARNING: ffmpeg is not installed!"
    echo "Please install ffmpeg via your package manager or from source"
fi

if [ -x "$(command -v espeak)" ]
then
    echo "SUCCESS: espeak is installed"
else
    echo "WARNING: espeak is not installed!"
    echo "Please install espeak via your package manager or from source"
fi

if [ -x "$(command -v pg_dump)" ]
then
    echo "SUCCESS: PostgreSQL is installed"
else
    echo "WARNING: PostgreSQL is not installed!"
    echo "Please install PostgreSQL via your package manager or from source"
fi

echo "Installing aeneas..."
pip3 install --user numpy
pip3 install --user aeneas

echo "Running aeneas self-diagnostics..."
python3 -m aeneas.diagnostics

echo "Installing packages"
npm i
mix deps.get

echo "Copying configuration example file..."
cp config/dev.example.exs config/dev.exs

echo ""
echo "All done! Be sure to fill out the config/dev.exs file and create the database:"
echo "mix ecto.setup"

echo ""
echo "You can then use the following scripts to run Tometo:"
echo "script/run_f - Run only the frontend"
echo "script/run_b - Run only the backend"
echo "script/run - Run both frontend and backend, and watch and rebuild on changes"
