53 lines
1.5 KiB
Bash
53 lines
1.5 KiB
Bash
source deploy/docker/logging.sh
|
|
|
|
# usage: loadVariable VAR [DEFAULT]
|
|
# ie: file_env 'DB_PASSWORD' 'example'
|
|
# (will allow for "$DB_PASSWORD_FILE" to fill in the value of
|
|
# "$DB_PASSWORD" from a file, especially for Docker's secrets feature)
|
|
loadVariable() {
|
|
local variable="$1"
|
|
local variableFile="${variable}_FILE"
|
|
local default="${2:-}"
|
|
if [ "${!variable:-}" ] && [ "${!variableFile:-}" ]; then
|
|
logError "Both $variable and $variableFile are set (but are exclusive)"
|
|
fi
|
|
local value="$default"
|
|
if [ "${!variable:-}" ]; then
|
|
value="${!variable}"
|
|
elif [ "${!variableFile:-}" ]; then
|
|
value="$(<"${!variableFile}")"
|
|
fi
|
|
export "$variable"="$value"
|
|
unset "$variableFile"
|
|
}
|
|
|
|
# loads various settings
|
|
setupEnvironment() {
|
|
loadVariable 'TIMEZONE' 'Etc/GMT'
|
|
|
|
# loadVariable 'MIGRATION_PARAM' ''
|
|
# # initialize values that might be stored in a file
|
|
# loadVariable 'MYSQL_HOST'
|
|
# loadVariable 'MYSQL_DATABASE' 'defaultDatabase'
|
|
# loadVariable 'MYSQL_USER' 'defaultUser'
|
|
# loadVariable 'MYSQL_PASSWORD'
|
|
|
|
# initialize values that might be stored in a file
|
|
loadVariable 'TOKEN'
|
|
loadVariable 'OWNER' 'default owner'
|
|
}
|
|
|
|
# verify required environment.
|
|
verifyEnvironment() {
|
|
if [ -z "$TOKEN" ]; then
|
|
logError $'Token is not completely filled\n\tYou need to specify $TOKEN'
|
|
fi
|
|
# if [ -z "$MYSQL_HOST" -o -z "$MYSQL_PASSWORD" ]; then
|
|
# logError $'MYSQL databases credentials is not completely filled\n\tYou need to specify $MYSQL_HOST, $MYSQL_PASSWORD'
|
|
# fi
|
|
}
|
|
|
|
setupEnvironment
|
|
verifyEnvironment
|
|
|