Skip to content

Commit 563eb41

Browse files
committed
entrypoint: Add a function to normalize True/False values.
1 parent 97a317a commit 563eb41

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

entrypoint.sh

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ fi
77
set -e
88
shopt -s extglob
99

10+
normalize_bool() {
11+
# Returns either "True" or "False"
12+
local varname="$1"
13+
local raw_value="${!varname}"
14+
local value="${raw_value,,}" # Convert to lowercase
15+
local default="${2:-False}"
16+
17+
case "$value" in
18+
true | enable | enabled | yes | y | 1 | on)
19+
echo "True"
20+
;;
21+
false | disable | disabled | no | n | 0 | off)
22+
echo "False"
23+
;;
24+
"")
25+
echo "$default"
26+
;;
27+
*)
28+
echo "WARNING: Invalid boolean ('$raw_value') for '$varname'; defaulting to $default" >&2
29+
echo "$default"
30+
;;
31+
esac
32+
}
33+
1034
# DB aka Database
1135
DB_HOST="${DB_HOST:-127.0.0.1}"
1236
DB_HOST_PORT="${DB_HOST_PORT:-5432}"
@@ -25,25 +49,26 @@ if [ -z "$SETTING_MEMCACHED_LOCATION" ]; then
2549
SETTING_MEMCACHED_LOCATION="127.0.0.1:11211"
2650
fi
2751
# Nginx settings
28-
DISABLE_HTTPS="${DISABLE_HTTPS:-false}"
52+
DISABLE_HTTPS="$(normalize_bool DISABLE_HTTPS)"
2953
NGINX_WORKERS="${NGINX_WORKERS:-2}"
3054
NGINX_PROXY_BUFFERING="${NGINX_PROXY_BUFFERING:-off}"
3155
NGINX_MAX_UPLOAD_SIZE="${NGINX_MAX_UPLOAD_SIZE:-80m}"
32-
TRUST_GATEWAY_IP="${TRUST_GATEWAY_IP:-False}"
56+
TRUST_GATEWAY_IP="$(normalize_bool TRUST_GATEWAY_IP)"
3357
# Zulip certificate parameters
3458
SSL_CERTIFICATE_GENERATION="${SSL_CERTIFICATE_GENERATION:self-signed}"
3559
# Zulip related settings
3660
ZULIP_AUTH_BACKENDS="${ZULIP_AUTH_BACKENDS:-EmailAuthBackend}"
37-
ZULIP_RUN_POST_SETUP_SCRIPTS="${ZULIP_RUN_POST_SETUP_SCRIPTS:-True}"
61+
ZULIP_RUN_POST_SETUP_SCRIPTS="$(normalize_bool ZULIP_RUN_POST_SETUP_SCRIPTS True)"
62+
QUEUE_WORKERS_MULTIPROCESS="$(normalize_bool QUEUE_WORKERS_MULTIPROCESS)"
3863
# Zulip user setup
39-
FORCE_FIRST_START_INIT="${FORCE_FIRST_START_INIT:-False}"
64+
FORCE_FIRST_START_INIT="$(normalize_bool FORCE_FIRST_START_INIT)"
4065
# Auto backup settings
41-
AUTO_BACKUP_ENABLED="${AUTO_BACKUP_ENABLED:-True}"
66+
AUTO_BACKUP_ENABLED="$(normalize_bool AUTO_BACKUP_ENABLED True)"
4267
AUTO_BACKUP_INTERVAL="${AUTO_BACKUP_INTERVAL:-30 3 * * *}"
4368
# Zulip configuration function specific variable(s)
44-
SPECIAL_SETTING_DETECTION_MODE="${SPECIAL_SETTING_DETECTION_MODE:-}"
45-
MANUAL_CONFIGURATION="${MANUAL_CONFIGURATION:-false}"
46-
LINK_SETTINGS_TO_DATA="${LINK_SETTINGS_TO_DATA:-false}"
69+
SPECIAL_SETTING_DETECTION_MODE="$(normalize_bool SPECIAL_SETTING_DETECTION_MODE)"
70+
MANUAL_CONFIGURATION="$(normalize_bool MANUAL_CONFIGURATION)"
71+
LINK_SETTINGS_TO_DATA="$(normalize_bool LINK_SETTINGS_TO_DATA)"
4772
# entrypoint.sh specific variable(s)
4873
SETTINGS_PY="/etc/zulip/settings.py"
4974

