#!/usr/bin/env bash set -euo pipefail server="${1:-worldserver}" case "${server}" in worldserver|bnetserver) ;; *) exec "$@" ;; esac db_host="${DB_HOST:-database}" db_port="${DB_PORT:-3306}" db_user="${DB_USER:-sylvania}" db_password="${DB_PASSWORD:-sylvania}" external_address="${EXTERNAL_ADDRESS:-127.0.0.1}" realm_name="${REALM_NAME:-Sylvania Solo}" realm_address="${REALM_ADDRESS:-127.0.0.1}" realm_port="${REALM_PORT:-8086}" dbc_locale="${DBC_LOCALE:-8}" if [[ ! "${realm_name}" =~ ^[[:alnum:]А-Яа-яЁё._[:space:]-]{1,32}$ ]]; then echo "REALM_NAME contains unsupported characters or is longer than 32 characters" >&2 exit 1 fi if [[ ! "${realm_address}" =~ ^[A-Za-z0-9.-]+$ ]]; then echo "REALM_ADDRESS must be an IPv4 address or a DNS name" >&2 exit 1 fi if [[ ! "${realm_port}" =~ ^[0-9]+$ ]] || (( realm_port < 1 || realm_port > 65535 )); then echo "REALM_PORT must be an integer between 1 and 65535" >&2 exit 1 fi if [[ ! "${dbc_locale}" =~ ^[0-9]+$ ]] || (( dbc_locale > 11 || dbc_locale == 9 )); then echo "DBC_LOCALE must be a valid locale index (ruRU is 8)" >&2 exit 1 fi config_dir=/opt/sylvania/etc template="${config_dir}/${server}.conf.dist" config="${config_dir}/${server}.conf" cp "${template}" "${config}" sed -i -E \ -e "s#^(LoginDatabaseInfo[[:space:]]*=).*#\\1 \"${db_host};${db_port};${db_user};${db_password};auth\"#" \ "${config}" # Keep the client-facing realm record in sync after restores and migrations. # Values are validated above before being interpolated into SQL. mariadb --default-character-set=utf8mb4 --protocol=tcp \ -h "${db_host}" -P "${db_port}" -u "${db_user}" "-p${db_password}" auth <