Comment and indent app entrypoint (#182)
This commit is contained in:
parent
5cc50eb522
commit
29bff18001
@ -1,9 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to generate a random salt
|
||||
generate_salt() {
|
||||
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 48 | head -n 1
|
||||
}
|
||||
|
||||
# Read environment variables or set default values
|
||||
DB_HOST=${DB_HOST:-db}
|
||||
DB_PORT_NUMBER=${DB_PORT_NUMBER:-5432}
|
||||
MM_USERNAME=${MM_USERNAME:-mmuser}
|
||||
@ -16,60 +18,64 @@ if [ "${1:0:1}" = '-' ]; then
|
||||
fi
|
||||
|
||||
if [ "$1" = 'platform' ]; then
|
||||
for ARG in $@;
|
||||
do
|
||||
case "$ARG" in
|
||||
-config=*)
|
||||
MM_CONFIG=${ARG#*=};;
|
||||
esac
|
||||
done
|
||||
# Check CLI args for a -config option
|
||||
for ARG in $@;
|
||||
do
|
||||
case "$ARG" in
|
||||
-config=*)
|
||||
MM_CONFIG=${ARG#*=};;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f $MM_CONFIG ]
|
||||
then
|
||||
# If there is no configuration file, create it with some default values
|
||||
echo "No configuration file" $MM_CONFIG
|
||||
echo "Creating a new one"
|
||||
# Copy default configuration file
|
||||
cp /config.json.save $MM_CONFIG
|
||||
# Substitue some parameters with jq
|
||||
jq '.ServiceSettings.ListenAddress = ":80"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.LogSettings.EnableConsole = false' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.LogSettings.ConsoleLevel = "INFO"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.Directory = "/mattermost/data/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.EnablePublicLink = true' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.PublicLinkSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SendEmailNotifications = false' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.FeedbackEmail = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SMTPServer = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SMTPPort = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.InviteSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.PasswordResetSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.RateLimitSettings.Enable = true' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.SqlSettings.DriverName = "postgres"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.SqlSettings.AtRestEncryptKey = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
else
|
||||
echo "Using existing config file" $MM_CONFIG
|
||||
fi
|
||||
|
||||
if [ ! -f $MM_CONFIG ]
|
||||
then
|
||||
echo "No configuration file" $MM_CONFIG
|
||||
echo "Creating a new one"
|
||||
# Copy default configuration file
|
||||
cp /config.json.save $MM_CONFIG
|
||||
# Substitue some parameters with jq
|
||||
jq '.ServiceSettings.ListenAddress = ":80"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.LogSettings.EnableConsole = false' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.LogSettings.ConsoleLevel = "INFO"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.Directory = "/mattermost/data/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.EnablePublicLink = true' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.FileSettings.PublicLinkSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SendEmailNotifications = false' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.FeedbackEmail = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SMTPServer = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.SMTPPort = ""' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.InviteSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.EmailSettings.PasswordResetSalt = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.RateLimitSettings.Enable = true' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.SqlSettings.DriverName = "postgres"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
jq '.SqlSettings.AtRestEncryptKey = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||
else
|
||||
echo "Using existing config file" $MM_CONFIG
|
||||
fi
|
||||
# Configure database access
|
||||
if [ -z "$MM_SQLSETTINGS_DATASOURCE" ]
|
||||
then
|
||||
echo -ne "Configure database connection..."
|
||||
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$MM_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=disable&connect_timeout=10"
|
||||
echo OK
|
||||
else
|
||||
echo "Using existing database connection"
|
||||
fi
|
||||
|
||||
if [ -z "$MM_SQLSETTINGS_DATASOURCE" ]
|
||||
then
|
||||
echo -ne "Configure database connection..."
|
||||
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$MM_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=disable&connect_timeout=10"
|
||||
echo OK
|
||||
else
|
||||
echo "Using existing database connection"
|
||||
fi
|
||||
|
||||
echo "Wait until database $DB_HOST:$DB_PORT_NUMBER is ready..."
|
||||
until nc -z $DB_HOST $DB_PORT_NUMBER
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Wait to avoid "panic: Failed to open sql connection pq: the database system is starting up"
|
||||
# Wait for database to be reachable
|
||||
echo "Wait until database $DB_HOST:$DB_PORT_NUMBER is ready..."
|
||||
until nc -z $DB_HOST $DB_PORT_NUMBER
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Starting platform"
|
||||
# Wait another second for the database to be properly started.
|
||||
# Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
|
||||
sleep 1
|
||||
|
||||
echo "Starting platform"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
Reference in New Issue
Block a user