瀏覽代碼

kamctl: added options to kamctlrc to set db cli and params

- implemented for mysql and postgress
- GH #4376
Daniel-Constantin Mierla 4 天之前
父節點
當前提交
058bc32af9
共有 5 個文件被更改,包括 47 次插入29 次删除
  1. 13 10
      utils/kamctl/kamctl.mysql
  2. 13 10
      utils/kamctl/kamctl.pgsql
  3. 6 0
      utils/kamctl/kamctlrc
  4. 4 1
      utils/kamctl/kamdbctl.mysql
  5. 11 8
      utils/kamctl/kamdbctl.pgsql

+ 13 - 10
utils/kamctl/kamctl.mysql

@@ -21,12 +21,16 @@ fi
 ##### ----------------------------------------------- #####
 ### binaries
 if [ -z "$MYSQL" ] ; then
-	locate_tool mysql
-	if [ -z "$TOOLPATH" ] ; then
-		echo "error: 'mysql' tool not found: set MYSQL variable to correct tool path"
-		exit
+	if [ -z "$DBCLI" ] ; then
+		locate_tool mysql
+		if [ -z "$TOOLPATH" ] ; then
+			echo "error: 'mysql' tool not found: set MYSQL variable to correct tool path"
+			exit
+		fi
+		MYSQL="$TOOLPATH"
+	else
+		MYSQL="$DBCLI"
 	fi
-	MYSQL="$TOOLPATH"
 fi
 
 # input: sql query, optional mysql command-line params
@@ -34,18 +38,18 @@ mysql_query() {
 	# if password not yet queried, query it now
 	prompt_pw "MySQL password for user '$DBRWUSER@$DBHOST'"
 	if [ -z "$DBPORT" ] ; then
-		$MYSQL $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
+		$MYSQL $DBCLIPARAMS $2 -h $DBHOST -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
 	else
-		$MYSQL $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
+		$MYSQL $DBCLIPARAMS $2 -h $DBHOST -P $DBPORT -u $DBRWUSER "-p$DBRWPW" -e "$1 ;" $DBNAME
 	fi
 }
 
 # input: sql query, optional mysql command-line params
 mysql_ro_query() {
 	if [ -z "$DBPORT" ] ; then
-		$MYSQL $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
+		$MYSQL $DBCLIPARAMS $2 -h $DBHOST -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
 	else
-		$MYSQL $2 -h $DBHOST -P $DBPORT -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
+		$MYSQL $DBCLIPARAMS $2 -h $DBHOST -P $DBPORT -u $DBROUSER "-p$DBROPW" -e "$1 ;" $DBNAME
 	fi
 }
 
@@ -63,4 +67,3 @@ DBCMD=mysql_query
 DBROCMD=mysql_ro_query
 DBRAWPARAMS="-B"
 DBCMDCONNECT=mysql_connect
-

+ 13 - 10
utils/kamctl/kamctl.pgsql

@@ -21,12 +21,16 @@ fi
 ##### ----------------------------------------------- #####
 ### binaries
 if [ -z "$PGSQL" ] ; then
-	locate_tool psql
-	if [ -z "$TOOLPATH" ] ; then
-		echo "error: 'psql' tool not found: set PGSQL variable to correct tool path"
-		exit
+	if [ -z "$DBCLI" ] ; then
+		locate_tool psql
+		if [ -z "$TOOLPATH" ] ; then
+			echo "error: 'psql' tool not found: set PGSQL variable to correct tool path"
+			exit
+		fi
+		PGSQL="$TOOLPATH"
+	else
+		PGSQL="$DBCLI"
 	fi
-	PGSQL="$TOOLPATH"
 fi
 
 
