#!/bin/bash

configSetupFileWithData()
{
    local app_name="$1"
    local custom_file="$2"
    local custom_path="$3"

    if [[ $custom_file != "" ]]; then
        local file_name="$custom_file"
    fi

    if [[ $custom_path == "" ]]; then
        local file_path="$containers_dir$app_name"
    elif [[ $custom_path != "" ]]; then
        local file_path="$containers_dir$app_name/$custom_path/"
    fi

    local full_file_path="$file_path/$file_name"

    result=$(runFileOp sed -i "s|DOMAINSUBNAMEHERE|$host_setup|g" "$full_file_path")
    checkSuccess "Updated DOMAINSUBNAMEHERE with: $host_setup"

    result=$(runFileOp sed -i "s|APPADDRESSHERE|$app_address|g" "$full_file_path")
    checkSuccess "Updated APPADDRESSHERE with: $app_address"

    result=$(runFileOp sed -i "s|DOMAINSUBNAME_DATA|$host_setup|g" "$full_file_path")
    checkSuccess "Updated DOMAINSUBNAME_DATA with: $host_setup"

    result=$(runFileOp sed -i "s|TIMEZONE_DATA|$CFG_TIMEZONE|g" "$full_file_path")
    checkSuccess "Updated TIMEZONE_DATA with: $CFG_TIMEZONE"

    result=$(runFileOp sed -i "s|EMAILHERE|$CFG_TRAEFIK_EMAIL|g" "$full_file_path")
    checkSuccess "Updated EMAILHERE with: $CFG_TRAEFIK_EMAIL"

    result=$(runFileOp sed -i "s|HOSTIPHERE|$public_ip_v4|g" "$full_file_path")
    checkSuccess "Updated HOSTIPHERE with: $public_ip_v4"

    scanFileForRandomPasswordKeysUsers "$full_file_path"

    isSuccessful "Updated $app_name configuration file"
}