2021-05-21 15:27:21 +03:00
#!/bin/bash
2022-04-11 23:31:06 +03:00
set -o errexit
set -o pipefail
set -o nounset
# Uncomment this line to see each command for debugging (careful: this will show secrets!)
# set -o xtrace
2021-05-21 15:27:21 +03:00
2022-07-14 17:27:07 +03:00
# Get the directory that this script is in
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " >/dev/null 2>& 1 && pwd ) "
2021-05-21 15:27:21 +03:00
echo -e "\n\e[34m╔══════════════════════════════════════╗"
echo -e "║ \e[33mAzure TRE Makefile\e[34m ║"
echo -e "╚══════════════════════════════════════╝"
echo -e "\n\e[34m»»» ✅ \e[96mChecking pre-reqs\e[0m..."
2021-06-15 11:05:47 +03:00
echo -e "\n\e[96mChecking for Azure CLI\e[0m..."
2022-04-11 23:31:06 +03:00
if ! command -v az & > /dev/null; then
2022-03-03 08:38:34 +03:00
echo -e "\e[31m»»» ⚠️ Azure CLI is not installed! 😥 Please go to http://aka.ms/cli to set it up or rebuild your devcontainer"
2022-02-23 17:08:06 +03:00
exit 1
2021-05-21 15:27:21 +03:00
fi
2022-01-21 00:35:24 +03:00
2022-07-14 17:27:07 +03:00
if [ [ " ${ 1 :- ? } " = = *"env" * ] ] ; then
if [ -z " ${ USE_ENV_VARS_NOT_FILES :- } " ] ; then
# We only do this for local builds
echo -e "\n\e[96mLoading local environment variables\e[0m..."
2022-12-12 15:09:03 +03:00
if [ ! -f "config.yaml" ] ; then
echo -e "\e[31m»»» ⚠️ Your config.yaml file has not been setup! 😥 Please create a config.yaml file."
2022-07-14 17:27:07 +03:00
exit 1
fi
# shellcheck disable=SC1091
2022-12-12 15:09:03 +03:00
. " $DIR /load_and_validate_env.sh "
2022-07-14 17:27:07 +03:00
fi
fi
2022-04-11 23:31:06 +03:00
if [ [ " ${ 1 :- ? } " != *"nodocker" * ] ] ; then
2021-06-15 11:05:47 +03:00
echo -e "\n\e[96mChecking for Docker\e[0m..."
2022-04-11 23:31:06 +03:00
if ! command -v docker & > /dev/null; then
2022-03-03 08:38:34 +03:00
echo -e "\e[31m»»» ⚠️ Docker is not installed! 😥 Please go to https://docs.docker.com/engine/install/ to set it up or rebuild your devcontainer"
2022-02-23 17:08:06 +03:00
exit 1
2021-06-15 11:05:47 +03:00
fi
2021-05-21 15:27:21 +03:00
fi
2022-04-11 23:31:06 +03:00
if [ [ " ${ 1 :- ? } " = = *"certbot" * ] ] ; then
2021-06-15 11:05:47 +03:00
echo -e "\n\e[96mChecking for Certbot\e[0m..."
2022-04-11 23:31:06 +03:00
if ! /opt/certbot/bin/certbot --version > /dev/null 2>& 1; then
2022-03-03 08:38:34 +03:00
echo -e "\e[31m»»» ⚠️ Certbot is not installed! 😥 Please go to https://certbot.eff.org/lets-encrypt/pip-other to set it up or rebuild your devcontainer"
2022-02-23 17:08:06 +03:00
exit 1
2021-06-15 11:05:47 +03:00
fi
2021-06-02 15:29:13 +03:00
fi
2021-05-21 15:27:21 +03:00
2022-04-11 23:31:06 +03:00
if [ [ " ${ 1 :- ? } " = = *"porter" * ] ] ; then
2021-06-15 11:05:47 +03:00
echo -e "\n\e[96mChecking for porter\e[0m..."
2022-04-11 23:31:06 +03:00
if ! command -v porter & > /dev/null; then
2022-03-03 08:38:34 +03:00
echo -e "\e[31m»»» ⚠️ Porter is not installed! 😥 Please go to https://porter.sh/install/ to set it up or rebuild your devcontainer"
2022-02-23 17:08:06 +03:00
exit 1
2021-06-15 11:05:47 +03:00
fi
2021-06-04 15:22:09 +03:00
fi
2022-01-21 19:37:11 +03:00
# This is called if we are in a CI system and we will login
# with a Service Principal.
2022-07-14 17:27:07 +03:00
if [ -n " ${ TF_IN_AUTOMATION :- } " ] ; then
2023-03-27 11:08:02 +03:00
az cloud set --name " $AZURE_ENVIRONMENT "
2022-01-21 19:37:11 +03:00
az login --service-principal -u " $ARM_CLIENT_ID " -p " $ARM_CLIENT_SECRET " --tenant " $ARM_TENANT_ID "
az account set -s " $ARM_SUBSCRIPTION_ID "
fi
2022-04-11 23:31:06 +03:00
SUB_NAME = $( az account show --query name -o tsv)
SUB_ID = $( az account show --query id -o tsv)
export SUB_ID
TENANT_ID = $( az account show --query tenantId -o tsv)
export TENANT_ID
2024-11-11 12:38:28 +03:00
# Configure AzureRM provider and backend to use Azure AD to connect to storage accounts
export ARM_STORAGE_USE_AZUREAD = true
export ARM_USE_AZUREAD = true
export ARM_USE_OIDC = true
2021-05-26 19:58:43 +03:00
if [ -z " $SUB_NAME " ] ; then
2021-05-21 15:27:21 +03:00
echo -e "\n\e[31m»»» ⚠️ You are not logged in to Azure!"
2022-02-23 17:08:06 +03:00
exit 1
2021-05-21 15:27:21 +03:00
fi
echo -e "\e[34m»»» 🔨 \e[96mAzure details from logged on user \e[0m"
echo -e " \e[34m»»» • \e[96mSubscription: \e[33m $SUB_NAME \e[0m "
2022-01-21 00:35:24 +03:00
echo -e " \e[34m»»» • \e[96mTenant: \e[33m $TENANT_ID \e[0m\n "
2022-04-11 23:31:06 +03:00
# This shouldn't be here but since other scripts don't use this option we must reset it.
# For tracking: https://github.com/microsoft/AzureTRE/issues/1672
set +o nounset