diff --git a/lib/scripts/aws/cloudfront_distribution/build.sh b/lib/scripts/aws/cloudfront_distribution/build.sh index 579ca065..f4813cd7 100755 --- a/lib/scripts/aws/cloudfront_distribution/build.sh +++ b/lib/scripts/aws/cloudfront_distribution/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [[ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]]; then +if [ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]; then echo "[ERROR] TERRAHUB_VAR_S3_BUCKET_NAME variable is empty. Aborting..." exit 1 fi @@ -9,15 +9,15 @@ fi _CWD="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" export TERRAHUB_BUILD_TEMP_VARS="/tmp/.env-$(date '+%Y%m%d%H%M%S%N%Z')" -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi touch ${TERRAHUB_BUILD_TEMP_VARS} # Re-source terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi # Invalidate CloudFront distribution @@ -25,6 +25,6 @@ echo "[EXEC] ${_CWD}/invalidate.sh ${TERRAHUB_VAR_S3_BUCKET_NAME}" ${_CWD}/invalidate.sh ${TERRAHUB_VAR_S3_BUCKET_NAME} # Cleanup terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi diff --git a/lib/scripts/aws/cloudfront_distribution/invalidate.sh b/lib/scripts/aws/cloudfront_distribution/invalidate.sh index e8d54b34..24b1521b 100755 --- a/lib/scripts/aws/cloudfront_distribution/invalidate.sh +++ b/lib/scripts/aws/cloudfront_distribution/invalidate.sh @@ -1,22 +1,22 @@ #!/bin/sh # Validate if terrahub build temporary file exists -if [[ -z "${TERRAHUB_BUILD_TEMP_VARS}" ]]; then +if [ -z "${TERRAHUB_BUILD_TEMP_VARS}" ]; then echo "[ERROR] TERRAHUB_BUILD_TEMP_VARS variable is empty. Aborting..." exit 1 fi # Re-source terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi # Source path -if [[ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]] && [[ ! -z "${1}" ]]; then +if [ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ] && [ ! -z "${1}" ]; then TERRAHUB_VAR_S3_BUCKET_NAME=${1} fi -if [[ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]]; then +if [ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]; then echo "[ERROR] TERRAHUB_VAR_S3_BUCKET_NAME variable is empty. Aborting..." exit 1 fi @@ -24,7 +24,7 @@ fi aws --version > /dev/null 2>&1 || { echo >&2 '[ERROR] awscli is missing. Aborting...'; exit 1; } _CF=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='${TERRAHUB_VAR_S3_BUCKET_NAME}' || AliasICPRecordals[0].CNAME=='${TERRAHUB_VAR_S3_BUCKET_NAME}'].Id" | jq ".[0]" || "null") -if [[ -z "${_CF}" ]] || [[ "${_CF}" == "null" ]]; then +if [ -z "${_CF}" ] || [ "${_CF}" == "null" ]; then echo "[ERROR] No CloudFront distributions were found. Aborting..." exit 0 fi diff --git a/lib/scripts/aws/lambda_function/build.sh b/lib/scripts/aws/lambda_function/build.sh index 892580ae..9a232447 100755 --- a/lib/scripts/aws/lambda_function/build.sh +++ b/lib/scripts/aws/lambda_function/build.sh @@ -1,41 +1,41 @@ #!/bin/sh -if [[ -z "${TERRAHUB_BUILD_COMPILE_FILE}" ]]; then +if [ -z "${TERRAHUB_BUILD_COMPILE_FILE}" ]; then echo "[ERROR] TERRAHUB_BUILD_COMPILE_FILE variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_LOCAL_PATH}" ]]; then +if [ -z "${TERRAHUB_BUILD_LOCAL_PATH}" ]; then echo "[ERROR] TERRAHUB_BUILD_LOCAL_PATH variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_S3_DEPLOY}" ]]; then +if [ -z "${TERRAHUB_BUILD_S3_DEPLOY}" ]; then echo "[ERROR] TERRAHUB_BUILD_S3_DEPLOY variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_S3_PATH}" ]]; then +if [ -z "${TERRAHUB_BUILD_S3_PATH}" ]; then echo "[ERROR] TERRAHUB_BUILD_S3_PATH variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_INDEX_FILE}" ]]; then +if [ -z "${TERRAHUB_BUILD_INDEX_FILE}" ]; then echo "[ERROR] TERRAHUB_BUILD_INDEX_FILE variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_LAMBDA_FILE}" ]]; then +if [ -z "${TERRAHUB_BUILD_LAMBDA_FILE}" ]; then echo "[ERROR] TERRAHUB_BUILD_LAMBDA_FILE variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_COMPONENT_HOME}" ]]; then +if [ -z "${TERRAHUB_COMPONENT_HOME}" ]; then echo "[ERROR] TERRAHUB_COMPONENT_HOME variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_OK}" ]]; then +if [ -z "${TERRAHUB_BUILD_OK}" ]; then export TERRAHUB_BUILD_OK="false" fi @@ -43,7 +43,7 @@ fi _CWD="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" export TERRAHUB_BUILD_TEMP_VARS="/tmp/.env-$(date '+%Y%m%d%H%M%S%N%Z')" -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi @@ -72,8 +72,8 @@ echo "[EXEC] ${_CWD}/shasum.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX ${_CWD}/shasum.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} # Re-source terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi # Upload index file to S3 storage @@ -85,10 +85,10 @@ echo "[EXEC] ${_CWD}/upload.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX ${_CWD}/upload.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} s3://${TERRAHUB_BUILD_S3_DEPLOY}/${TERRAHUB_BUILD_S3_PATH}/${TERRAHUB_BUILD_INDEX_FILE} # Cleanup terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi -if [[ -f ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} ]]; then +if [ -f "${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE}" ]; then rm -f ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} fi diff --git a/lib/scripts/aws/lambda_function/compare.sh b/lib/scripts/aws/lambda_function/compare.sh index 5bd9cc64..0e21699f 100755 --- a/lib/scripts/aws/lambda_function/compare.sh +++ b/lib/scripts/aws/lambda_function/compare.sh @@ -2,21 +2,21 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## Source files for build process _COMPARE="${@:2}" -if [[ -z "${_COMPARE}" ]]; then +if [ -z "${_COMPARE}" ]; then echo '[ERROR] _COMPARE variable is empty. Aborting...' exit 1 fi ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Handle case where OS has sha1sum command instead of shasum @@ -32,7 +32,7 @@ fi ## Compare SHA256 sums from _SRC file with files in _COMPARE echo "[INFO] TERRAHUB_BUILD_OK='${TERRAHUB_BUILD_OK}' ==> Comparing SHA256 sums." _EXCLUDE=" -path **/node_modules -o -path **/venv " -if [[ "$(uname)" == "Darwin" ]]; then +if [ "$(uname)" == "Darwin" ]; then _SHASUM_ID=$(find -s ${_COMPARE} \( ${_EXCLUDE} \) -prune -o -type f -exec ${_SHASUM_CLI} {} \; | sort -k 2 | ${_SHASUM_CLI} | cut -f 1 -d " ") else _SHASUM_ID=$(find ${_COMPARE} \( ${_EXCLUDE} \) -prune -o -type f -exec ${_SHASUM_CLI} {} \; | sort -k 2 | ${_SHASUM_CLI} | cut -f 1 -d " ") @@ -41,7 +41,7 @@ fi ## Checking if needs to skip SHA256 sums compare echo "export TERRAHUB_SHA=\"${_SHASUM_ID}\"" >> ${TERRAHUB_BUILD_TEMP_VARS} echo "[INFO] Current SHA256 => ${_SHASUM_ID}" -if [[ "${TERRAHUB_BUILD_OK}" == "true" ]]; then +if [ "${TERRAHUB_BUILD_OK}" == "true" ]; then echo "[INFO] TERRAHUB_BUILD_OK='${TERRAHUB_BUILD_OK}' ==> Skipping comparing SHA256 sums." exit 0 fi @@ -49,7 +49,7 @@ fi ## Checking if the project requires to be built _SHASUM_CHK=$(head -n 1 ${_SRC}) echo "[INFO] S3 Object SHA256 => ${_SHASUM_CHK}" -if [[ "${_SHASUM_ID}" == "${_SHASUM_CHK}" ]]; then +if [ "${_SHASUM_ID}" == "${_SHASUM_CHK}" ]; then echo '[INFO] Build is NOT required.' exit 0 fi diff --git a/lib/scripts/aws/lambda_function/compile.sh b/lib/scripts/aws/lambda_function/compile.sh index bf80d6ba..8ffbb729 100755 --- a/lib/scripts/aws/lambda_function/compile.sh +++ b/lib/scripts/aws/lambda_function/compile.sh @@ -9,7 +9,7 @@ fi ## Setup environmental variables if [ -f ${TERRAHUB_BUILD_TEMP_VARS} ]; then - source ${TERRAHUB_BUILD_TEMP_VARS} + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true diff --git a/lib/scripts/aws/lambda_function/download.sh b/lib/scripts/aws/lambda_function/download.sh index 73c28a37..a58db6ce 100755 --- a/lib/scripts/aws/lambda_function/download.sh +++ b/lib/scripts/aws/lambda_function/download.sh @@ -2,14 +2,14 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## S3 bucket name _S3=${2-${TERRAHUB_BUILD_S3_DEPLOY}} -if [[ -z "${_S3}" ]]; then +if [ -z "${_S3}" ]; then echo >&2 '[ERROR] _S3 variable is empty. Aborting...' exit 1 fi @@ -18,14 +18,14 @@ fi _OPTIONS="${@:3}" ## Clean environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if _S3 file exists in S3 aws --version > /dev/null 2>&1 || { echo >&2 'awscli is missing. Aborting...'; exit 1; } _COMPARE=$(aws s3 ls ${_S3} ${_OPTIONS} || echo "") -if [[ -z "${_COMPARE}" ]]; then +if [ -z "${_COMPARE}" ]; then echo "[INFO] ${_S3} does NOT exist ==> First execution." echo 'export TERRAHUB_BUILD_OK="true"' >> ${TERRAHUB_BUILD_TEMP_VARS} exit 0 diff --git a/lib/scripts/aws/lambda_function/shasum.sh b/lib/scripts/aws/lambda_function/shasum.sh index 95b8cb08..d21779cf 100755 --- a/lib/scripts/aws/lambda_function/shasum.sh +++ b/lib/scripts/aws/lambda_function/shasum.sh @@ -2,24 +2,24 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true -if [[ "$TERRAHUB_BUILD_OK" != "true" ]]; then +if [ "$TERRAHUB_BUILD_OK" != "true" ]; then echo '[INFO] Build was NOT executed ==> SHA256 will NOT be updated.' exit 0 fi ## Checking if SHA256 sums exists -if [[ -z "${TERRAHUB_SHA}" ]]; then +if [ -z "${TERRAHUB_SHA}" ]; then echo >&2 '[ERROR] TERRAHUB_SHA variable is empty. Aborting...' exit 1 fi diff --git a/lib/scripts/aws/lambda_function/upload.sh b/lib/scripts/aws/lambda_function/upload.sh index 5bac3d21..746f85bd 100755 --- a/lib/scripts/aws/lambda_function/upload.sh +++ b/lib/scripts/aws/lambda_function/upload.sh @@ -2,14 +2,14 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## S3 bucket name _S3=${2-${TERRAHUB_BUILD_S3_DEPLOY}} -if [[ -z "${_S3}" ]]; then +if [ -z "${_S3}" ]; then echo >&2 '[ERROR] _S3 variable is empty. Aborting...' exit 1 fi @@ -18,8 +18,8 @@ fi _OPTIONS="${@:3}" ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true @@ -31,9 +31,9 @@ fi ## Sync _SRC to _S3 aws --version > /dev/null 2>&1 || { echo >&2 'awscli is missing. Aborting...'; exit 1; } -if [[ -d "${_SRC}" ]]; then +if [ -d "${_SRC}" ]; then aws s3 sync ${_SRC} ${_S3} ${_OPTIONS} -elif [[ -f "${_SRC}" ]]; then +elif [ -f "${_SRC}" ]; then aws s3 cp ${_SRC} ${_S3} ${_OPTIONS} else echo >&2 "[ERROR] ${_SRC} is not valid" diff --git a/lib/scripts/aws/lambda_function/zip.sh b/lib/scripts/aws/lambda_function/zip.sh index 0abfd51a..9eeefce7 100755 --- a/lib/scripts/aws/lambda_function/zip.sh +++ b/lib/scripts/aws/lambda_function/zip.sh @@ -2,38 +2,38 @@ ## zip option _OPTION=${1} -if [[ "${_OPTION}" != "-r" ]] && [[ "${_OPTION}" != "-j" ]]; then +if [ "${_OPTION}" != "-r" ] && [ "${_OPTION}" != "-j" ]; then echo >&2 '[ERROR] _OPTION variable must be "-r" or "-j". Aborting...' exit 1 fi ## zip file _FILE=${2} -if [[ -z "${_FILE}" ]]; then +if [ -z "${_FILE}" ]; then echo >&2 '[ERROR] _FILE variable is empty. Aborting...' exit 1 fi ## Source files or folders for zip process _PATH="${@:3}" -if [[ -z "${_PATH}" ]]; then +if [ -z "${_PATH}" ]; then echo >&2 '[ERROR] _PATH variable is empty. Aborting...' exit 1 fi ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true -if [[ "${TERRAHUB_BUILD_OK}" != "true" ]]; then +if [ "${TERRAHUB_BUILD_OK}" != "true" ]; then echo '[INFO] Build was NOT executed ==> zip file was NOT created.' exit 0 fi ## Check if zip file exists and remove it -if [[ -f "${_FILE}" ]]; then +if [ -f "${_FILE}" ]; then echo "[INFO] Removing existing ${_FILE}" rm -f "${_FILE}" fi diff --git a/lib/scripts/aws/s3_bucket/build.sh b/lib/scripts/aws/s3_bucket/build.sh index 320837d2..e785c4eb 100755 --- a/lib/scripts/aws/s3_bucket/build.sh +++ b/lib/scripts/aws/s3_bucket/build.sh @@ -1,46 +1,46 @@ #!/bin/sh -if [[ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]]; then +if [ -z "${TERRAHUB_VAR_S3_BUCKET_NAME}" ]; then echo "[ERROR] TERRAHUB_VAR_S3_BUCKET_NAME variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_COMPILE_FILE}" ]]; then +if [ -z "${TERRAHUB_BUILD_COMPILE_FILE}" ]; then echo "[ERROR] TERRAHUB_BUILD_COMPILE_FILE variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_LOCAL_PATH}" ]]; then +if [ -z "${TERRAHUB_BUILD_LOCAL_PATH}" ]; then echo "[ERROR] TERRAHUB_BUILD_LOCAL_PATH variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_SOURCE_PATH}" ]]; then +if [ -z "${TERRAHUB_BUILD_SOURCE_PATH}" ]; then echo "[ERROR] TERRAHUB_BUILD_SOURCE_PATH variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_S3_DEPLOY}" ]]; then +if [ -z "${TERRAHUB_BUILD_S3_DEPLOY}" ]; then echo "[ERROR] TERRAHUB_BUILD_S3_DEPLOY variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_S3_PATH}" ]]; then +if [ -z "${TERRAHUB_BUILD_S3_PATH}" ]; then echo "[ERROR] TERRAHUB_BUILD_S3_PATH variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_INDEX_FILE}" ]]; then +if [ -z "${TERRAHUB_BUILD_INDEX_FILE}" ]; then echo "[ERROR] TERRAHUB_BUILD_INDEX_FILE variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_COMPONENT_HOME}" ]]; then +if [ -z "${TERRAHUB_COMPONENT_HOME}" ]; then echo "[ERROR] TERRAHUB_COMPONENT_HOME variable is empty. Aborting..." exit 1 fi -if [[ -z "${TERRAHUB_BUILD_OK}" ]]; then +if [ -z "${TERRAHUB_BUILD_OK}" ]; then export TERRAHUB_BUILD_OK="false" fi @@ -48,7 +48,7 @@ fi _CWD="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" export TERRAHUB_BUILD_TEMP_VARS="/tmp/.env-$(date '+%Y%m%d%H%M%S%N%Z')" -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi @@ -59,7 +59,7 @@ echo "[EXEC] ${_CWD}/download.sh ${TERRAHUB_COMPONENT_HOME} s3://${TERRAHUB_BUIL ${_CWD}/download.sh ${TERRAHUB_COMPONENT_HOME} s3://${TERRAHUB_BUILD_S3_DEPLOY}/${TERRAHUB_BUILD_S3_PATH}/ # Move .env file to path in project root -if [[ ! -z "${TERRAHUB_BUILD_DOTENV_FILE}" ]] && [[ -f "${TERRAHUB_BUILD_DOTENV_FILE}" ]]; then +if [ ! -z "${TERRAHUB_BUILD_DOTENV_FILE}" ] && [ -f "${TERRAHUB_BUILD_DOTENV_FILE}" ]; then echo "[EXEC] mv -f ${TERRAHUB_BUILD_DOTENV_FILE} ${TERRAHUB_BUILD_LOCAL_PATH}/" mv -f ${TERRAHUB_BUILD_DOTENV_FILE} ${TERRAHUB_BUILD_LOCAL_PATH}/ fi @@ -77,8 +77,8 @@ echo "[EXEC] ${_CWD}/shasum.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX ${_CWD}/shasum.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} # Re-source terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi # Upload index file to S3 storage @@ -86,15 +86,15 @@ echo "[EXEC] ${_CWD}/upload.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX ${_CWD}/upload.sh ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} s3://${TERRAHUB_BUILD_S3_DEPLOY}/${TERRAHUB_BUILD_S3_PATH}/ # Upload local build to S3 runtime -if [[ -z "${TERRAHUB_VAR_S3_BUCKET_MAX_AGE}" ]]; then TERRAHUB_VAR_S3_BUCKET_MAX_AGE="0"; fi +if [ -z "${TERRAHUB_VAR_S3_BUCKET_MAX_AGE}" ]; then TERRAHUB_VAR_S3_BUCKET_MAX_AGE="0"; fi echo "[EXEC] ${_CWD}/upload.sh ${TERRAHUB_BUILD_LOCAL_PATH}/build s3://${TERRAHUB_VAR_S3_BUCKET_NAME}/ --cache-control max-age=${TERRAHUB_VAR_S3_BUCKET_MAX_AGE}" ${_CWD}/upload.sh ${TERRAHUB_BUILD_LOCAL_PATH}/build s3://${TERRAHUB_VAR_S3_BUCKET_NAME}/ --cache-control max-age=${TERRAHUB_VAR_S3_BUCKET_MAX_AGE} # Cleanup terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then rm -f ${TERRAHUB_BUILD_TEMP_VARS} fi -if [[ -f ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} ]]; then +if [ -f "${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE}" ]; then rm -f ${TERRAHUB_COMPONENT_HOME}/${TERRAHUB_BUILD_INDEX_FILE} fi diff --git a/lib/scripts/aws/s3_bucket/compare.sh b/lib/scripts/aws/s3_bucket/compare.sh index 5bd9cc64..0e21699f 100755 --- a/lib/scripts/aws/s3_bucket/compare.sh +++ b/lib/scripts/aws/s3_bucket/compare.sh @@ -2,21 +2,21 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## Source files for build process _COMPARE="${@:2}" -if [[ -z "${_COMPARE}" ]]; then +if [ -z "${_COMPARE}" ]; then echo '[ERROR] _COMPARE variable is empty. Aborting...' exit 1 fi ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Handle case where OS has sha1sum command instead of shasum @@ -32,7 +32,7 @@ fi ## Compare SHA256 sums from _SRC file with files in _COMPARE echo "[INFO] TERRAHUB_BUILD_OK='${TERRAHUB_BUILD_OK}' ==> Comparing SHA256 sums." _EXCLUDE=" -path **/node_modules -o -path **/venv " -if [[ "$(uname)" == "Darwin" ]]; then +if [ "$(uname)" == "Darwin" ]; then _SHASUM_ID=$(find -s ${_COMPARE} \( ${_EXCLUDE} \) -prune -o -type f -exec ${_SHASUM_CLI} {} \; | sort -k 2 | ${_SHASUM_CLI} | cut -f 1 -d " ") else _SHASUM_ID=$(find ${_COMPARE} \( ${_EXCLUDE} \) -prune -o -type f -exec ${_SHASUM_CLI} {} \; | sort -k 2 | ${_SHASUM_CLI} | cut -f 1 -d " ") @@ -41,7 +41,7 @@ fi ## Checking if needs to skip SHA256 sums compare echo "export TERRAHUB_SHA=\"${_SHASUM_ID}\"" >> ${TERRAHUB_BUILD_TEMP_VARS} echo "[INFO] Current SHA256 => ${_SHASUM_ID}" -if [[ "${TERRAHUB_BUILD_OK}" == "true" ]]; then +if [ "${TERRAHUB_BUILD_OK}" == "true" ]; then echo "[INFO] TERRAHUB_BUILD_OK='${TERRAHUB_BUILD_OK}' ==> Skipping comparing SHA256 sums." exit 0 fi @@ -49,7 +49,7 @@ fi ## Checking if the project requires to be built _SHASUM_CHK=$(head -n 1 ${_SRC}) echo "[INFO] S3 Object SHA256 => ${_SHASUM_CHK}" -if [[ "${_SHASUM_ID}" == "${_SHASUM_CHK}" ]]; then +if [ "${_SHASUM_ID}" == "${_SHASUM_CHK}" ]; then echo '[INFO] Build is NOT required.' exit 0 fi diff --git a/lib/scripts/aws/s3_bucket/compile.sh b/lib/scripts/aws/s3_bucket/compile.sh index 7a71d90f..7d5eb884 100755 --- a/lib/scripts/aws/s3_bucket/compile.sh +++ b/lib/scripts/aws/s3_bucket/compile.sh @@ -2,24 +2,24 @@ # Source path _SRC=${@:1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo "[ERROR] _SRC variable is empty. Aborting..." exit 1 fi # Validate if terrahub build temporary file exists -if [[ -z "${TERRAHUB_BUILD_TEMP_VARS}" ]]; then +if [ -z "${TERRAHUB_BUILD_TEMP_VARS}" ]; then echo "[ERROR] TERRAHUB_BUILD_TEMP_VARS variable is empty. Aborting..." exit 1 fi # Re-source terrahub build temporary file -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi # Checking if TERRAHUB_BUILD_OK is true -if [[ "${TERRAHUB_BUILD_OK}" != "true" ]]; then +if [ "${TERRAHUB_BUILD_OK}" != "true" ]; then echo "[INFO] Build was NOT executed ==> zip file was NOT created." exit 0 fi diff --git a/lib/scripts/aws/s3_bucket/download.sh b/lib/scripts/aws/s3_bucket/download.sh index 73c28a37..a58db6ce 100755 --- a/lib/scripts/aws/s3_bucket/download.sh +++ b/lib/scripts/aws/s3_bucket/download.sh @@ -2,14 +2,14 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## S3 bucket name _S3=${2-${TERRAHUB_BUILD_S3_DEPLOY}} -if [[ -z "${_S3}" ]]; then +if [ -z "${_S3}" ]; then echo >&2 '[ERROR] _S3 variable is empty. Aborting...' exit 1 fi @@ -18,14 +18,14 @@ fi _OPTIONS="${@:3}" ## Clean environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if _S3 file exists in S3 aws --version > /dev/null 2>&1 || { echo >&2 'awscli is missing. Aborting...'; exit 1; } _COMPARE=$(aws s3 ls ${_S3} ${_OPTIONS} || echo "") -if [[ -z "${_COMPARE}" ]]; then +if [ -z "${_COMPARE}" ]; then echo "[INFO] ${_S3} does NOT exist ==> First execution." echo 'export TERRAHUB_BUILD_OK="true"' >> ${TERRAHUB_BUILD_TEMP_VARS} exit 0 diff --git a/lib/scripts/aws/s3_bucket/shasum.sh b/lib/scripts/aws/s3_bucket/shasum.sh index 95b8cb08..d21779cf 100755 --- a/lib/scripts/aws/s3_bucket/shasum.sh +++ b/lib/scripts/aws/s3_bucket/shasum.sh @@ -2,24 +2,24 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true -if [[ "$TERRAHUB_BUILD_OK" != "true" ]]; then +if [ "$TERRAHUB_BUILD_OK" != "true" ]; then echo '[INFO] Build was NOT executed ==> SHA256 will NOT be updated.' exit 0 fi ## Checking if SHA256 sums exists -if [[ -z "${TERRAHUB_SHA}" ]]; then +if [ -z "${TERRAHUB_SHA}" ]; then echo >&2 '[ERROR] TERRAHUB_SHA variable is empty. Aborting...' exit 1 fi diff --git a/lib/scripts/aws/s3_bucket/upload.sh b/lib/scripts/aws/s3_bucket/upload.sh index 5bac3d21..746f85bd 100755 --- a/lib/scripts/aws/s3_bucket/upload.sh +++ b/lib/scripts/aws/s3_bucket/upload.sh @@ -2,14 +2,14 @@ ## Source path _SRC=${1} -if [[ -z "${_SRC}" ]]; then +if [ -z "${_SRC}" ]; then echo >&2 '[ERROR] _SRC variable is empty. Aborting...' exit 1 fi ## S3 bucket name _S3=${2-${TERRAHUB_BUILD_S3_DEPLOY}} -if [[ -z "${_S3}" ]]; then +if [ -z "${_S3}" ]; then echo >&2 '[ERROR] _S3 variable is empty. Aborting...' exit 1 fi @@ -18,8 +18,8 @@ fi _OPTIONS="${@:3}" ## Setup environmental variables -if [[ -f ${TERRAHUB_BUILD_TEMP_VARS} ]]; then - source ${TERRAHUB_BUILD_TEMP_VARS} +if [ -f "${TERRAHUB_BUILD_TEMP_VARS}" ]; then + . ${TERRAHUB_BUILD_TEMP_VARS} fi ## Checking if TERRAHUB_BUILD_OK is true @@ -31,9 +31,9 @@ fi ## Sync _SRC to _S3 aws --version > /dev/null 2>&1 || { echo >&2 'awscli is missing. Aborting...'; exit 1; } -if [[ -d "${_SRC}" ]]; then +if [ -d "${_SRC}" ]; then aws s3 sync ${_SRC} ${_S3} ${_OPTIONS} -elif [[ -f "${_SRC}" ]]; then +elif [ -f "${_SRC}" ]; then aws s3 cp ${_SRC} ${_S3} ${_OPTIONS} else echo >&2 "[ERROR] ${_SRC} is not valid"