<commit_before>#!/bin/bash

 #*****************************************************************************
 #*                                                                           *
 #* Copyright FUJITSU LIMITED 2020                                            *
 #*                                                                           *
 #* Creation Date: 16-07-2020                                                 *
 #*                                                                           *
 #*****************************************************************************

# Variables for this script
COMPOSE_CONFIG_PATH=/opt
TARGET_PATH=/target
LOCKFILE=${TARGET_PATH}/oscm-deployer.lock

# If ${TARGET_PATH}/var.env does not exist, just copy the template for the operator and exit
if [ ! -f ${TARGET_PATH}/var.env ] || [ ! -f ${TARGET_PATH}/.env ]; then
	if [ -z ${HOST_FQDN} ]; then 
		echo "Please specify your host name with -e HOST_FQDN=..., where OSCM shall be accessible."
	else	
		envsubst '$HOST_FQDN' < /opt/env.template  > ${TARGET_PATH}/.env
		if [ "${SAMPLE_DATA}" == "true" ]; then
		    cp /opt/var.env.template ${TARGET_PATH}/var.env
		     
		else    
		    cp /opt/var.env.withoutSampleData.template ${TARGET_PATH}/var.env
		fi
	fi
	exit 0
fi


# Enable automatic exporting of variables
set -a
# Read configuration files
source ${TARGET_PATH}/.env
# Disable automatic exporting of variables
set +a
# Exit on error
set -e


# Create Docker directories if they do not exist yet
for docker_directory in \
    ${TARGET_PATH}/proxy \
    ${TARGET_PATH}/data/oscm-db/data \
    ${TARGET_PATH}/config/certs \
    ${TARGET_PATH}/config/certs/sso \
    ${TARGET_PATH}/config/oscm-branding/brandings \
    ${TARGET_PATH}/config/oscm-core/ssl/privkey \
    ${TARGET_PATH}/config/oscm-core/ssl/cert \
    ${TARGET_PATH}/config/oscm-core/ssl/chain \
    ${TARGET_PATH}/config/oscm-app/ssl/privkey \
    ${TARGET_PATH}/config/oscm-app/ssl/cert \
    ${TARGET_PATH}/config/oscm-app/ssl/chain \
    ${TARGET_PATH}/config/oscm-app/scripts \
    ${TARGET_PATH}/config/oscm-identity/ssl/privkey \
    ${TARGET_PATH}/config/oscm-identity/tenants \
    ${TARGET_PATH}/config/oscm-identity/ssl/cert \
    ${TARGET_PATH}/config/oscm-identity/ssl/chain \
    ${TARGET_PATH}/config/oscm-identity/tenants \
    ${TARGET_PATH}/config/oscm-birt/ssl/privkey \
    ${TARGET_PATH}/config/oscm-birt/ssl/cert \
    ${TARGET_PATH}/config/oscm-birt/ssl/chain \
    ${TARGET_PATH}/config/oscm-branding/ssl/privkey \
    ${TARGET_PATH}/config/oscm-branding/ssl/cert \
    ${TARGET_PATH}/config/oscm-branding/ssl/chain \
    ${TARGET_PATH}/config/oscm-help/ssl/privkey \
    ${TARGET_PATH}/config/oscm-help/ssl/cert \
    ${TARGET_PATH}/config/oscm-help/ssl/chain \
    ${TARGET_PATH}/config/oscm-proxy/ssl/privkey \
    ${TARGET_PATH}/config/oscm-proxy/ssl/cert \
    ${TARGET_PATH}/config/oscm-proxy/ssl/chain \
    ${TARGET_PATH}/config/oscm-proxy/data \
    ${TARGET_PATH}/config/oscm-proxy/html \
    ${TARGET_PATH}/logs/oscm-app \
    ${TARGET_PATH}/logs/oscm-app/tomcat \
    ${TARGET_PATH}/logs/oscm-birt \
    ${TARGET_PATH}/logs/oscm-birt/tomcat \
    ${TARGET_PATH}/logs/oscm-identity \
    ${TARGET_PATH}/logs/oscm-branding \
    ${TARGET_PATH}/logs/oscm-help \
    ${TARGET_PATH}/logs/oscm-core \
    ${TARGET_PATH}/logs/oscm-core/tomcat \
    ${TARGET_PATH}/logs/oscm-db; do
    if [ ! -d ${docker_directory} ]; then
        mkdir -p ${docker_directory}
    fi
done

