From 16358fdb8353d56733db07b7bd2c25420fe69497 Mon Sep 17 00:00:00 2001
From: Vincent Massol <vincent@massol.net>
Date: Tue, 9 Jun 2020 16:36:11 +0200
Subject: [PATCH] XDOCKER-131: docker-entrypoint doen't set database * Fix bug

---
 11/mysql-tomcat/xwiki/docker-entrypoint.sh    | 5 +++++
 11/postgres-tomcat/xwiki/docker-entrypoint.sh | 5 +++++
 12/mysql-tomcat/xwiki/docker-entrypoint.sh    | 5 +++++
 12/postgres-tomcat/xwiki/docker-entrypoint.sh | 5 +++++
 template/xwiki/docker-entrypoint.sh           | 4 ++--
 5 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/11/mysql-tomcat/xwiki/docker-entrypoint.sh b/11/mysql-tomcat/xwiki/docker-entrypoint.sh
index 8f8685a..e8de6d1 100755
--- a/11/mysql-tomcat/xwiki/docker-entrypoint.sh
+++ b/11/mysql-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/11/postgres-tomcat/xwiki/docker-entrypoint.sh b/11/postgres-tomcat/xwiki/docker-entrypoint.sh
index 8f8685a..e8de6d1 100755
--- a/11/postgres-tomcat/xwiki/docker-entrypoint.sh
+++ b/11/postgres-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/12/mysql-tomcat/xwiki/docker-entrypoint.sh b/12/mysql-tomcat/xwiki/docker-entrypoint.sh
index 8f8685a..e8de6d1 100755
--- a/12/mysql-tomcat/xwiki/docker-entrypoint.sh
+++ b/12/mysql-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/12/postgres-tomcat/xwiki/docker-entrypoint.sh b/12/postgres-tomcat/xwiki/docker-entrypoint.sh
index 8f8685a..e8de6d1 100755
--- a/12/postgres-tomcat/xwiki/docker-entrypoint.sh
+++ b/12/postgres-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh
index 88a04b5..cdfdbac 100755
--- a/template/xwiki/docker-entrypoint.sh
+++ b/template/xwiki/docker-entrypoint.sh
@@ -129,8 +129,8 @@ function configure() {
   safesed "replacedatabase" \$DB_DATABASE /usr/local/tomcat/webapps/\$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
   # Set any non-default main wiki database name in the xwiki.cfg file.
-  if [ "$DB_DATABASE" != "xwiki" ]; then
-    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  if [ "\$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" \$DB_DATABASE
   fi
 
   echo '  Generating authentication validation and encryption keys...'
-- 
GitLab