#!/usr/bin/env bash

red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`

bash_realpath() {
  # print the resolved path
  # @params
  # 1: the path to resolve
  # @return
  # &1: the resolved link path

  local path="${1}"
  while [[ -L ${path} && "$(ls -l "${path}")" =~ -\>\ (.*) ]]
  do
    path="${BASH_REMATCH[1]}"
  done
  echo "${path}"
}

REALPATH="$(bash_realpath "${BASH_SOURCE[0]}")"
CURRENTDIR="$(cd "$(dirname "$REALPATH")" && pwd)"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
  $CURRENTDIR/mason-linux "$@"

elif [[ "$OSTYPE" == "darwin"* ]]; then
  $CURRENTDIR/mason-macos "$@"
else
  echo "${yellow}Cannot find a binary for your environment.${reset}"
  exit 1
fi
