#!/bin/bash

. ./@Core/Scripts/templates.sh

echo "Create the .env file from the .env.example and use the gitlab variables to populate"
env
while read line;
do
  IFS='=' read -a variableArray <<< "$line"

  if [ "${variableArray[0]}" != '#' ]
  then
    if [ "${variableArray[0]}" != '' ]
    then
      if [ "${!variableArray[0]}" = '' ]
      then
        echo "############################################"
        echo "############################################"
        echo "############################################"
        echo " "
        echo "FAIL - ENVIRONMENT VARIABLE ISN'T IN GITLAB."
        echo "MISSING VARIABLE = ${variableArray[0]}"
        echo "FIX:: Add the environment variable to gitlab"
        echo " "
        echo "ALSO... Is your branch name correct??"
        echo " "
        echo "############################################"
        echo "############################################"
        echo "############################################"
        exit 1
      else
        echo "${variableArray[0]}=\"${!variableArray[0]}\"" >> .env
      fi
    fi
  fi
done <.env.example

echo "Environment .env file contents"
cat .env
