#!/bin/bash

trap "exit 1111" HUP INT QUIT TERM

CONFIG_FILE=deploy-config/all.conf
source scripts/utils.sh
source scripts/config_get.sh
source scripts/global_variables.sh

source scripts/prepare.sh
source scripts/ssh_key_config.sh
source scripts/env_config.sh
source scripts/docker_install.sh
source scripts/datapath_config.sh
source scripts/storage_config.sh
source scripts/deploy_mode.sh
source scripts/compose_config.sh
source scripts/portainer_install.sh
# source scripts/change_compose_label.sh
source scripts/external_database_config.sh
source scripts/install_requirements.sh
source scripts/hardware_perfcheck.sh
source scripts/net_precheck.sh

function main() {
    source scripts/echo_variable.sh
    install_requirements
    ssh_key_config
    prepare

    system_env_config
    
    # docker网络相关检查
    net_percheck

    # 检查环境硬件性能
    hardware_perfcheck
    # system_env_config
    docker_install
    docker_compose_config
    deploy_mode
    portainer_install

    log_info "The ${DOCKER_COMPOSE_FILE} file is stored in the ${IP_LIST[0]}  ${DOCKER_COMPOSE_DIR} directory"
    if [ "${REGION}" == "mainregion" ]; then
        log_info "edoc2 mainregion deploy success"
        log_info "Please access your application via http://${IP_LIST[0]}:${NODE_PORT}"
    fi
    if [ "${REGION}" == "subregion" ]; then
        log_info "edoc2 subregion deploy success"
        log_info "Please check your subregion status in mainregion web via ${PRIMARYURL}"
    fi
}

main
