#!/usr/bin/env bash

set -e
set -x

COMMAND_LOG="$(bazel info command_log)"
bazel build \
  //src/main/scala/net/eagle0/eagle:eagle_server_deploy.jar
STATUS="$?"

if [ $STATUS -eq 0 ]
then
  echo "Build succeeded!" > command_log.txt
else
  echo "Build failed. Copying command log from ${COMMAND_LOG}"
  cp "${COMMAND_LOG}" command_log.txt
  exit $STATUS
fi

echo "Removing old server files..."
/bin/rm -rf ./deploy
/bin/mkdir -p ./deploy

echo "Copying eagle jar..."
/bin/cp -R ./bazel-bin/src/main/scala/net/eagle0/eagle/eagle_server_deploy.jar ./deploy/

echo "build_servers_eagle completed"
