#!/bin/sh

set -x
set -e

if ! brew -v &> /dev/null
then
  echo "WARNING: Cannot find brew. Skipping brewfile installation."
  export KERL_CONFIGURE_OPTIONS="--disable-hipe"
else
  brew bundle
  export KERL_CONFIGURE_OPTIONS="--disable-hipe --with-ssl=$(brew --prefix openssl)"
fi

if ! asdf -v &> /dev/null
then
  echo "WARNING: No asdf. Skipping erlang, elixir, node installation."
else
  export CFLAGS="-O2 -g -fno-stack-check"

  asdf plugin-add elixir || true
  asdf plugin-add erlang || true
  asdf plugin-add nodejs || true

  ${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring

  asdf install
fi

mix local.hex --force 
