#!/bin/bash

set -e

if [ -n "$DEBUG" ];then
    set -x
    PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # print line number and function name
fi

if [ -z "$(which shasum)" ]; then
    echo "Checksum utility 'shasum' not found."
    exit 1
fi

. script/bootstrap

mkdir -p bin
bindir="$PWD"/bin
scriptdir="$PWD"/script

# We have a few binaries that we want to build, so let's put them into bin/

version="3.2.6-16"
describe="f722ac55db00d140b6db6512ebcc872183fab173"

export GOPATH="$PWD/.gopath"
cd .gopath/src/github.com/openark/orchestrator

# We put the binaries directly into the bindir, because we have no need for shim wrappers
go build -o "$bindir/orchestrator" -ldflags "-X main.AppVersion=${version} -X main.GitCommit=${describe}" ./go/cmd/orchestrator/main.go

chmod -R +w "${GOPATH}"

rsync -qa ./resources $bindir/
