git » chasquid » commit 607ea44

docker: Set the hostname option unconditionally

author Alberto Bertogli
2021-02-22 23:41:06 UTC
committer Alberto Bertogli
2021-02-23 00:21:55 UTC
parent e7a5a4875c1bc6fdc9f8362a737939172dcdea3f

docker: Set the hostname option unconditionally

In commit 5305d584 we fixed an issue with the way the Docker image
adds the "hostname" option to chasquid.conf.

Currently, the Docker entrypoint sets the "hostname" option in
chasquid.conf if it's missing.

That works fine, except when there is a configuration change and the
domain is removed. In that case, the hostname option will have a stale
value, forcing the user to re-create the container, which can be
cumbersome.

This patch fixes the issue by unconditionally setting the hostname
option to one of the available domains at the time of start up.

Thanks to Jaywann@github for finding and reporting this problem on
https://github.com/albertito/chasquid/issues/16, and suggesting an
alternative fix!

docker/entrypoint.sh +4 -3

diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index a14f578..3bb9e9f 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -95,9 +95,10 @@ done >> /etc/dovecot/auto-ssl.conf
 # Pick the default domain as default hostname for chasquid. This is only used
 # in plain text sessions and on very rare cases, and it's mostly for aesthetic
 # purposes.
-if ! grep -iq "hostname:" /etc/chasquid/chasquid.conf; then
-	echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf
-fi
+# Since the list of domains could have changed since the last run, always
+# remove and re-add the setting for consistency.
+sed -i '/^hostname:/d' /etc/chasquid/chasquid.conf
+echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf
 
 # Start the services: dovecot in background, chasquid in foreground.
 start-stop-daemon --start --quiet --pidfile /run/dovecot.pid \