Skip to content

Commit eb949b1

Browse files
authored
do not allow empty or no password (#29)
Signed-off-by: Alexander Piskun <[email protected]>
1 parent 1efae75 commit eb949b1

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

start.sh

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ if [ ! -f "/haproxy.cfg" ]; then
1515
fi
1616

1717
if [ -n "$NC_HAPROXY_PASSWORD_FILE" ]; then
18-
NC_HAPROXY_PASSWORD=$(mkpasswd -m sha-256 < "$NC_HAPROXY_PASSWORD_FILE")
19-
else
18+
if [ -s "$NC_HAPROXY_PASSWORD_FILE" ]; then
19+
NC_HAPROXY_PASSWORD=$(mkpasswd -m sha-256 < "$NC_HAPROXY_PASSWORD_FILE")
20+
else
21+
echo "Error: NC_HAPROXY_PASSWORD_FILE is specified but is empty."
22+
exit 1
23+
fi
24+
elif [ -n "$NC_HAPROXY_PASSWORD" ]; then
2025
NC_HAPROXY_PASSWORD=$(echo "$NC_HAPROXY_PASSWORD" | mkpasswd -m sha-256)
26+
else
27+
echo "Error: Either NC_HAPROXY_PASSWORD_FILE or NC_HAPROXY_PASSWORD must be set and contain a password."
28+
exit 1
2129
fi
2230

2331
export NC_HAPROXY_PASSWORD
@@ -26,14 +34,14 @@ if [ ! -f "/haproxy.cfg" ]; then
2634
envsubst < /haproxy_ex_apps.cfg.template > /haproxy_ex_apps.cfg
2735

2836
if [ -f "/certs/cert.pem" ]; then
29-
EX_APPS_COUNT_PADDED=$(printf "%03d" "$EX_APPS_COUNT")
30-
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6 ssl crt /certs/cert.pem|" /haproxy.cfg
31-
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:23000-23$EX_APPS_COUNT_PADDED v4v6 ssl crt /certs/cert.pem|" /haproxy_ex_apps.cfg
32-
sed -i "s|EX_APPS_NET_PLACEHOLDER|$EX_APPS_NET|" /haproxy_ex_apps.cfg
33-
# Chmod certs to be accessible by haproxy
34-
chmod 644 /certs/cert.pem
37+
EX_APPS_COUNT_PADDED=$(printf "%03d" "$EX_APPS_COUNT")
38+
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6 ssl crt /certs/cert.pem|" /haproxy.cfg
39+
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:23000-23$EX_APPS_COUNT_PADDED v4v6 ssl crt /certs/cert.pem|" /haproxy_ex_apps.cfg
40+
sed -i "s|EX_APPS_NET_PLACEHOLDER|$EX_APPS_NET|" /haproxy_ex_apps.cfg
41+
# Chmod certs to be accessible by haproxy
42+
chmod 644 /certs/cert.pem
3543
else
36-
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6|" /haproxy.cfg
44+
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6|" /haproxy.cfg
3745
fi
3846
else
3947
echo "HaProxy config already present."
@@ -49,5 +57,6 @@ else
4957
cat /haproxy.cfg
5058
haproxy -f /haproxy.cfg -db
5159
fi
60+
5261
echo "HaProxy quit unexpectedly"
5362
exit 1

0 commit comments

Comments
 (0)