#!/bin/bash

set -e

install_dir=$1
if [ -z "$install_dir" ]; then
  echo "usage: $0 INSTALL_DIR"
  exit 1
fi

if ! [[ "$install_dir" =~ ^/ ]]; then
  echo "$install_dir must be an absolute path"
  exit 1
fi

if [ ! -d "$install_dir/bin" ]; then
  mkdir -p "$install_dir/bin"
fi

helpers_dir="$(dirname "${BASH_SOURCE[0]}")"
cd $helpers_dir

os="$(uname -s | tr '[:upper:]' '[:lower:]')"
echo "building $install_dir/bin/helper"

GO111MODULE=on GOOS="$os" GOARCH=amd64 go build -o "$install_dir/bin/helper" .
