#! /usr/bin/env bash
#
# Install system packages required to build and test atd (Ubuntu)
#
# This is used by the Dockerfile and by the CI build.
#
set -eu

sudo apt-get update

# Add repo to install a sufficiently-recent version of node (for atdts tests)
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

# This includes compilers and libraries to support the various target
# languages of atd.
#
sudo apt-get install -y \
  default-jdk \
  nodejs \
  python3 \
  python3-pip \
  python-is-python3 \
  scala

# For JSON Schema and atdpy testing
pip install jsonschema pytest mypy flake8

# To get latest ldc version
source $(curl https://dlang.org/install.sh | bash -s ldc -a)
echo "source $(~/dlang/install.sh ldc -a)" >> "$BASH_ENV"

###### Sanity checks ######

echo 'check opam'
opam --version

echo 'check ocamlopt'
opam exec -- ocamlopt -version

echo 'check javac'
javac --version

echo 'check scalac'
scalac -version

echo 'check python3'
python3 --version

echo 'check jsonschema'
python3 -m jsonschema --version

echo 'check pytest'
python3 -m pytest --version

echo 'check mypy'
python3 -m mypy --version

echo 'check Node.js'
node --version

echo 'check npm'
npm --version

echo 'check ldc2 (dlang)'
ldc2 --version