@@ -57,7 +82,7 @@ prepareDirectories() {
5782
ln -sfT "$DATA_DIR/uploads" /home/zulip/uploads
5883
chown zulip:zulip -R "$DATA_DIR/uploads"
5984
# Link settings folder
60-
if [ "$LINK_SETTINGS_TO_DATA" = "True" ] || [ "$LINK_SETTINGS_TO_DATA" = "true" ]; then
85+
if [ "$LINK_SETTINGS_TO_DATA" = "True" ]; then
6186
# Create settings directories
6287
if [ ! -d "$DATA_DIR/settings" ]; then
6388
mkdir -p "$DATA_DIR/settings"
@@ -129,19 +154,19 @@ nginxConfiguration() {
129154
puppetConfiguration() {
130155
echo "Executing puppet configuration ..."
131156

132-
if [ "$DISABLE_HTTPS" == "True" ] || [ "$DISABLE_HTTPS" == "true" ]; then
157+
if [ "$DISABLE_HTTPS" == "True" ]; then
133158
echo "Disabling https in nginx."
134159
crudini --set /etc/zulip/zulip.conf application_server http_only true
135160
fi
136-
if [ "$QUEUE_WORKERS_MULTIPROCESS" == "True" ] || [ "$QUEUE_WORKERS_MULTIPROCESS" == "true" ]; then
161+
if [ "$QUEUE_WORKERS_MULTIPROCESS" == "True" ]; then
137162
echo "Setting queue workers to run in multiprocess mode ..."
138163
crudini --set /etc/zulip/zulip.conf application_server queue_workers_multiprocess true
139-
elif [ "$QUEUE_WORKERS_MULTIPROCESS" == "False" ] || [ "$QUEUE_WORKERS_MULTIPROCESS" == "false" ]; then
164+
else
140165
echo "Setting queue workers to run in multithreaded mode ..."
141166
crudini --set /etc/zulip/zulip.conf application_server queue_workers_multiprocess false
142167
fi
143168

144-
if [ "$TRUST_GATEWAY_IP" == "True" ] || [ "$TRUST_GATEWAY_IP" == "true" ]; then
169+
if [ "$TRUST_GATEWAY_IP" == "True" ]; then
145170
GATEWAY_IP=$(ip route | grep default | awk '{print $3}')
146171
echo "Trusting local network gateway $GATEWAY_IP"
147172
LOADBALANCER_IPS="${LOADBALANCER_IPS:+$LOADBALANCER_IPS,}$GATEWAY_IP"
@@ -315,8 +340,7 @@ zulipConfiguration() {
315340
|| [ "$setting_key" = "ALLOWED_HOSTS" ]; then
316341
type="array"
317342
fi
318-
if [ "$SPECIAL_SETTING_DETECTION_MODE" = "True" ] || [ "$SPECIAL_SETTING_DETECTION_MODE" = "true" ] \
319-
|| [ "$type" = "string" ]; then
343+
if [ "$SPECIAL_SETTING_DETECTION_MODE" = "True" ] || [ "$type" = "string" ]; then
320344
type=""
321345
fi
322346
if [ "$setting_key" = "EMAIL_HOST_USER" ] \
@@ -333,7 +357,7 @@ zulipConfiguration() {
333357
echo "Zulip configuration succeeded."
334358
}
335359
autoBackupConfiguration() {
336-
if [ "$AUTO_BACKUP_ENABLED" != "True" ] && [ "$AUTO_BACKUP_ENABLED" != "true" ]; then
360+
if [ "$AUTO_BACKUP_ENABLED" != "True" ]; then
337361
rm -f /etc/cron.d/autobackup
338362
echo "Auto backup is disabled. Continuing."
339363
return 0
@@ -347,7 +371,7 @@ initialConfiguration() {
347371
puppetConfiguration
348372
nginxConfiguration
349373
configureCerts
350-
if [ "$MANUAL_CONFIGURATION" = "False" ] || [ "$MANUAL_CONFIGURATION" = "false" ]; then
374+
if [ "$MANUAL_CONFIGURATION" = "False" ]; then
351375
# Start with the settings template file.
352376
cp -a /home/zulip/deployments/current/zproject/prod_settings_template.py "$SETTINGS_PY"
353377
databaseConfiguration
@@ -357,7 +381,7 @@ initialConfiguration() {
357381
else
358382
# Check that the configuration will work
359383
root_path="/etc/zulip"
360-
if [ "$LINK_SETTINGS_TO_DATA" = "True" ] || [ "$LINK_SETTINGS_TO_DATA" = "true" ]; then
384+
if [ "$LINK_SETTINGS_TO_DATA" = "True" ]; then
361385
root_path="/data/settings/etc-zulip"
362386
fi
363387
failure=0
@@ -400,7 +424,7 @@ waitingForDatabase() {
400424
}
401425
zulipFirstStartInit() {
402426
echo "Executing Zulip first start init ..."
403-
if [ -e "$DATA_DIR/.initiated" ] && [ "$FORCE_FIRST_START_INIT" != "True" ] && [ "$FORCE_FIRST_START_INIT" != "true" ]; then
427+
if [ -e "$DATA_DIR/.initiated" ] && [ "$FORCE_FIRST_START_INIT" != "True" ]; then
404428
echo "First Start Init not needed. Continuing."
405429
return 0
406430
fi
@@ -432,7 +456,7 @@ zulipMigration() {
432456
}
433457
runPostSetupScripts() {
434458
echo "Post setup scripts execution ..."
435-
if [ "$ZULIP_RUN_POST_SETUP_SCRIPTS" != "True" ] && [ "$ZULIP_RUN_POST_SETUP_SCRIPTS" != "true" ]; then
459+
if [ "$ZULIP_RUN_POST_SETUP_SCRIPTS" != "True" ]; then
436460
echo "Not running post setup scripts. ZULIP_RUN_POST_SETUP_SCRIPTS isn't true."
437461
return 0
438462
fi

0 commit comments

Comments
 (0)