#!/usr/bin/env bash
# —————————————————————————————————————————————————————————————————————————————————————
# NOTE: These setup scripts rely on an open source BASH framework BashMatic.
#       https://github.com/kigster/bashmatic
#
# The framework is pretty light-weight, and is installed in your $HOME/.bashmatic folder.
# You can safely remove that folder after the setup if you wish, although re-running the
# setup will re-install it.
# —————————————————————————————————————————————————————————————————————————————————————

set -e
source "bin/deps"

setup.linux.bazel() {
  run "sudo apt update -y || true"
  run "sudo apt-get install -y libreadline-dev zlib1g-dev"
  run "sudo curl -L -o /usr/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.0/bazelisk-linux-amd64"
  run "sudo chmod +x /usr/bin/bazel"
}

setup.linux() {
  [[ -n $(command -v rvm) ]] && {
    run "rvm implode --force"
    [[ -d ${HOME}/.rvm ]] && run "rm -rf ${HOME}/.rvm"
  }

  run.set-all abort-on-error
  setup.linux.bazel
}
