83 lines
3.2 KiB
Bash
83 lines
3.2 KiB
Bash
#!/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 <<SQL
|
||
INSERT INTO realmlist
|
||
(id, name, address, localAddress, localSubnetMask, port, icon, flag,
|
||
timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup)
|
||
VALUES
|
||
(1, '${realm_name}', '${realm_address}', '${realm_address}',
|
||
'255.255.255.0', ${realm_port}, 0, 0, 1, 0, 0, 26972, 1, 1)
|
||
ON DUPLICATE KEY UPDATE
|
||
name = VALUES(name),
|
||
address = VALUES(address),
|
||
localAddress = VALUES(localAddress),
|
||
port = VALUES(port),
|
||
gamebuild = VALUES(gamebuild);
|
||
SQL
|
||
|
||
if [[ "${server}" == worldserver ]]; then
|
||
sed -i -E \
|
||
-e "s#^(WorldDatabaseInfo[[:space:]]*=).*#\\1 \"${db_host};${db_port};${db_user};${db_password};world\"#" \
|
||
-e "s#^(CharacterDatabaseInfo[[:space:]]*=).*#\\1 \"${db_host};${db_port};${db_user};${db_password};characters\"#" \
|
||
-e "s#^(HotfixDatabaseInfo[[:space:]]*=).*#\\1 \"${db_host};${db_port};${db_user};${db_password};hotfixes\"#" \
|
||
-e "s#^(ShopDatabaseInfo[[:space:]]*=).*#\\1 \"${db_host};${db_port};${db_user};${db_password};shop\"#" \
|
||
-e 's#^DataDir[[:space:]]*=.*#DataDir = "/opt/sylvania/data"#' \
|
||
-e "s#^DBC.Locale[[:space:]]*=.*#DBC.Locale = ${dbc_locale}#" \
|
||
-e 's#^LogsDir[[:space:]]*=.*#LogsDir = "/opt/sylvania/logs"#' \
|
||
"${config}"
|
||
else
|
||
sed -i -E \
|
||
-e "s#^LoginREST.ExternalAddress=.*#LoginREST.ExternalAddress=${external_address}#" \
|
||
-e "s#^LoginREST.LocalAddress=.*#LoginREST.LocalAddress=${external_address}#" \
|
||
-e 's#^LogsDir[[:space:]]*=.*#LogsDir = "/opt/sylvania/logs"#' \
|
||
"${config}"
|
||
fi
|
||
|
||
exec "/opt/sylvania/bin/${server}" -c "${config}"
|