kamctl: added DBPORT option
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 9 Jan 2017 19:35:47 +0000 (20:35 +0100)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 9 Jan 2017 19:35:47 +0000 (20:35 +0100)
- allows to specify database engine (mysql/psql) port
- requested by GH #916

utils/kamctl/kamctl.mysql
utils/kamctl/kamctl.pgsql
utils/kamctl/kamctlrc
utils/kamctl/kamdbctl.mysql
utils/kamctl/kamdbctl.pgsql

index 7fda5e7..3d33fa9 100644 (file)
@@ -33,18 +33,30 @@ fi
 mysql_query() {
        # if password not yet queried, query it now
        prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
 mysql_query() {
        # if password not yet queried, query it now
        prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
-       $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
+       if [ -z "$DBPORT" ] ; then
+               $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
+       else
+               $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
+       fi
 }
 
 # input: sql query, optional mysql command-line params
 mysql_ro_query() {
 }
 
 # input: sql query, optional mysql command-line params
 mysql_ro_query() {
-       $MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
+       if [ -z "$DBPORT" ] ; then
+               $MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
+       else
+               $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
+       fi
 }
 
 mysql_connect() {
        # if password not yet queried, query it now
        prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
 }
 
 mysql_connect() {
        # if password not yet queried, query it now
        prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
-       $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" $DBNAME
+       if [ -z "$DBPORT" ] ; then
+               $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" $DBNAME
+       else
+               $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" $DBNAME
+       fi
 }
 
 DBCMD=mysql_query
 }
 
 DBCMD=mysql_query
index 60cbd92..7e5abae 100644 (file)
@@ -35,23 +35,43 @@ pgsql_query() {
        # if password not yet queried, query it now
        prompt_pw "PgSQL password for user '$DBRWUSER@$DBHOST'"
        mecho "pgsql_query: $PGSQL $2 -A -q -t -P fieldsep='    ' -h $DBHOST -U $DBRWUSER $DBNAME -c '$1'"
        # if password not yet queried, query it now
        prompt_pw "PgSQL password for user '$DBRWUSER@$DBHOST'"
        mecho "pgsql_query: $PGSQL $2 -A -q -t -P fieldsep='    ' -h $DBHOST -U $DBRWUSER $DBNAME -c '$1'"
-       PGPASSWORD="$DBRWPW" $PGSQL $2 \
-               -A -q -t \
-               -P fieldsep="   " \
-               -h $DBHOST \
-               -U $DBRWUSER \
-               $DBNAME \
-               -c "$1"
+       if [ -z "$DBPORT" ] ; then
+               PGPASSWORD="$DBRWPW" $PGSQL $2 \
+                       -A -q -t \
+                       -P fieldsep="   " \
+                       -h $DBHOST \
+                       -U $DBRWUSER \
+                       $DBNAME \
+                       -c "$1"
+       else
+               PGPASSWORD="$DBRWPW" $PGSQL $2 \
+                       -A -q -t \
+                       -P fieldsep="   " \
+                       -h $DBHOST \
+                       -p $DBPORT \
+                       -U $DBRWUSER \
+                       $DBNAME \
+                       -c "$1"
+       fi
 }
 
 # input: sql query, optional pgsql command-line params
 pgsql_ro_query() {
        mdbg "pgsql_ro_query: $PGSQL $2 -h $DBHOST -U $DBROUSER $DBNAME -c '$1'"
 }
 
 # input: sql query, optional pgsql command-line params
 pgsql_ro_query() {
        mdbg "pgsql_ro_query: $PGSQL $2 -h $DBHOST -U $DBROUSER $DBNAME -c '$1'"
-       PGPASSWORD="$DBROPW" $PGSQL $2 \
-               -h $DBHOST \
-               -U $DBROUSER \
-               $DBNAME \
-               -c "$1"
+       if [ -z "$DBPORT" ] ; then
+               PGPASSWORD="$DBROPW" $PGSQL $2 \
+                       -h $DBHOST \
+                       -U $DBROUSER \
+                       $DBNAME \
+                       -c "$1"
+       else
+               PGPASSWORD="$DBROPW" $PGSQL $2 \
+                       -h $DBHOST \
+                       -p $DBPORT \
+                       -U $DBROUSER \
+                       $DBNAME \
+                       -c "$1"
+       fi
 }
 
 DBCMD=pgsql_query
 }
 
 DBCMD=pgsql_query
index 87a976d..2c9ad5f 100644 (file)
@@ -20,6 +20,9 @@
 ## database host
 # DBHOST=localhost
 
 ## database host
 # DBHOST=localhost
 
+## database host
+# DBPORT=3306
+
 ## database name (for ORACLE this is TNS name)
 # DBNAME=kamailio
 
 ## database name (for ORACLE this is TNS name)
 # DBNAME=kamailio
 
index f8fea39..8d090fc 100644 (file)
@@ -38,8 +38,14 @@ fi
 #PW=""
 
 
 #PW=""
 
 
-CMD="mysql -h $DBHOST -u$DBROOTUSER "
-DUMP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c -t "
+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 "
+fi
+
 #################################################################
 
 
 #################################################################
 
 
index cf3309c..a946f2a 100644 (file)
@@ -51,8 +51,14 @@ if [ -z "$DBROOTUSER" ]; then
        fi
 fi
 
        fi
 fi
 
-CMD="psql -q -h $DBHOST -U $DBROOTUSER "
-DUMP_CMD="pg_dump -h $DBHOST -U $DBROOTUSER -c"
+if [ -z "$DBPORT" ] ; then
+       CMD="psql -q -h $DBHOST -U $DBROOTUSER "
+       DUMP_CMD="pg_dump -h $DBHOST -U $DBROOTUSER -c"
+else
+       CMD="psql -q -h $DBHOST -p $DBHOST -U $DBROOTUSER "
+       DUMP_CMD="pg_dump -h $DBHOST -p $DBHOST -U $DBROOTUSER -c"
+fi
+
 #################################################################
 
 
 #################################################################