kamctl: added DBPORT option
[sip-router] / utils / kamctl / kamctl.mysql
1 #
2 #
3 # control tool for maintaining Kamailio
4 #
5 #===================================================================
6
7 ##### ----------------------------------------------- #####
8 ### MySQL specific variables and functions
9 #
10
11 ##### ----------------------------------------------- #####
12 ### load SQL base
13 #
14 if [ -f "$MYLIBDIR/kamctl.sqlbase" ]; then
15         . "$MYLIBDIR/kamctl.sqlbase"
16 else
17         echo "Cannot load SQL core functions '$MYLIBDIR/kamctl.sqlbase' - exiting ..."
18         exit -1
19 fi
20
21 ##### ----------------------------------------------- #####
22 ### binaries
23 if [ -z "$MYSQL" ] ; then
24         locate_tool mysql
25         if [ -z "$TOOLPATH" ] ; then
26                 echo "error: 'mysql' tool not found: set MYSQL variable to correct tool path"
27                 exit
28         fi
29         MYSQL="$TOOLPATH"
30 fi
31
32 # input: sql query, optional mysql command-line params
33 mysql_query() {
34         # if password not yet queried, query it now
35         prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
36         if [ -z "$DBPORT" ] ; then
37                 $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
38         else
39                 $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
40         fi
41 }
42
43 # input: sql query, optional mysql command-line params
44 mysql_ro_query() {
45         if [ -z "$DBPORT" ] ; then
46                 $MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
47         else
48                 $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
49         fi
50 }
51
52 mysql_connect() {
53         # if password not yet queried, query it now
54         prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
55         if [ -z "$DBPORT" ] ; then
56                 $MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" $DBNAME
57         else
58                 $MYSQL $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" $DBNAME
59         fi
60 }
61
62 DBCMD=mysql_query
63 DBROCMD=mysql_ro_query
64 DBRAWPARAMS="-B"
65 DBCMDCONNECT=mysql_connect
66