@@ -36,7 +40,7 @@ pgsql_query() {
 	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 [ -z "$DBPORT" ] ; then
-		PGPASSWORD="$DBRWPW" $PGSQL $2 \
+		PGPASSWORD="$DBRWPW" $PGSQL $DBCLIPARAMS $2 \
 			-A -q -t \
 			-P fieldsep="	" \
 			-h $DBHOST \
@@ -44,7 +48,7 @@ pgsql_query() {
 			$DBNAME \
 			-c "$1"
 	else
-		PGPASSWORD="$DBRWPW" $PGSQL $2 \
+		PGPASSWORD="$DBRWPW" $PGSQL $DBCLIPARAMS $2 \
 			-A -q -t \
 			-P fieldsep="	" \
 			-h $DBHOST \
@@ -59,14 +63,14 @@ pgsql_query() {
 pgsql_ro_query() {
 	mdbg "pgsql_ro_query: $PGSQL $2 -A -q -t -h $DBHOST -U $DBROUSER $DBNAME -c '$1'"
 	if [ -z "$DBPORT" ] ; then
-		PGPASSWORD="$DBROPW" $PGSQL $2 \
+		PGPASSWORD="$DBROPW" $PGSQL $DBCLIPARAMS $2 \
 			-A -q -t \
 			-h $DBHOST \
 			-U $DBROUSER \
 			$DBNAME \
 			-c "$1"
 	else
-		PGPASSWORD="$DBROPW" $PGSQL $2 \
+		PGPASSWORD="$DBROPW" $PGSQL $DBCLIPARAMS $2 \
 			-A -q -t \
 			-h $DBHOST \
 			-p $DBPORT \
@@ -79,4 +83,3 @@ pgsql_ro_query() {
 DBCMD=pgsql_query
 DBROCMD=pgsql_ro_query
 DBRAWPARAMS="-A -q -t"
-

+ 6 - 0
utils/kamctl/kamctlrc

@@ -63,6 +63,12 @@
 ## option to ask confirmation for all database creation steps
 # DBINITASK=yes
 
+## database client command
+# DBCLI="mysql"
+
+## additional parameters to database client command
+# DBCLIPARAMS=""
+
 ## database character set (used by MySQL when creating database)
 #CHARSET="latin1"
 

+ 4 - 1
utils/kamctl/kamdbctl.mysql

@@ -34,7 +34,10 @@ fi
 
 # build the client base commands one param at a time
 # let the client choose defaults where not specified
-CMD="mysql -h $DBROOTHOST"
+if [ -z "$DBCLI" ] ; then
+	DBCLI="mysql"
+fi
+CMD="$DBCLI $DBCLIPARAMS -h $DBROOTHOST"
 DUMP_CMD="mysqldump -c -t -h $DBROOTHOST"
 if [ -n "$DBROOTPORT" ] ; then
 	CMD="$CMD -P $DBROOTPORT"

+ 11 - 8
utils/kamctl/kamdbctl.pgsql

@@ -5,17 +5,17 @@
 # 2006-05-16  added ability to specify MD5 from a configuration file
 #             FreeBSD does not have the md5sum function (norm)
 # 2006-07-14  Corrected syntax from MySQL to Postgres (norm)
-#             moved INDEX creation out of CREATE table statement into 
+#             moved INDEX creation out of CREATE table statement into
 #                  CREATE INDEX (usr_preferences, trusted)
-#             auto_increment isn't valid in Postgres, replaced with 
+#             auto_increment isn't valid in Postgres, replaced with
 #                  local AUTO_INCREMENT
-#             datetime isn't valid in Postgres, replaced with local DATETIME 
-#             split GRANTs for SERWeb tables so that it is only executed 
+#             datetime isn't valid in Postgres, replaced with local DATETIME
+#             split GRANTs for SERWeb tables so that it is only executed
 #                  if SERWeb tables are created
 #             added GRANTs for re_grp table
 #             added CREATE pdt table (from PDT module)
 #             corrected comments to indicate Postgres as opposed to MySQL
-#             made last_modified/created stamps consistent to now() using 
+#             made last_modified/created stamps consistent to now() using
 #                  local TIMESTAMP
 # 2006-10-19  Added address table (bogdan)
 # 2006-10-27  subscriber table cleanup; some columns are created only if
@@ -50,12 +50,15 @@ if [ -z "$DBROOTUSER" ]; then
 		exit 1
 	fi
 fi
+if [ -z "$DBCLI" ] ; then
+	DBCMD="psql"
+fi
 
 if [ -z "$DBROOTPORT" ] ; then
-	CMD="psql -q -h $DBROOTHOST -U $DBROOTUSER "
+	CMD="$DBCLI $DBCLIPARAMS -q -h $DBROOTHOST -U $DBROOTUSER "
 	DUMP_CMD="pg_dump -h $DBROOTHOST -U $DBROOTUSER -c"
 else
-	CMD="psql -q -h $DBROOTHOST -p $DBROOTPORT -U $DBROOTUSER "
+	CMD="$DBCLI $DBCLIPARAMS -q -h $DBROOTHOST -p $DBROOTPORT -U $DBROOTUSER "
 	DUMP_CMD="pg_dump -h $DBROOTHOST -p $DBROOTPORT -U $DBROOTUSER -c"
 fi
 
@@ -97,7 +100,7 @@ sql_query "template1" "drop user \"$DBRWUSER\"; drop user \"$DBROUSER\";"
 
 if [ $? -ne 0 ] ; then
 	mwarn "Could not drop $DBRWUSER or $DBROUSER users, try to continue.."
-else 
+else
 	minfo "Database user deleted"
 fi