Module: kamailio
Branch: master
Commit: de23dc1035e4b885f45bc4150d282c26b294db64
URL: 
https://github.com/kamailio/kamailio/commit/de23dc1035e4b885f45bc4150d282c26b294db64

Author: Tyler Moore <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2024-04-28T23:14:16+02:00

utils/kamctl: make root host/port configurable

- add support for configuring the DB root host/port connection
  parameters separate from the ro/rw settings. This allows the
  user to authenticate over the specific socket configured
  (tcp/udp/unix) for each connection type (root/ro/rw).
- note that support is added for mysql and postgresql connections.
  no changes to the other DB engine connection parameters.

---

Modified: utils/kamctl/kamctlrc
Modified: utils/kamctl/kamdbctl.base
Modified: utils/kamctl/kamdbctl.mysql
Modified: utils/kamctl/kamdbctl.pgsql

---

Diff:  
https://github.com/kamailio/kamailio/commit/de23dc1035e4b885f45bc4150d282c26b294db64.diff
Patch: 
https://github.com/kamailio/kamailio/commit/de23dc1035e4b885f45bc4150d282c26b294db64.patch

---

diff --git a/utils/kamctl/kamctlrc b/utils/kamctl/kamctlrc
index ce0bd9d93bc..67af483d9c6 100644
--- a/utils/kamctl/kamctlrc
+++ b/utils/kamctl/kamctlrc
@@ -44,6 +44,14 @@
 ## database access host (from where is kamctl used)
 # DBACCESSHOST=192.168.0.1
 
+## database host for super user (useful for specifying a local socket or 
virtual hostname)
+# defaults to value of DBHOST when not set
+# DBROOTHOST="localhost"
+
+## database port for super user (on some DB specifying the port will force TCP 
connections)
+# default value will depend on client DB tool
+# DBROOTPORT=""
+
 ## database super user (for ORACLE this is 'scheme-creator' user)
 # DBROOTUSER="root"
 
diff --git a/utils/kamctl/kamdbctl.base b/utils/kamctl/kamdbctl.base
index 4a3beccaef4..5579c9e8373 100644
--- a/utils/kamctl/kamdbctl.base
+++ b/utils/kamctl/kamdbctl.base
@@ -20,6 +20,9 @@ DBROUSER=${DBROUSER:-kamailioro}
 # password for read-only user
 DBROPW=${DBROPW:-kamailioro}
 
+# address of database server for root connections
+DBROOTHOST=${DBROOTHOST:-$DBHOST}
+
 # user name column
 USERCOL=${USERCOL:-username}
 
diff --git a/utils/kamctl/kamdbctl.mysql b/utils/kamctl/kamdbctl.mysql
index 81a730bbe65..49915dc7954 100644
--- a/utils/kamctl/kamdbctl.mysql
+++ b/utils/kamctl/kamdbctl.mysql
@@ -27,23 +27,22 @@ fi
 # config vars
 #################################################################
 
-# full privileges MySQL user
-if [ -z "$DBROOTUSER" ]; then
-       DBROOTUSER="root"
-fi
-
 # Set DBROOTPW in kamctlrc or via next line to set the database
 # root password if you want to run this script without any user prompt.
 # This is unsafe, but useful e.g. for automatic testing.
 #DBROOTPW=""
 
-
-if [ -z "$DBPORT" ] ; then
-       CMD="mysql -h $DBHOST -u$DBROOTUSER "
-       DUMP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c -t "
-else
-       CMD="mysql -h $DBHOST -P $DBPORT -u$DBROOTUSER "
-       DUMP_CMD="mysqldump -h $DBHOST -P $DBPORT -u$DBROOTUSER -c -t "
+# build the client base commands one param at a time
+# let the client choose defaults where not specified
+CMD="mysql -h $DBROOTHOST"
+DUMP_CMD="mysqldump -c -t -h $DBROOTHOST"
+if [ -n "$DBROOTPORT" ] ; then
+       CMD="$CMD -P $DBROOTPORT"
+       DUMP_CMD="$DUMP_CMD -P $DBROOTPORT"
+fi
+if [ -n "$DBROOTUSER" ]; then
+       CMD="$CMD -u $DBROOTUSER"
+       DUMP_CMD="mysqldump -u $DBROOTUSER"
 fi
 
 #################################################################
diff --git a/utils/kamctl/kamdbctl.pgsql b/utils/kamctl/kamdbctl.pgsql
index 1eb5d88d2b8..3b46c04294f 100644
--- a/utils/kamctl/kamdbctl.pgsql
+++ b/utils/kamctl/kamdbctl.pgsql
@@ -51,12 +51,12 @@ if [ -z "$DBROOTUSER" ]; then
        fi
 fi
 
-if [ -z "$DBPORT" ] ; then
-       CMD="psql -q -h $DBHOST -U $DBROOTUSER "
-       DUMP_CMD="pg_dump -h $DBHOST -U $DBROOTUSER -c"
+if [ -z "$DBROOTPORT" ] ; then
+       CMD="psql -q -h $DBROOTHOST -U $DBROOTUSER "
+       DUMP_CMD="pg_dump -h $DBROOTHOST -U $DBROOTUSER -c"
 else
-       CMD="psql -q -h $DBHOST -p $DBPORT -U $DBROOTUSER "
-       DUMP_CMD="pg_dump -h $DBHOST -p $DBPORT -U $DBROOTUSER -c"
+       CMD="psql -q -h $DBROOTHOST -p $DBROOTPORT -U $DBROOTUSER "
+       DUMP_CMD="pg_dump -h $DBROOTHOST -p $DBROOTPORT -U $DBROOTUSER -c"
 fi
 
 #################################################################

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to [email protected]

Reply via email to