#!/bin/bash
# shellcheck disable=SC2034

# Following variables might be rewrited by config generated by GPUStack
DATA_DIR="${DATA_DIR:-/var/lib/gpustack}"
LOG_DIR="${LOG_DIR:-${DATA_DIR}/log}"
HIGRESS_DATA_DIR="${DATA_DIR}/higress"
HIGRESS_LOG_DIR="${LOG_DIR}/higress"
APISERVER_PORT=${APISERVER_PORT:-18443}
APISERVER_DATA_DIR="${HIGRESS_DATA_DIR}/apiserver"
EMBEDDED_KUBECONFIG_PATH="${EMBEDDED_KUBECONFIG_PATH:-${HIGRESS_DATA_DIR}/kubeconfig}"
GATEWAY_HTTP_PORT="${GATEWAY_HTTP_PORT:-80}"
GATEWAY_HTTPS_PORT="${GATEWAY_HTTPS_PORT:-443}"
GATEWAY_CONCURRENCY="${GATEWAY_CONCURRENCY:-16}"
ISTIO_DATA_DIR="${HIGRESS_DATA_DIR}/istio-data"

GPUSTACK_API_PORT=${GPUSTACK_API_PORT:-30080}

EMBEDDED_DATABASE_PORT="${EMBEDDED_DATABASE_PORT:-5432}"
STATE_MIGRATION_DONE_FILE="${STATE_MIGRATION_DONE_FILE:-${DATA_DIR}/run/state_migration_done}"
POSTGRES_DATA_DIR="${POSTGRES_DATA_DIR:-${DATA_DIR}/postgres/data}"

PROMETHEUS_PORT="${PROMETHEUS_PORT:-19090}"
PROMETHEUS_DATA_DIR="${PROMETHEUS_DATA_DIR:-${DATA_DIR}/prometheus}"
PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_FILE:-/etc/prometheus/prometheus.yml}"

GF_SERVER_HTTP_PORT="${GF_SERVER_HTTP_PORT:-13000}"
GF_PATHS_DATA="${GF_PATHS_DATA:-${DATA_DIR}/grafana}"
GF_PATHS_LOGS="${GF_PATHS_LOGS:-${LOG_DIR}/grafana}"
GF_PATHS_PLUGINS="${GF_PATHS_PLUGINS:-${GF_PATHS_DATA}/plugins}"
GF_PATHS_PROVISIONING="${GF_PATHS_PROVISIONING:-/etc/grafana/provisioning}"
GF_PATHS_CONFIG="${GF_PATHS_CONFIG:-/etc/grafana/grafana.ini}"
GF_SERVER_ROOT_URL="${GF_SERVER_ROOT_URL:-%(protocol)s://%(domain)s:%(http_port)s/grafana}"
GF_SERVER_SERVE_FROM_SUB_PATH="${GF_SERVER_SERVE_FROM_SUB_PATH:-true}"
GF_SECURITY_ADMIN_USER="${GF_SECURITY_ADMIN_USER:-admin}"
GF_SECURITY_ADMIN_PASSWORD="${GF_SECURITY_ADMIN_PASSWORD:-grafana}"
GF_AUTH_ANONYMOUS_ENABLED="${GF_AUTH_ANONYMOUS_ENABLED:-true}"
GF_AUTH_ANONYMOUS_ORG_ROLE="${GF_AUTH_ANONYMOUS_ORG_ROLE:-Viewer}"
GF_AUTH_DISABLE_LOGIN_FORM="${GF_AUTH_DISABLE_LOGIN_FORM:-true}"

GATEWAY_CONTROLLER_GRPC_PORT="${GATEWAY_CONTROLLER_GRPC_PORT:-15051}"
GATEWAY_CONTROLLER_HTTP_PORT="${GATEWAY_CONTROLLER_HTTP_PORT:-8088}"
GATEWAY_PILOT_GRPC_PORT="${GATEWAY_PILOT_GRPC_PORT:-15010}"
GATEWAY_PILOT_TLS_GRPC_PORT="${GATEWAY_PILOT_TLS_GRPC_PORT:-15012}"
GATEWAY_PILOT_INTROSPECTION_PORT="${GATEWAY_PILOT_INTROSPECTION_PORT:-9876}"
GATEWAY_ENVOY_ADMIN_PORT="${GATEWAY_ENVOY_ADMIN_PORT:-15000}"
GATEWAY_ENVOY_HEALTHCHECK_PORT="${GATEWAY_ENVOY_HEALTHCHECK_PORT:-15021}"
GATEWAY_ENVOY_METRICS_PORT="${GATEWAY_ENVOY_METRICS_PORT:-15090}"
GATEWAY_PILOT_AGENT_METRICS_PORT="${GATEWAY_PILOT_AGENT_METRICS_PORT:-15020}"
