Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bglopez/15015c5024b0b131c41285732bfd65bf to your computer and use it in GitHub Desktop.

Select an option

Save bglopez/15015c5024b0b131c41285732bfd65bf to your computer and use it in GitHub Desktop.
bash devops snippets
for line in $(cat docker-compose-integration-tests.yml | tr ' ' '\n' | sort -u | grep -Po '\${.+}' )
do
var="${line/\$/""}"
var="${var/\{/""}"
var="${var/\}/""}"
var=$(echo "$var" | cut -d ":" -f 1 | xargs)
if [[ -z "${!var}" ]]; then
echo "Enter $var value:" && read _value
export $var=$_value
echo "$var=$_value" >>.env
fi
done
function download_env_variables {
echo_log ""
echo_log "##### Starting to download environment variables #####"
http_response=$(curl -s -o env_variables -w "%{http_code}" --user ${USER}:${PASSWORD} ${VARIABLES_MANAGER_SERVICE_URL})
echo_log "## status: $http_response ##"
if [ $http_response == "200" ]; then
cp env_variables /env/
echo_log "## Exporting Environment Variables ##"
source /env/env_variables
else
echo_log "## New Environment Variables could not be obtained ##"
if [ -e /env/env_variables ]; then
echo_log "## Exporting old env variables ##"
source /env/env_variables
else
echo_log "## Environment file not found in : /env/env_variables ##"
exit 1
fi
fi
}
function export_java_env {
java_environments=""
echo_log "## Exporting Java Environment Variables ##"
while IFS='=' read -r name value ; do
if [[ $name == *'JAVA_'* ]] && [[ $name != "JAVA_HOME" ]] && [[ $name != "JAVA_VERSION" ]]; then
java_environments="$java_environments ${!name} ";
fi
done < <(env)
export CATALINA_OPTS="$java_environments"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment