<commit_before>#!/usr/bin/env bash

set -eu

MAX_ATTEMPTS=120
KEYCLOAK=""
ATTEMPTS=0

echo "Waiting for Keycloak ..."

while [[ -z "${KEYCLOAK}" && "${ATTEMPTS}" -lt "${MAX_ATTEMPTS}" ]]; do
    sleep 1
    KEYCLOAK=$( (curl -v "http://auth.lumen.local:8080/auth/realms/akvo/.well-known/openid-configuration" 2>&1 | grep "HTTP/1.1 200 OK") || echo "")
    let ATTEMPTS+=1
done

if [[ -z "${KEYCLOAK}" ]]; then
    echo "Keycloak is not available"
    exit 1
fi

echo "Keycloak is ready!"

echo "Waiting for PostgreSQL ..."

echo $JAVA_HOME
# In JRE container JAVA_HOME points to /jre
# In JDK container JAVA_HOME points to the parent of */jre
cacerts_file=""
# JDK-8189131 : Open-source the Oracle JDK Root Certificates
# https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8189131
if [ "${JAVA_HOME}" == "/docker-java-home" ]
then
    cacerts_file="${JAVA_HOME%jre}/jre/lib/security/cacerts"
else
    cacerts_file="${JAVA_HOME%jre}/lib/security/cacerts"
fi


ATTEMPTS=0
CERT_INSTALLED=$( (keytool -list -trustcacerts -keystore "${cacerts_file}" -storepass changeit | grep postgrescert) || echo "not found")

while [[ "${CERT_INSTALLED}" == "not found" && "${ATTEMPTS}" -lt "${MAX_ATTEMPTS}" ]]; do
    if [[ -f "${PGSSLROOTCERT}" ]]; then
	keytool -import -trustcacerts -keystore "${cacerts_file}" -storepass changeit -noprompt -alias postgrescert -file "${PGSSLROOTCERT}" || true
	CERT_INSTALLED=$( (keytool -list -trustcacerts -keystore "${cacerts_file}" -storepass changeit | grep postgrescert) || echo "not found")
    fi
    sleep 1
    let ATTEMPTS+=1
done

if [[ "${CERT_INSTALLED}" == "not found" ]]; then
    echo "PostgreSQL SSL certificate is not available"
    exit 1
fi

ATTEMPTS=0<commit_msg>[#2231] First try for CI and local dev cases<commit_after>#!/usr/bin/env bash

set -eu

MAX_ATTEMPTS=120
KEYCLOAK=""
ATTEMPTS=0

echo "Waiting for Keycloak ..."

while [[ -z "${KEYCLOAK}" && "${ATTEMPTS}" -lt "${MAX_ATTEMPTS}" ]]; do
    sleep 1
    KEYCLOAK=$( (curl -v "http://auth.lumen.local:8080/auth/realms/akvo/.well-known/openid-configuration" 2>&1 | grep "HTTP/1.1 200 OK") || echo "")
    let ATTEMPTS+=1
done

if [[ -z "${KEYCLOAK}" ]]; then
    echo "Keycloak is not available"
    exit 1
fi

echo "Keycloak is ready!"

echo "Waiting for PostgreSQL ..."

echo "@JAVA HOME"
echo $JAVA_HOME
# In JRE container JAVA_HOME points to /jre
# In JDK container JAVA_HOME points to the parent of */jre
cacerts_file=""
# JDK-8189131 : Open-source the Oracle JDK Root Certificates
# https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8189131
if [ "${JAVA_HOME}" == "/docker-java-home" ];
then
    cacerts_file="${JAVA_HOME%jre}/jre/lib/security/cacerts"
elif [ "${JAVA_HOME}" == "/usr/local/openjdk-8" ]; then
    cacerts_file="${JAVA_HOME}/jre/lib/security/cacerts"
else
    cacerts_file="${JAVA_HOME%jre}/jre/lib/security/cacerts"
fi

echo $cacerts_file

ATTEMPTS=0
CERT_INSTALLED=$( (keytool -list -trustcacerts -keystore "${cacerts_file}" -storepass changeit | grep postgrescert) || echo "not found")

while [[ "${CERT_INSTALLED}" == "not found" && "${ATTEMPTS}" -lt "${MAX_ATTEMPTS}" ]]; do
    if [[ -f "${PGSSLROOTCERT}" ]]; then
	keytool -import -trustcacerts -keystore "${cacerts_file}" -storepass changeit -noprompt -alias postgrescert -file "${PGSSLROOTCERT}" || true
	CERT_INSTALLED=$( (keytool -list -trustcacerts -keystore "${cacerts_file}" -storepass changeit | grep postgrescert) || echo "not found")
    fi
    sleep 1
    let ATTEMPTS+=1
done

if [[ "${CERT_INSTALLED}" == "not found" ]]; then
    echo "PostgreSQL SSL certificate is not available"
    exit 1
fi

ATTEMPTS=0
{'fraction_non_alphanumeric': 0.1631578947368421, 'fraction_numerical': 0.02188365650969529, 'mean_word_length': 4.225759768451519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4989045', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1374, 'n_words': 343}