#!/usr/bin/env bash
IFS=$'\n\t'
set -euo pipefail

#
# GovCMS prepare for deploy.
#
# This performs some perfunctory commands to ensure that the
# sites are in a deployable state.
#
# @deprecated 1.0
#
# This is used in the legacy projects that have not been updated with the latest
# scaffold.
#

echo "GovCMS Deploy :: Update site alias"

# When a new environment is created a new mount is provisioned. This
# overrides the standard files directory created by the base containers.
# Drupal doesn't create the directories and expects them to exist so
# that it can use them. This is a stopgap fix to ensure that the files
# directory is available for all containers.
mkdir -p /app/web/sites/default/files/private/{backups,tmp}

if [ ! -f /app/drush/sites/govcms.site.yml ]; then
  echo "[skip]: Site alias file does not exist."
  exit 0;
fi

sed -i "s/%%PROJECT_NAME%%/\${LAGOON_PROJECT}/g" /app/drush/sites/govcms.site.yml

echo "[success]: Completed successfully."
