#!/bin/bash
set -euo pipefail

# Required env vars
# CONCOURSE_URL
# CONCOURSE_ATC_USER
# CONCOURSE_ATC_PASSWORD
# FLY_CMD
# FLY_TARGET

FLY_CMD_URL="${CONCOURSE_URL}/api/v1/cli?arch=amd64&platform=$(uname | tr '[:upper:]' '[:lower:]')"
echo "Downloading fly command..."
curl "$FLY_CMD_URL" -# -L -f -z "$FLY_CMD" -o "$FLY_CMD" -u "${CONCOURSE_ATC_USER}:${CONCOURSE_ATC_PASSWORD}"
chmod +x "$FLY_CMD"

echo "Doing fly login"
$FLY_CMD -t "${FLY_TARGET}" login --concourse-url "${CONCOURSE_URL}" -u "${CONCOURSE_ATC_USER}" -p "${CONCOURSE_ATC_PASSWORD}"

echo "Doing fly sync"
$FLY_CMD -t "${FLY_TARGET}" sync

#!/bin/bash
set -euo pipefail

# Required env vars
# CONCOURSE_URL
# CONCOURSE_ATC_USER
# CONCOURSE_ATC_PASSWORD
# FLY_CMD
# FLY_TARGET

fetch_fly() {
  echo "Downloading fly .."
  FLY_CMD_URL="${CONCOURSE_URL}/api/v1/cli?arch=amd64&platform=$(uname | tr '[:upper:]' '[:lower:]')"
  curl \
    --progress-bar \
    --location \
    --fail \
    --output "$FLY_CMD" \
    "$FLY_CMD_URL"
  chmod +x "$FLY_CMD"
}

fly_sync() {
  echo "Doing fly sync .."
  $FLY_CMD -t "${FLY_TARGET}" sync
}

fly_login() {
  echo "Doing fly login .."
  $FLY_CMD -t "${FLY_TARGET}" login --concourse-url "${CONCOURSE_URL}" -u "${CONCOURSE_ATC_USER}" -p "${CONCOURSE_ATC_PASSWORD}"
}

fly_is_runnable() {
  [ -x "${FLY_CMD}" ]
}

if fly_is_runnable; then
  if fly_login; then
    fly_sync
  else
    fetch_fly
    fly_login
  fi
else
  fetch_fly
  fly_login
fi

Make fly-sync wrapper able to upgrade v3 -> v4
Make fly-sync wrapper able to upgrade v3 -> v4

Our fly-sync wrapper isn't able to upgrade from Concourse v3 to v4. This
problem was solved originally in alphagov/paas-release-ci#79 [1], and
this commit (and the next one) propagate the results of that merge into
this repo.

[1] https://github.com/alphagov/paas-release-ci/pull/79
