#!/bin/bash
# 定基本环境变量并导出
# 不同的环境采用不同的DOMAIN
if [ -z "${VERSION}" ]; then
    export VERSION=""
    echo "环境变量 VERSION 未设置"
else
    echo "环境变量 VERSION 已设置，设置为 ${VERSION}"
fi

if [ -z "${DOMAIN}" ]; then
    export DOMAIN=bazhong
    echo "环境变量 DOMAIN 未设置，设置为默认值 ${DOMAIN}"
else
    echo "环境变量 DOMAIN 已设置，设置为 ${DOMAIN}"
fi

if [[ "$(uname)" == "Darwin" ]]; then
  echo "当前是 Mac 系统"
  export PLATFORM=""
  # 这里写 Mac 下要执行的命令
else
  echo "当前不是 Mac 系统"
  export PLATFORM="linux"
  echo "环境变量 PLATFORM 已设置，设置为 ${PLATFORM}"
  # 这里写 Linux 或其他系统下要执行的命令
fi


export NETWORK="swarm_network_$DOMAIN"
# 镜像仓库地址
export REGISTRY=registry.t-aaron.com
# 主机的域名后缀
if [ -z "${DOMAIN_END}" ]; then
    export DOMAIN_END=t-aaron.com
    echo "环境变量 DOMAIN_END 未设置，设置为默认值 ${DOMAIN_END}"
else
    echo "环境变量 DOMAIN_END 已设置，设置为 ${DOMAIN_END}"
fi

# 主机对外爆露的HTTP端口
if [ -z "$NGINX_HTTP_PORT" ]; then
    export NGINX_HTTP_PORT=8899
else
    echo "环境变量 NGINX_HTTP_PORT 已设置，设置为 ${NGINX_HTTP_PORT}"
fi
# 主机对外爆露的HTTPS端口
if [ -z "$NGINX_HTTPS_PORT" ]; then
    export NGINX_HTTPS_PORT=2443
else
    echo "环境变量 NGINX_HTTPS_PORT 已设置，设置为 ${NGINX_HTTPS_PORT}"
fi

if [ -z "$SKYWALKING_UI_DOMAIN" ]; then
   export SKYWALKING_UI_DOMAIN=sky-${DOMAIN}.${DOMAIN_END}
fi

if [ -z "$CONSUL_DOMAIN" ]; then
   export CONSUL_DOMAIN=consul-${DOMAIN}.${DOMAIN_END}
fi

if [ -z "$XXLJOB_DOMAIN" ]; then
   export XXLJOB_DOMAIN=xxljob-${DOMAIN}.${DOMAIN_END}
fi

if [ -z "$OIDC_SERVER_DOMAIN" ]; then
   export OIDC_SERVER_DOMAIN=oidc-${DOMAIN}.${DOMAIN_END}
