#!/usr/bin/env bash

set -e
set -o pipefail

check_installed() {
  if ! command -v $1 > /dev/null 2>&1; then
    printf "$1 must be installed before running this script!"
    exit 1
  fi
}

configure_pipeline() {
  local name=$1
  local pipeline=$2

  printf "configuring the $name pipeline...\n"

  fly -t ci set-pipeline \
    -p $name \
    -c $pipeline \
    -v cli-pools-github-private-key="$(lpass show Shared-CLI/Concourse/pr-builder-bosh-lite-bool-private-key --notes)" \
    -v github-access-token="$(lpass show Shared-CLI/Concourse/pr-builder-access-token --notes)"

}

check_installed lpass
check_installed fly

pipelines_path=$(cd $(dirname $0)/.. && pwd)

configure_pipeline cli-pr-builder $pipelines_path/cli-pr-builder/pipeline.yml


