#!/usr/bin/env bash

set -e

source /etc/profile.d/chruby.sh
chruby 2.1.7

# input
input_dir=$(realpath director-state/)
bosh_cli=$(realpath bosh-cli/bosh-cli-*)
chmod +x $bosh_cli

if [ ! -e "${input_dir}/director-state.json" ]; then
  echo "director-state.json does not exist, skipping..."
  exit 0
fi

if [ -d "${input_dir}/.bosh" ]; then
  # reuse compiled packages
  cp -r ${input_dir}/.bosh $HOME/
fi

pushd ${input_dir} > /dev/null
  echo "cleaning up bosh BOSH Director..."
  $bosh_cli -n clean-up --all
  echo "deleting existing BOSH Director VM..."
  $bosh_cli -n delete-env --vars-store "${input_dir}/creds.yml" -v director_name=bosh director.yml
popd

#!/usr/bin/env bash

set -e

source /etc/profile.d/chruby.sh
chruby 2.1.7

# input
input_dir=$(realpath director-state/)
bosh_cli=$(realpath bosh-cli/bosh-cli-*)
chmod +x $bosh_cli

if [ ! -e "${input_dir}/director-state.json" ]; then
  echo "director-state.json does not exist, skipping..."
  exit 0
fi

if [ -d "${input_dir}/.bosh" ]; then
  # reuse compiled packages
  cp -r ${input_dir}/.bosh $HOME/
fi

pushd ${input_dir} > /dev/null
  source director.env
  : ${BOSH_ENVIRONMENT:?}
  : ${BOSH_CLIENT:?}
  : ${BOSH_CLIENT_SECRET:?}
  export BOSH_CA_CERT="${input_dir}/ca_cert.pem"

  echo "cleaning up bosh BOSH Director..."
  $bosh_cli -n clean-up --all
  echo "deleting existing BOSH Director VM..."
  $bosh_cli -n delete-env --vars-store "${input_dir}/creds.yml" -v director_name=bosh director.yml
popd

Set a bosh-environment before cleaning up
Set a bosh-environment before cleaning up

[#145308231](https://www.pivotaltracker.com/story/show/145308231)

Signed-off-by: Chris Dutra <7eb54fc324f04033595eb420f2ee7c112fb7259e@pivotal.io>
