#!/usr/bin/env bash

git --version

# Store Key in temporary file and lock it down
KEY_FILE_GITLAB="99-gitlab.key"

echo "${GITLAB_RUNNER_GITLAB_SSH_KEY}" > ${KEY_FILE_GITLAB}
chmod 400 ${KEY_FILE_GITLAB}

# Clone Acquia CI-CD repo for deployment scripts
GIT_SSH_COMMAND="ssh -v -i ${KEY_FILE_GITLAB} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -F /dev/null" git clone --depth=1 --branch=master ${GITLAB_RUNNER_GITLAB_DEPLOY_GIT_REPO} acquia-deploy-scripts

# Empty and delete temporary key
chmod u+w ${KEY_FILE_GITLAB}
echo > ${KEY_FILE_GITLAB}
rm ${KEY_FILE_GITLAB}

# Remove git folder from deploy scripts
rm -rd acquia-deploy-scripts/.git

# Run scripts
cd acquia-deploy-scripts
. ./00-master-deploy-script.bash
