#!/bin/bash -xe
export WEKA_VERSION="3.8.1"
export WEKA_GET_BASE_URL="https://get.weka.io"
export WEKA_DIST_SERVER="https://get.weka.io"
export WEKA_DIST_TOKEN="${dist_token}"
export WEKA_PKG_URL="https://get.weka.io/dist/v1/pkg/weka-3.8.1.tar"
export WEKA_THIS_INSTANCE="Backend${instance_index}"
export WEKA_CLUSTER_NAME="${cluster_name}"
export WEKA_INSTALLATION_ID="${weka_installation_id}"
export WEKA_INSTANCES_WAIT_TIME="43199"
export WEKA_LOG_GROUP_NAME="/wekaio/${log_group_name}"
export WEKA_AZ_COUNT="1"
export WEKA_PROTECTION="2"
export WEKA_AWS_DOWNLOAD_REGION="us-west-2"
export WEKA_HOST="${weka_host}"
mkdir -p /tmp/wekaio
CURL_RETRY=0
until curl -u $WEKA_DIST_TOKEN: --fail -v https://get.weka.io/dist/v1/aws/scripts/wekaio-instance-boot.sh > /tmp/wekaio/wekaio-instance-boot.sh || [ $CURL_RETRY -eq 15 ]
  do sleep $(( CURL_RETRY++ ))
done
chmod 755 /tmp/wekaio/wekaio-instance-boot.sh
/tmp/wekaio/wekaio-instance-boot.sh backend
