#!/bin/bash -e

VERSION='v2.4.0'
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
DOWNLOAD_TYPE="${OS}-${ARCH}"
if [[ "${ARCH}" = "aarch64" ]]; then
  DOWNLOAD_TYPE="${OS}-arm64"
fi
if [[ "${ARCH}" = "x86_64" ]]; then
  DOWNLOAD_TYPE="${OS}-amd64"
fi

CACHE_DIR="./tmp/cache/${ARCH}-${OS}/"
echo "[download toxiproxy for $DOWNLOAD_TYPE into ${CACHE_DIR}]"
mkdir -p "${CACHE_DIR}"
curl --silent -L "https://github.com/Shopify/toxiproxy/releases/download/${VERSION}/toxiproxy-server-${DOWNLOAD_TYPE}" -o "${CACHE_DIR}/toxiproxy-server"
chmod +x "${CACHE_DIR}/toxiproxy-server"
