#!/usr/bin/env bash

SW_DIR="${SW_DIR:-dependencies}"

if [ ! -d venv ]; then
  python3 -m venv venv
  source venv/bin/activate
  pip install -r requirements.txt
  pip install `python oscarlm/taskcluster.py --decoder --branch v0.7.0-alpha.2`
  printf "\n ****** Installed Python packages ****** \n\n\n\n"
fi

if [ ! -f "${SW_DIR}/kenlm/build/bin/lmplz" ]; then
  mkdir -p "${SW_DIR}/kenlm"
  pushd "${SW_DIR}"

  git clone https://github.com/kpu/kenlm.git
  pushd kenlm

  mkdir -p build
  pushd build
  cmake ..
  make -j 4
  popd

  popd

  popd
  printf "\n ****** Installed KenLM ****** \n\n\n\n"
fi

if [ ! -f "${SW_DIR}/deepspeech/libdeepspeech.so" ]; then
  source venv/bin/activate
  mkdir -p "${SW_DIR}/deepspeech"
  python oscarlm/taskcluster.py --target "${SW_DIR}/deepspeech" --branch v0.6.0
  printf "\n ****** Installed DeepSpeech tools ****** \n\n\n\n"
fi

if [[ ! -d models && ! -L models ]]; then
  mkdir models
fi
