From 094af5a41e9541f421a838e87ff25fc214e5e2a2 Mon Sep 17 00:00:00 2001
From: Andreas Jonsson <andreas.jonsson@kreablo.se>
Date: Thu, 4 Jul 2019 16:44:34 +0200
Subject: [PATCH] Bug 23141: Parse mysql portnumber from
 /etc/mysql/koha-common.cnf

---
 debian/scripts/koha-create | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create
index 3c51d7df84..fb8fb73366 100755
--- a/debian/scripts/koha-create
+++ b/debian/scripts/koha-create
@@ -152,6 +152,22 @@ getmysqlhost() {
         /etc/mysql/koha-common.cnf
 }
 
+getmysqlport() {
+    if [ -e /etc/mysql/koha-common.cnf ]
+    then
+        port=$(awk '
+            BEGIN { FS="=" }
+            $1 ~/\[/ { inclient=0 }
+            $1 ~/\[client\]/ { inclient=1; next }
+            inclient==1 && $1 ~/port/ { gsub(/ /, "", $2); print $2 }' \
+            /etc/mysql/koha-common.cnf)
+    else
+        port=3306
+    fi
+
+    echo $port
+}
+
 getinstancemysqlpassword() {
     xmlstarlet sel -t -v 'yazgfs/config/pass' "/etc/koha/sites/$1/koha-conf.xml"
 }
@@ -677,6 +693,11 @@ then
     mysqlhost="$(getmysqlhost)"
 fi
 
+if [ "$mysqlport" = "" ]
+then
+    mysqlport="$(getmysqlport)"
+fi
+
 if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ]
 then
     if [ "$mysqlpwd" = "" ]
@@ -765,7 +786,7 @@ eof
         touch "$name-db-request.txt"
         chmod 0600 "$name-db-request.txt"
         cat > "$name-db-request.txt" << eof
-Please create a MySQL database and user on $mysqlhost as follows:
+Please create a MySQL database and user on $mysqlhost port $mysqlport as follows:
 
 database name: $mysqldb
 database user: $mysqluser
-- 
2.29.2