Updating shell scripts to adhear better to Bash style guides (#510)

* Updated Shell Script Format

Signed-off-by: Spencer <wf6DJd8a3xSSCZbn@protonmail.com>
This commit is contained in:
wf6DJd8a3xSSCZbn 2021-01-08 10:45:00 -05:00 committed by GitHub
parent ad76445269
commit 6f8c34c0f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 61 deletions

View File

@ -20,7 +20,7 @@ The following people help to maintain this open source project:
|:--------------------------------------|:--------------| |:--------------------------------------|:--------------|
| Carlos Tadeu Panato Junior - @cpanato | Feb 18 2018 | | Carlos Tadeu Panato Junior - @cpanato | Feb 18 2018 |
In case something happens where no maintainers are able to complete their responsibilies, the following sponsoring organization can help find a new maintainer: In case something happens where no maintainers are able to complete their responsibilities, the following sponsoring organization can help find a new maintainer:
| Sponsoring Organization | Start Date | | Sponsoring Organization | Start Date |
|:-------------------------------|:--------------| |:-------------------------------|:--------------|

View File

@ -196,7 +196,7 @@ docker-compose build app
docker-compose run app -upgrade_db_30 docker-compose run app -upgrade_db_30
docker-compose up -d docker-compose up -d
``` ```
See the [offical Upgrade Guide](http://docs.mattermost.com/administration/upgrade.html) for more details. See the [official Upgrade Guide](http://docs.mattermost.com/administration/upgrade.html) for more details.
## Installation using Docker Swarm Mode ## Installation using Docker Swarm Mode

View File

@ -2,7 +2,7 @@
# Function to generate a random salt # Function to generate a random salt
generate_salt() { generate_salt() {
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 48 | head -n 1 tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w 48 | head -n 1
} }
# Read environment variables or set default values # Read environment variables or set default values
@ -21,62 +21,62 @@ DB_USE_SSL=${DB_USE_SSL:-disable}
MM_DBNAME=${MM_DBNAME:-mattermost} MM_DBNAME=${MM_DBNAME:-mattermost}
MM_CONFIG=${MM_CONFIG:-/mattermost/config/config.json} MM_CONFIG=${MM_CONFIG:-/mattermost/config/config.json}
_1=$(echo "$1" | awk '{ s=substr($0, 0, 1); print s; }' ) _1=$(echo "$1" | awk '{ s=substr($0, 0, 1); print s; }')
if [ "$_1" = '-' ]; then if [ "$_1" = '-' ]; then
set -- mattermost "$@" set -- mattermost "$@"
fi fi
if [ "$1" = 'mattermost' ]; then if [ "$1" = 'mattermost' ]; then
# Check CLI args for a -config option # Check CLI args for a -config option
for ARG in "$@"; do for ARG in "$@"; do
case "$ARG" in case "$ARG" in
-config=*) MM_CONFIG=${ARG#*=};; -config=*) MM_CONFIG=${ARG#*=} ;;
esac esac
done done
if [ ! -f "$MM_CONFIG" ]; then if [ ! -f "$MM_CONFIG" ]; then
# If there is no configuration file, create it with some default values # If there is no configuration file, create it with some default values
echo "No configuration file $MM_CONFIG" echo "No configuration file $MM_CONFIG"
echo "Creating a new one" echo "Creating a new one"
# Copy default configuration file # Copy default configuration file
cp /config.json.save "$MM_CONFIG" cp /config.json.save "$MM_CONFIG"
# Substitute some parameters with jq # Substitute some parameters with jq
jq '.ServiceSettings.ListenAddress = ":8000"' "$MM_CONFIG" > "$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG" jq '.ServiceSettings.ListenAddress = ":8000"' "$MM_CONFIG" >"$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG"
jq '.LogSettings.EnableConsole = true' "$MM_CONFIG" > "$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG" jq '.LogSettings.EnableConsole = true' "$MM_CONFIG" >"$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG"
jq '.LogSettings.ConsoleLevel = "ERROR"' "$MM_CONFIG" > "$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG" jq '.LogSettings.ConsoleLevel = "ERROR"' "$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.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.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 ".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.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.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.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.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.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 ".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 '.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.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" jq ".SqlSettings.AtRestEncryptKey = \"$(generate_salt)\"" "$MM_CONFIG" >"$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG"
jq '.PluginSettings.Directory = "/mattermost/plugins/"' "$MM_CONFIG" > "$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG" jq '.PluginSettings.Directory = "/mattermost/plugins/"' "$MM_CONFIG" >"$MM_CONFIG.tmp" && mv "$MM_CONFIG.tmp" "$MM_CONFIG"
else else
echo "Using existing config file $MM_CONFIG" echo "Using existing config file $MM_CONFIG"
fi fi
# Configure database access # Configure database access
if [ -z "$MM_SQLSETTINGS_DATASOURCE" ] && [ -n "$MM_USERNAME" ] && [ -n "$MM_PASSWORD" ]; then if [ -z "$MM_SQLSETTINGS_DATASOURCE" ] && [ -n "$MM_USERNAME" ] && [ -n "$MM_PASSWORD" ]; then
echo "Configure database connection..." echo "Configure database connection..."
# URLEncode the password, allowing for special characters # URLEncode the password, allowing for special characters
ENCODED_PASSWORD=$(printf %s "$MM_PASSWORD" | jq -s -R -r @uri) ENCODED_PASSWORD=$(printf %s "$MM_PASSWORD" | jq -s -R -r @uri)
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$ENCODED_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=$DB_USE_SSL&connect_timeout=10" export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$ENCODED_PASSWORD@$DB_HOST:$DB_PORT_NUMBER/$MM_DBNAME?sslmode=$DB_USE_SSL&connect_timeout=10"
echo "OK" echo "OK"
else else
echo "Using existing database connection" echo "Using existing database connection"
fi fi
# Wait another second for the database to be properly started. # 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" # Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
sleep 1 sleep 1
echo "Starting mattermost" echo "Starting mattermost"
fi fi
exec "$@" exec "$@"

View File

@ -5,7 +5,7 @@ export WAL_LEVEL=${WAL_LEVEL:-minimal}
export ARCHIVE_MODE=${ARCHIVE_MODE:-off} export ARCHIVE_MODE=${ARCHIVE_MODE:-off}
export ARCHIVE_TIMEOUT=${ARCHIVE_TIMEOUT:-60} export ARCHIVE_TIMEOUT=${ARCHIVE_TIMEOUT:-60}
function update_conf () { function update_conf() {
wal=$1 wal=$1
# PGDATA is defined in upstream postgres dockerfile # PGDATA is defined in upstream postgres dockerfile
config_file=$PGDATA/postgresql.conf config_file=$PGDATA/postgresql.conf
@ -23,11 +23,11 @@ function update_conf () {
sed -i "s/archive_command =.*$//g" $config_file sed -i "s/archive_command =.*$//g" $config_file
# Configure wal-e # Configure wal-e
if [ "$wal" = true ] ; then if [ "$wal" = true ]; then
/docker-entrypoint-initdb.d/setup-wale.sh /docker-entrypoint-initdb.d/setup-wale.sh
fi fi
echo "log_timezone = $DEFAULT_TIMEZONE" >> $config_file echo "log_timezone = $DEFAULT_TIMEZONE" >>$config_file
echo "timezone = $DEFAULT_TIMEZONE" >> $config_file echo "timezone = $DEFAULT_TIMEZONE" >>$config_file
} }
if [ "${1:0:1}" = '-' ]; then if [ "${1:0:1}" = '-' ]; then
@ -46,7 +46,7 @@ if [ "$1" = 'postgres' ]; then
done done
# Setup wal-e env variables # Setup wal-e env variables
if [ "$wal_enable" = true ] ; then if [ "$wal_enable" = true ]; then
for v in ${VARS[@]}; do for v in ${VARS[@]}; do
export $v="${!v}" export $v="${!v}"
done done

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# wal-e specific configuration # wal-e specific configuration
echo "wal_level = $WAL_LEVEL" >> $PGDATA/postgresql.conf echo "wal_level = $WAL_LEVEL" >>$PGDATA/postgresql.conf
echo "archive_mode = $ARCHIVE_MODE" >> $PGDATA/postgresql.conf echo "archive_mode = $ARCHIVE_MODE" >>$PGDATA/postgresql.conf
echo "archive_command = '/usr/bin/wal-e wal-push %p'" >> $PGDATA/postgresql.conf echo "archive_command = '/usr/bin/wal-e wal-push %p'" >>$PGDATA/postgresql.conf
echo "archive_timeout = $ARCHIVE_TIMEOUT" >> $PGDATA/postgresql.conf echo "archive_timeout = $ARCHIVE_TIMEOUT" >>$PGDATA/postgresql.conf

View File

@ -11,7 +11,7 @@ if [ -f "/cert/cert.pem" -a -f "/cert/key-no-password.pem" ]; then
else else
echo "linking plain config" echo "linking plain config"
fi fi
# Ensure that the configuration file is not present before linking. # Ensure that the configuration file is not present before linking.
test -w /etc/nginx/conf.d/mattermost.conf && rm /etc/nginx/conf.d/mattermost.conf test -w /etc/nginx/conf.d/mattermost.conf && rm /etc/nginx/conf.d/mattermost.conf
# Linking Nginx configuration file # Linking Nginx configuration file
ln -s -f /etc/nginx/sites-available/mattermost$ssl /etc/nginx/conf.d/mattermost.conf ln -s -f /etc/nginx/sites-available/mattermost$ssl /etc/nginx/conf.d/mattermost.conf