#!/bin/bash
# This script runs the same sequence as the CircleCI build

if [ $(uname) == "Darwin" ]; then
  if which brew >/dev/null; then
    echo "Brew is already installed"
  else
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  fi
fi

# install nodejs
if which node >/dev/null; then
  echo "Nodejs is already installed"
else
  if [ $(uname) == "Darwin" ]; then
    brew install node
  else
    curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    sudo apt-get install -y nodejs
  fi
fi

# install python
if which python3 >/dev/null; then
  echo "Python3 is already installed"
else
  if [ $(uname) == "Darwin" ]; then
    brew install python3
  else
    sudo apt-get -y install python3-dev python3-pip python3-setuptools build-essential
  fi
fi

# install pip modules
if python3 -m pip show spacy socketIO-client-nexus >/dev/null; then
  echo "Pip modules already installed"
else
  python3 -m pip install -U socketIO-client-nexus
  python3 -m pip install -U spacy
fi

if python3 -m spacy info | grep en_core_web_md >/dev/null; then
  echo "spaCy model already installed"
else  
  python3 -m spacy download en_core_web_md
fi

# install npm modules
if [ -d ./node_modules ]; then
  echo "Npm modules already installed"
else
  npm install
fi