# If ${TARGET_PATH}/tenant-default.properties does not exist, copy the template for the operator
if [ ! -f ${TARGET_PATH}/config/oscm-identity/tenants/tenant-default.properties ]; then
	cp /opt/tenant-default.properties ${TARGET_PATH}/config/oscm-identity/tenants/tenant-default.properties.template
fi

# Create Docker log files if they do not exist yet
for docker_log_file in \
    ${TARGET_PATH}/logs/oscm-app/oscm-app.out.log \
    ${TARGET_PATH}/logs/oscm-identity/oscm-identity.out.log \
    ${TARGET_PATH}/logs/oscm-birt/oscm-birt.out.log \
    ${TARGET_PATH}/logs/oscm-branding/oscm-branding.out.log \
    ${TARGET_PATH}/logs/oscm-help/oscm-help.out.log \
    ${TARGET_PATH}/logs/oscm-core/oscm-core.out.log \
    ${TARGET_PATH}/logs/oscm-db/oscm-db.out.log; do
    if [ ! -f {docker_log_file} ]; then
        touch ${docker_log_file}
        chmod 640 ${docker_log_file}
    fi
done



# Delete existing yml files
    rm -f ${TARGET_PATH}/*.yml

# Create Docker Compose files from templates
envsubst '$DOCKER_PATH $IMAGE_DB $IMAGE_INITDB $LOG_LEVEL' \
< ${COMPOSE_CONFIG_PATH}/docker-compose-initdb.yml.template \
> ${TARGET_PATH}/docker-compose-initdb.yml
if [ ${SYSLOG} == "true" ]; then
    envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-oscm-syslog.yml.template \
    > ${TARGET_PATH}/docker-compose-oscm.yml
else
    envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-oscm.yml.template \
    > ${TARGET_PATH}/docker-compose-oscm.yml
fi

envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-proxy.yml.template \
> ${TARGET_PATH}/proxy/docker-compose-proxy.yml
envsubst < ${COMPOSE_CONFIG_PATH}/var.env.proxy.template \
> ${TARGET_PATH}/proxy/var.env


# If proxy.conf does exist, copy it in the correct folder<commit_msg>Create var.env file for proxy within the thirst deployer call (#318)<commit_after>#!/bin/bash

 #*****************************************************************************
 #*                                                                           *
 #* Copyright FUJITSU LIMITED 2020                                            *
 #*                                                                           *
 #* Creation Date: 16-07-2020                                                 *
 #*                                                                           *
 #*****************************************************************************

# Variables for this script
COMPOSE_CONFIG_PATH=/opt
TARGET_PATH=/target
LOCKFILE=${TARGET_PATH}/oscm-deployer.lock

if [ ! -d ${TARGET_PATH}/proxy ]; then
    mkdir -p ${TARGET_PATH}/proxy
fi

# If ${TARGET_PATH}/var.env does not exist, just copy the template for the operator and exit
if [ ! -f ${TARGET_PATH}/var.env ] || [ ! -f ${TARGET_PATH}/.env ]; then
	if [ -z ${HOST_FQDN} ]; then 
		echo "Please specify your host name with -e HOST_FQDN=..., where OSCM shall be accessible."
	else	
		envsubst '$HOST_FQDN' < /opt/env.template  > ${TARGET_PATH}/.env
		cp /opt/var.env.proxy.template ${TARGET_PATH}/proxy/var.env
		if [ "${SAMPLE_DATA}" == "true" ]; then
		    cp /opt/var.env.template ${TARGET_PATH}/var.env
		else    
		    cp /opt/var.env.withoutSampleData.template ${TARGET_PATH}/var.env
		fi
	fi
	exit 0
fi


# Enable automatic exporting of variables
set -a
# Read configuration files
source ${TARGET_PATH}/.env
# Disable automatic exporting of variables
set +a
# Exit on error
set -e


# Create Docker directories if they do not exist yet
for docker_directory in \
    ${TARGET_PATH}/data/oscm-db/data \
    ${TARGET_PATH}/config/certs \
    ${TARGET_PATH}/config/certs/sso \
    ${TARGET_PATH}/config/oscm-branding/brandings \
    ${TARGET_PATH}/config/oscm-core/ssl/privkey \
    ${TARGET_PATH}/config/oscm-core/ssl/cert \
    ${TARGET_PATH}/config/oscm-core/ssl/chain \
    ${TARGET_PATH}/config/oscm-app/ssl/privkey \
    ${TARGET_PATH}/config/oscm-app/ssl/cert \
    ${TARGET_PATH}/config/oscm-app/ssl/chain \
    ${TARGET_PATH}/config/oscm-app/scripts \
    ${TARGET_PATH}/config/oscm-identity/ssl/privkey \
    ${TARGET_PATH}/config/oscm-identity/tenants \
    ${TARGET_PATH}/config/oscm-identity/ssl/cert \
    ${TARGET_PATH}/config/oscm-identity/ssl/chain \
    ${TARGET_PATH}/config/oscm-identity/tenants \
    ${TARGET_PATH}/config/oscm-birt/ssl/privkey \
    ${TARGET_PATH}/config/oscm-birt/ssl/cert \
    ${TARGET_PATH}/config/oscm-birt/ssl/chain \
    ${TARGET_PATH}/config/oscm-branding/ssl/privkey \
    ${TARGET_PATH}/config/oscm-branding/ssl/cert \
    ${TARGET_PATH}/config/oscm-branding/ssl/chain \
    ${TARGET_PATH}/config/oscm-help/ssl/privkey \
    ${TARGET_PATH}/config/oscm-help/ssl/cert \
    ${TARGET_PATH}/config/oscm-help/ssl/chain \
    ${TARGET_PATH}/config/oscm-proxy/ssl/privkey \
    ${TARGET_PATH}/config/oscm-proxy/ssl/cert \
    ${TARGET_PATH}/config/oscm-proxy/ssl/chain \
    ${TARGET_PATH}/config/oscm-proxy/data \
    ${TARGET_PATH}/config/oscm-proxy/html \
    ${TARGET_PATH}/logs/oscm-app \
    ${TARGET_PATH}/logs/oscm-app/tomcat \
    ${TARGET_PATH}/logs/oscm-birt \
    ${TARGET_PATH}/logs/oscm-birt/tomcat \
    ${TARGET_PATH}/logs/oscm-identity \
    ${TARGET_PATH}/logs/oscm-branding \
    ${TARGET_PATH}/logs/oscm-help \
    ${TARGET_PATH}/logs/oscm-core \
    ${TARGET_PATH}/logs/oscm-core/tomcat \
    ${TARGET_PATH}/logs/oscm-db; do
    if [ ! -d ${docker_directory} ]; then
        mkdir -p ${docker_directory}
    fi
done

# If ${TARGET_PATH}/tenant-default.properties does not exist, copy the template for the operator
if [ ! -f ${TARGET_PATH}/config/oscm-identity/tenants/tenant-default.properties ]; then
	cp /opt/tenant-default.properties ${TARGET_PATH}/config/oscm-identity/tenants/tenant-default.properties.template
fi

# Create Docker log files if they do not exist yet
for docker_log_file in \
    ${TARGET_PATH}/logs/oscm-app/oscm-app.out.log \
    ${TARGET_PATH}/logs/oscm-identity/oscm-identity.out.log \
    ${TARGET_PATH}/logs/oscm-birt/oscm-birt.out.log \
    ${TARGET_PATH}/logs/oscm-branding/oscm-branding.out.log \
    ${TARGET_PATH}/logs/oscm-help/oscm-help.out.log \
    ${TARGET_PATH}/logs/oscm-core/oscm-core.out.log \
    ${TARGET_PATH}/logs/oscm-db/oscm-db.out.log; do
    if [ ! -f {docker_log_file} ]; then
        touch ${docker_log_file}
        chmod 640 ${docker_log_file}
    fi
done



# Delete existing yml files
    rm -f ${TARGET_PATH}/*.yml

# Create Docker Compose files from templates
envsubst '$DOCKER_PATH $IMAGE_DB $IMAGE_INITDB $LOG_LEVEL' \
< ${COMPOSE_CONFIG_PATH}/docker-compose-initdb.yml.template \
> ${TARGET_PATH}/docker-compose-initdb.yml
if [ ${SYSLOG} == "true" ]; then
    envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-oscm-syslog.yml.template \
    > ${TARGET_PATH}/docker-compose-oscm.yml
else
    envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-oscm.yml.template \
    > ${TARGET_PATH}/docker-compose-oscm.yml
fi

envsubst < ${COMPOSE_CONFIG_PATH}/docker-compose-proxy.yml.template \
> ${TARGET_PATH}/proxy/docker-compose-proxy.yml



# If proxy.conf does exist, copy it in the correct folder
{'fraction_non_alphanumeric': 0.170927127050744, 'fraction_numerical': 0.0033384204502098437, 'mean_word_length': 2.7286628733997156, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '200010', 'n_tokens_mistral': 3595, 'n_tokens_neox': 3431, 'n_words': 536}