This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
# LaDOSE.DiscordBot reads its configuration from ./settings.json and from nothing else:
|
||||
# Program.cs builds a ConfigurationBuilder with AddJsonFile("settings.json") and no
|
||||
# AddEnvironmentVariables(), so a LADOSE_* variable would be invisible to it. This script
|
||||
# renders that file at container start instead — the same indirection LaDOSE.WebApp's
|
||||
# entrypoint uses to turn LADOSE_API_BASE_URL into /config.js. One image, any token.
|
||||
#
|
||||
# It writes only when LADOSE_DISCORD_TOKEN is set. Left unset, whatever settings.json is
|
||||
# already at /app wins: the placeholder baked in by the build, or a file bind-mounted over
|
||||
# it. Doing both — mounting settings.json read-only *and* setting the variable — fails
|
||||
# here with EROFS rather than silently ignoring one of them.
|
||||
set -eu
|
||||
|
||||
settings_file=/app/settings.json
|
||||
|
||||
# Drop control characters (newlines included) so a value cannot break out of its string
|
||||
# literal, then escape backslashes before double quotes. A token containing " or \ stays
|
||||
# inert data.
|
||||
json_string() {
|
||||
printf '%s' "${1:-}" | tr -d '\001-\037' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
|
||||
}
|
||||
|
||||
if [ -n "${LADOSE_DISCORD_TOKEN:-}" ]; then
|
||||
rest_url=${LADOSE_BOT_REST_URL:-http://api:5000}
|
||||
|
||||
# All five keys, always. Program.cs calls .ToString() on each of them at startup, so a
|
||||
# missing one is a NullReferenceException before the bot ever reaches Discord.
|
||||
cat >"$settings_file" <<EOF
|
||||
{
|
||||
"Discord": {
|
||||
"Token": "$(json_string "${LADOSE_DISCORD_TOKEN}")"
|
||||
},
|
||||
"Challonge": {
|
||||
"Token": "$(json_string "${LADOSE_CHALLONGE_API_KEY:-}")"
|
||||
},
|
||||
"REST": {
|
||||
"Url": "$(json_string "${rest_url}")",
|
||||
"User": "$(json_string "${LADOSE_BOT_REST_USER:-}")",
|
||||
"Password": "$(json_string "${LADOSE_BOT_REST_PASSWORD:-}")"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
# The token is deliberately not echoed.
|
||||
echo "settings.json: rendered from the environment (REST:Url=$rest_url)" >&2
|
||||
else
|
||||
echo "settings.json: LADOSE_DISCORD_TOKEN unset, using the file already at $settings_file" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user