fi
export OIDC_DOMAIN_FULL=${OIDC_SERVER_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$OIDC_ADMIN_DOMAIN" ]; then
   export OIDC_ADMIN_DOMAIN=oidcadmin-${DOMAIN}.${DOMAIN_END}
fi
export OIDC_ADMIN_DOMAIN_FULL=${OIDC_ADMIN_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$MINIO_DOMAIN" ]; then
   export MINIO_DOMAIN=minio-${DOMAIN}.${DOMAIN_END}
fi

if [ -z "$MINIO_CONSOLE_DOMAIN" ]; then
   export MINIO_CONSOLE_DOMAIN=minioconsole-${DOMAIN}.${DOMAIN_END}
fi

if [ -z "$AIRPORT_DOMAIN" ]; then
   export AIRPORT_DOMAIN=airport-${DOMAIN}.${DOMAIN_END}
fi
export AIRPORT_DOMAIN_FULL=${AIRPORT_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$BUSINESS_DOMAIN" ]; then
   export BUSINESS_DOMAIN=business-${DOMAIN}.${DOMAIN_END}
fi
export BUSINESS_DOMAIN_FULL=${BUSINESS_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$SRS_DOMAIN" ]; then
   export SRS_DOMAIN=srs-${DOMAIN}.${DOMAIN_END}
fi
export SRS_DOMAIN_FULL=${SRS_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$HHZ_DOMAIN" ]; then
   export HHZ_DOMAIN=hhz-${DOMAIN}.${DOMAIN_END}
fi
export HHZ_DOMAIN_FULL=${HHZ_DOMAIN}:${NGINX_HTTPS_PORT}

if [ -z "$DSP_DOMAIN" ]; then
   export DSP_DOMAIN=dsp-${DOMAIN}.${DOMAIN_END}
fi
export DSP_DOMAIN_FULL=${DSP_DOMAIN}:${NGINX_HTTPS_PORT}
export REGISTRY_HOST=${REGISTRY}/tuoheng/

if [ -z "$KAFKA_DOMAIN" ]; then
  export KAFKA_DOMAIN=kafka-${DOMAIN}.${DOMAIN_END}
fi
 



 

#Nginx 配置
export NGINX_NAME=NGINX_${DOMAIN}
export NGINX_IMAGE=${REGISTRY_HOST}nginx:${DOMAIN}${VERSION}
export NGINX_MEMORY=256m

#MySql 配置 
# 数据库对外爆露端口 

# 主机对外爆露的HTTPS端口
if [ -z "$MYSQL_PORT" ]; then
    export MYSQL_PORT=3308
else
    echo "环境变量 MYSQL_PORT 已设置，设置为 ${MYSQL_PORT}"
fi
export MYSQL_ROOT_PASSWORD=tuoheng2024
export MYSQL_IMAGE=${REGISTRY_HOST}mysql:8.0.25
export MYSQL_DATA=${NETWORK}_mysql_data
export MYSQL_NAME=MYSQL_${DOMAIN} 
export MYSQL_MEMORY=1g    

#Redis 配置
if [ -z "$REDIS_PORT" ]; then
   export REDIS_PORT=6380
else
    echo "环境变量 REDIS_PORT 已设置，设置为 ${REDIS_PORT}"
fi
 
export REDIS_IMAGE=${REGISTRY_HOST}redis:latest
export REDIS_DATA=${NETWORK}_redis_data
export REDIS_NAME=REDIS_${DOMAIN}
export REDIS_MEMORY=512m    


#MQTT 配置
# MQTT对外爆露端口
if [ -z "$MQTT_PORT" ]; then
   export MQTT_PORT=1883
else
    echo "环境变量 MQTT_PORT 已设置，设置为 ${MQTT_PORT}"
fi
if [ -z "$MQTT_WS_PORT" ]; then
   export MQTT_WS_PORT=9001
else
    echo "环境变量 MQTT_WS_PORT 已设置，设置为 ${MQTT_WS_PORT}"
fi
 
 
export MQTT_IMAGE=${REGISTRY_HOST}eclipse-mosquitto:latest
export MQTT_NAME=MQTT_${DOMAIN}
export MQTT_MEMORY=512m    

#Kafka 配置
# Kafka对外爆露端口
if [ -z "$KAFKA_PORT" ]; then
   export KAFKA_PORT=9292
else
    echo "环境变量 KAFKA_PORT 已设置，设置为 ${KAFKA_PORT}"
fi
if [[ "$(uname)" == "Darwin" ]]; then
  echo "当前是 Mac 系统"
  export KAFKA_IMAGE=${REGISTRY_HOST}bitnami/kafka:latest
  # 这里写 Mac 下要执行的命令
else
  echo "当前不是 Mac 系统"
  export KAFKA_IMAGE=${REGISTRY_HOST}bitnami/kafka:${PLATFORM}
  echo "环境变量 KAFKA_IMAGE 已设置，设置为 ${KAFKA_IMAGE}"
  # 这里写 Linux 或其他系统下要执行的命令
fi
export KAFKA_NAME=KAFKA_${DOMAIN}
export KAFKA_MEMORY=2g
export KAFKA_DATA=${NETWORK}_kafka_data  
export KAFKA_DOMAIN_FULL=${KAFKA_DOMAIN}:${KAFKA_PORT}
 

#SRS 配置
# SRS对外爆露端口 Name比较特别,没有DOAMIN后缀
export SRS_NAME=SRS
if [ -z "$SRS_RTMP_PORT" ]; then
  export SRS_RTMP_PORT=1935
else
    echo "环境变量 SRS_RTMP_PORT 已设置，设置为 ${SRS_RTMP_PORT}"
fi
if [ -z "$SRS_RTC_PORT" ]; then
  export SRS_RTC_PORT=8000
else
    echo "环境变量 SRS_RTC_PORT 已设置，设置为 ${SRS_RTC_PORT}"
fi
export SRS_RTMP_DOMAIN_FULL=${SRS_DOMAIN}:${SRS_RTMP_PORT}
export SRS_MEMORY=512m
export SRS_IMAGE=${REGISTRY_HOST}srs:6
export SRS_DATA=${NETWORK}_srs_data

#Minio 配置 Name比较特别,没有DOAMIN后缀
export MINIO_NAME=MINIO
export MINIO_MEMORY=512m
export MINIO_IMAGE=${REGISTRY_HOST}quay.io/minio:latest${PLATFORM}
export MINIO_DATA=${NETWORK}_minio_data 
# Minio对外爆露端口
if [ -z "$MINIO_API_PORT" ]; then
   export MINIO_API_PORT=9000
else
    echo "环境变量 MINIO_API_PORT 已设置，设置为 ${MINIO_API_PORT}"
fi
# Minio控制台对外爆露端口
if [ -z "$MINIO_CONSOLE_PORT" ]; then
   export MINIO_CONSOLE_PORT=9002
else
    echo "环境变量 MINIO_CONSOLE_PORT 已设置，设置为 ${MINIO_CONSOLE_PORT}"
fi
export MINIO_ROOT_USER=miniopassword
export MINIO_ROOT_PASSWORD=miniopassword   

if [ -z "$MINIO_ACCESS_KEY" ]; then
    export MINIO_ACCESS_KEY=shvngIfksXjTqlQHKSxt
else
    echo "环境变量 MINIO_ACCESS_KEY 已设置，设置为 ${MINIO_ACCESS_KEY}"
fi

if [ -z "$MINIO_SECRET_KEY" ]; then
    export MINIO_SECRET_KEY=Xed4RsGAF1iX7bzEsNEXydnEYsWMUHzU4cA4IPGl
else
    echo "环境变量 MINIO_SECRET_KEY 已设置，设置为 ${MINIO_SECRET_KEY}"
fi

# Elasticsearch 配置
export ES_NAME=ES_${DOMAIN}
export ES_IMAGE=${REGISTRY_HOST}elasticsearch:7.8.0
export ES_MEMORY=1g
# Elasticsearch对外爆露端口
export ES_PORT=9200
export ES_DATA=${NETWORK}_es_data
export ES_LOG_DATA=${NETWORK}_es_log_data

# SkyWalking 配置
export SKYWALKING_OAP_NAME=SKYWALKING_OAP_${DOMAIN}
export SKYWALKING_UI_NAME=SKYWALKING_UI_${DOMAIN}
export SKYWALKING_OAP_IMAGE=${REGISTRY_HOST}apache/skywalking-oap-server:8.6.0-es7
export SKYWALKING_UI_IMAGE=${REGISTRY_HOST}apache/skywalking-ui:8.6.0
export SKYWALKING_OAP_MEMORY=1g
export SKYWALKING_UI_MEMORY=1g
# SkyWalking UI对外爆露端口
export SKYWALKING_UI_PORT=8282
export SW_AGENT_COLLECTOR_BACKEND_SERVICES=${SKYWALKING_OAP_NAME}:11800
export SKYWALKING_USERNAME=skywalking
export SKYWALKING_PASSWORD=skywalking

#SKY_AOP 配置
export SKY_AOP=${SKYWALKING_OAP_NAME}:11800

# Consul 配置
export CONSUL_NAME=CONSUL_${DOMAIN}
export CONSUL_IMAGE=${REGISTRY_HOST}consul:latest
if [ -z "$CONSUL_PORT" ]; then
   export CONSUL_PORT=8500
else
    echo "环境变量 CONSUL_PORT 已设置，设置为 ${CONSUL_PORT}"
fi
export CONSUL_MEMORY="512m"

# XXL-Job 配置
export XXLJOB_NAME=XXL-JOB-${DOMAIN}
export XXLJOB_IMAGE=${REGISTRY_HOST}xuxueli/xxl-job-admin:2.4.0
if [ -z "$XXLJOB_PORT" ]; then
   export XXLJOB_PORT=8282 
else
    echo "环境变量 XXLJOB_PORT 已设置，设置为 ${XXLJOB_PORT}"
fi
export XXLJOB_MEMORY=1g
export XXLJOB_ACCESS_TOKEN=default_token
 


#OIDCServer 配置
export OIDC_SERVER_NAME=OIDC-SERVER${DOMAIN} 
export OIDC_SERVER_IMAGE=${REGISTRY_HOST}oidcserver:${DOMAIN}${VERSION} 
export OIDC_SERVER_JAR=tuoheng_oidc_server.jar
if [ -z "$OIDC_SERVER_REMOTE_JAR" ]; then
   export OIDC_SERVER_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/oidcservice/${OIDC_SERVER_JAR}
else
    echo "环境变量 OIDC_SERVER_REMOTE_JAR 已设置，设置为 ${OIDC_SERVER_REMOTE_JAR}"
fi
export OIDC_SERVER_MEMORY=1g

#OIDCAdmin 配置
export OIDC_ADMIN_NAME=OIDC-ADMIN${DOMAIN} 
export OIDC_ADMIN_IMAGE=${REGISTRY_HOST}oidcadmin:${DOMAIN}${VERSION} 
export OIDC_ADMIN_JAR=tuoheng_oidc_admin.jar
if [ -z "$OIDC_ADMIN_REMOTE_JAR" ]; then
   export OIDC_ADMIN_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/oidcadmin/${OIDC_ADMIN_JAR}
else
    echo "环境变量 OIDC_ADMIN_REMOTE_JAR 已设置，设置为 ${OIDC_ADMIN_REMOTE_JAR}"
fi
export OIDC_ADMIN_MEMORY=1g

#网关配置
export GATEWAY_NAME=GATEWAY${DOMAIN}
export GATEWAY_IMAGE=${REGISTRY_HOST}gateway:${DOMAIN}${VERSION}
export GATEWAY_JAR=tuoheng_gateway.jar
if [ -z "$GATEWAY_REMOTE_JAR" ]; then
  export GATEWAY_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/gateway/${GATEWAY_JAR}
else
    echo "环境变量 GATEWAY_REMOTE_JAR 已设置，设置为 ${GATEWAY_REMOTE_JAR}"
fi
export GATEWAY_MEMORY=1g

#流媒体录制配置
export STREAM_NAME=STREAM
export STREAM_IMAGE=${REGISTRY_HOST}stream:${DOMAIN}${VERSION}
if [ -z "$STREAM_REMOTE_JAR" ]; then
  export STREAM_REMOTE_JAR=/Users/sunpeng/workspace/ideaproject/stream_server/target/stream_server-0.0.1-SNAPSHOT.jar
else
    echo "环境变量 STREAM_REMOTE_JAR 已设置，设置为 ${STREAM_REMOTE_JAR}"
fi
export STREAM_MEMORY=1g
export STREAM_JAR=stream_server-0.0.1-SNAPSHOT.jar
export STREAM_DATA=${NETWORK}_stream_data
export STREAM_DEBUG_PORT=7878

#河湖长
export HHZ_API_NAME=HHZ-API${DOMAIN}
export HHZ_API_IMAGE=${REGISTRY_HOST}hhzapi:${DOMAIN}${VERSION}
export HHZ_API_JAR=tuoheng_hhz_api.jar
if [ -z "$HHZ_API_REMOTE_JAR" ]; then
  export HHZ_API_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/hhz-api/${HHZ_API_JAR}
else
    echo "环境变量 HHZ_API_REMOTE_JAR 已设置，设置为 ${HHZ_API_REMOTE_JAR}"
fi
export HHZ_API_MEMORY=1g

#河湖长
export HHZ_ADMIN_NAME=HHZ-ADMIN${DOMAIN}
export HHZ_ADMIN_IMAGE=${REGISTRY_HOST}hhzadmin:${DOMAIN}${VERSION}
export HHZ_ADMIN_JAR=tuoheng_hhz_admin.jar
if [ -z "${HHZ_ADMIN_REMOTE_JAR}" ]; then
    export HHZ_ADMIN_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/hhz-admin/${HHZ_ADMIN_JAR}
else
    echo "环境变量 HHZ_ADMIN_REMOTE_JAR 已设置，设置为 ${HHZ_ADMIN_REMOTE_JAR}"
fi
export HHZ_ADMIN_MEMORY=1g
if [ -z "${HHZ_ADMIN_WEB_DIST}" ]; then
    export HHZ_ADMIN_WEB_DIST=/Users/sunpeng/workspace/remote/tuoheng_hhz_web/dist
else
    echo "环境变量 HHZ_ADMIN_WEB_DIST 已设置，设置为 ${HHZ_ADMIN_WEB_DIST}"
fi


#机场平台
export AIRPORT_NAME=AIRPORT${DOMAIN}
export AIRPORT_IMAGE=${REGISTRY_HOST}airport:${DOMAIN}${VERSION}
export AIRPORT_JAR=tuoheng_airport_admin.jar
if [ -z "${AIRPORT_REMOTE_JAR}" ]; then
    export AIRPORT_REMOTE_JAR=/Users/sunpeng/workspace/remote/tuoheng_airport/tuoheng-admin/target/${AIRPORT_JAR}
else
    echo "环境变量 AIRPORT_REMOTE_JAR 已设置，设置为 ${AIRPORT_REMOTE_JAR}"
fi
if [ -z "${AIRPORT_WEB_DIST}" ]; then
    export AIRPORT_WEB_DIST=/Users/sunpeng/workspace/remote/docker/tuoheng_airport_web/dist
else
    echo "环境变量 AIRPORT_WEB_DIST 已设置，设置为 ${AIRPORT_WEB_DIST}"
fi
export AIRPORT_MEMORY=1g


export BUSINESS_NAME=BUSINESS${DOMAIN}
export BUSINESS_IMAGE=${REGISTRY_HOST}business:${DOMAIN}${VERSION}
export BUSINESS_JAR=tuoheng_business_admin.jar
if [ -z "${BUSINESS_REMOTE_JAR}" ]; then
   export BUSINESS_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/business/${BUSINESS_JAR}
else
    echo "环境变量 BUSINESS_REMOTE_JAR 已设置，设置为 ${BUSINESS_REMOTE_JAR}"
fi
export BUSINESS_MEMORY=512m
if [ -z "${BUSINESS_WEB_DIST}" ]; then
    export BUSINESS_WEB_DIST=/Users/sunpeng/workspace/remote/tuoheng_hhz_web/dist
else
    echo "环境变量 BUSINESS_WEB_DIST 已设置，设置为 ${BUSINESS_WEB_DIST}"
fi

 
export DSP_API_NAME=DSP-API${DOMAIN}
export DSP_API_IMAGE=${REGISTRY_HOST}dspapi:${DOMAIN}${VERSION}
export DSP_API_JAR=tuoheng_dsp_api.jar
if [ -z "${DSP_API_REMOTE_JAR}" ]; then
   export DSP_API_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/dsp-api/${DSP_API_JAR}
else
    echo "环境变量 DSP_API_REMOTE_JAR 已设置，设置为 ${DSP_API_REMOTE_JAR}"
fi
export DSP_API_MEMORY=1g

export DSP_ADMIN_NAME=DSP-ADMIN${DOMAIN}
export DSP_ADMIN_IMAGE=${REGISTRY_HOST}dspadmin:${DOMAIN}${VERSION}
export DSP_ADMIN_JAR=tuoheng_dsp_admin.jar
if [ -z "${DSP_ADMIN_REMOTE_JAR}" ]; then
    export DSP_ADMIN_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/dsp-admin/${DSP_ADMIN_JAR}
else
    echo "环境变量 DSP_ADMIN_REMOTE_JAR 已设置，设置为 ${DSP_ADMIN_REMOTE_JAR}"
fi
export DSP_ADMIN_MEMORY=512m
if [ -z "${DSP_ADMIN_WEB_DIST}" ]; then
    export DSP_ADMIN_WEB_DIST=/home/th/workspace/dockerbuilder/webs/dsp-admin/dist
else
    echo "环境变量 DSP_ADMIN_WEB_DIST 已设置，设置为 ${DSP_ADMIN_WEB_DIST}"
fi


export DSP_INSPECTION_NAME=DSP-INSPECTION${DOMAIN}
export DSP_INSPECTION_IMAGE=${REGISTRY_HOST}dspinspection:${DOMAIN}${VERSION}
export DSP_INSPECTION_JAR=tuoheng_dsp_inspection.jar
if [ -z "${DSP_INSPECTION_REMOTE_JAR}" ]; then
    export DSP_INSPECTION_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/dsp-inspection/${DSP_INSPECTION_JAR}
else
    echo "环境变量 DSP_INSPECTION_REMOTE_JAR 已设置，设置为 ${DSP_INSPECTION_REMOTE_JAR}"
fi
export DSP_INSPECTION_MEMORY=512m

export DSP_MINI_NAME=DSP-MINI${DOMAIN}
export DSP_MINI_IMAGE=${REGISTRY_HOST}dspmini:${DOMAIN}${VERSION}
export DSP_MINI_JAR=tuoheng_dsp_miniprogram.jar
if [ -z "${DSP_MINI_REMOTE_JAR}" ]; then
    export DSP_MINI_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/dsp-mini/${DSP_MINI_JAR}
else
    echo "环境变量 DSP_MINI_REMOTE_JAR 已设置，设置为 ${DSP_MINI_REMOTE_JAR}"
fi
export DSP_MINI_MEMORY=512m

export DSP_PORTAL_NAME=DSP-PORTAL${DOMAIN}
export DSP_PORTAL_IMAGE=${REGISTRY_HOST}dspportal:${DOMAIN}${VERSION}
export DSP_PORTAL_JAR=tuoheng_dsp_portal.jar
if [ -z "${DSP_PORTAL_REMOTE_JAR}" ]; then
    export DSP_PORTAL_REMOTE_JAR=/home/th/workspace/test/swarm/dockerfile/dsp-portal/${DSP_PORTAL_JAR}
else
    echo "环境变量 DSP_PORTAL_REMOTE_JAR 已设置，设置为 ${DSP_PORTAL_REMOTE_JAR}"
fi
export DSP_PORTAL_MEMORY=512m

# Kafka UI 配置
export KAFKA_UI_PORT=8080
export KAFKA_UI_NAME=KAFKA_UI_${DOMAIN}
export KAFKA_UI_IMAGE=registry.t-aaron.com/tuoheng/provectuslabs/kafka-ui:latest
export KAFKA_UI_MEMORY=512m