regen.sh - Add support for alternate ports (using same configuration as setup.sh)
authorTim Otten <totten@civicrm.org>
Wed, 29 Oct 2014 01:54:49 +0000 (18:54 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 29 Oct 2014 01:56:05 +0000 (18:56 -0700)
bin/regen.sh
bin/setup.lib.sh [new file with mode: 0644]
bin/setup.sh

index 378be1c62a94205666778d2c5e18b29b26317fc7..3717b33dc20a42da3db5fb946613ba725b335206 100755 (executable)
@@ -1,6 +1,9 @@
 #!/usr/bin/env /bin/bash
+set -e
+set -x
 
 source `dirname $0`/setup.conf
+source `dirname $0`/setup.lib.sh
 
 # someone might want to use empty password for development,
 # let's make it possible - we asked before.
@@ -19,7 +22,9 @@ cd $CIVISOURCEDIR/sql
 
 echo; echo "Dropping civicrm_* tables from database $DBNAME"
 # mysqladmin -f -u $DBUSER $PASSWDSECTION $DBARGS drop $DBNAME
-MYSQLCMD="mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME"
+MYSQLCMD=$(mysql_cmd)
+MYSQLADMCMD=$(mysqladmin_cmd)
+MYSQLDUMP=$(mysqldump_cmd)
 echo "SELECT table_name FROM information_schema.TABLES  WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'VIEW'" \
   | $MYSQLCMD \
   | grep '^\(civicrm_\|log_civicrm_\)' \
@@ -31,26 +36,26 @@ echo "SELECT table_name FROM information_schema.TABLES  WHERE TABLE_SCHEMA='${DB
   | awk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}' \
   | $MYSQLCMD
 
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < civicrm.mysql
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < civicrm_data.mysql
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < civicrm_sample.mysql
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < zipcodes.mysql
+$MYSQLCMD < civicrm.mysql
+$MYSQLCMD < civicrm_data.mysql
+$MYSQLCMD < civicrm_sample.mysql
+$MYSQLCMD < zipcodes.mysql
 php GenerateData.php
 
 # run the cli script to build the menu and the triggers
 cd $CIVISOURCEDIR
 "$PHP5PATH"php bin/cli.php -e System -a flush --triggers 1 --session 1
 
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME -e "DROP TABLE zipcodes; UPDATE civicrm_domain SET config_backend = NULL; UPDATE civicrm_setting SET value = NULL WHERE name = 'userFrameworkResourceURL'  OR name = 'imageUploadURL';"
+$MYSQLCMD -e "DROP TABLE zipcodes; UPDATE civicrm_domain SET config_backend = NULL; UPDATE civicrm_setting SET value = NULL WHERE name = 'userFrameworkResourceURL'  OR name = 'imageUploadURL';"
 
 cd $CIVISOURCEDIR/sql
-mysqldump -cent --skip-triggers -u $DBUSER $PASSWDSECTION $DBARGS $DBNAME > civicrm_generated.mysql
+$MYSQLDUMP -cent --skip-triggers $DBNAME > civicrm_generated.mysql
 #cat civicrm_sample_report.mysql >> civicrm_generated.mysql
 cat civicrm_sample_custom_data.mysql >> civicrm_generated.mysql
 #cat civicrm_devel_config.mysql >> civicrm_generated.mysql
 cat civicrm_dummy_processor.mysql >> civicrm_generated.mysql
-mysqladmin -f -u$DBUSER $PASSWDSECTION $DBARGS drop $DBNAME
-mysqladmin -u$DBUSER $PASSWDSECTION $DBARGS create $DBNAME
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < civicrm.mysql
-mysql -u$DBUSER $PASSWDSECTION $DBARGS $DBNAME < civicrm_generated.mysql
+$MYSQLADMCMD -f drop $DBNAME
+$MYSQLADMCMD create $DBNAME
+$MYSQLCMD < civicrm.mysql
+$MYSQLCMD < civicrm_generated.mysql
 popd
diff --git a/bin/setup.lib.sh b/bin/setup.lib.sh
new file mode 100644 (file)
index 0000000..8ee4db0
--- /dev/null
@@ -0,0 +1,34 @@
+function _mysql_vars() {
+  # someone might want to use empty password for development,
+  # let's make it possible - we asked before.
+  if [ -z $DBPASS ]; then # password still empty
+    PASSWDSECTION=""
+  else
+    PASSWDSECTION="-p$DBPASS"
+  fi
+
+  HOSTSECTTION=""
+  if [ ! -z "$DBHOST" ]; then
+    HOSTSECTION="-h $DBHOST"
+  fi
+
+  PORTSECTION=""
+  if [ ! -z "$DBPORT" ]; then
+    PORTSECTION="-P $DBPORT"
+  fi
+}
+
+function mysql_cmd() {
+  _mysql_vars
+  echo "mysql -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS $DBNAME"
+}
+
+function mysqladmin_cmd() {
+  _mysql_vars
+  echo "mysqladmin -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS"
+}
+
+function mysqldump_cmd() {
+  _mysql_vars
+  echo "mysqldump -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS"
+}
\ No newline at end of file
index 45bffaed4752db413ab8d5ffbb9e864b5a01d095..96049cb97088aa2a3068028b89f879c63ab2336f 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
 set -e
+set -x
 
 CALLEDPATH=`dirname $0`
 
@@ -17,6 +18,7 @@ if [ ! -f "$CALLEDPATH/setup.conf" ]; then
 fi
 
 source "$CALLEDPATH/setup.conf"
+source "$CALLEDPATH/setup.lib.sh"
 
 if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
   echo; echo Usage: setup.sh [schema file] [database data file] [database name] [database user] [database password] [database host] [database port] [additional args]; echo
@@ -56,31 +58,13 @@ if [ -d "$CALLEDPATH/../xml" ]; then
   else
     PHP_MYSQL_HOSTPORT="$DBHOST:$DBPORT"
   fi
-  "$PHP5PATH"php -d mysql.default_host="$PHP_MYSQL_HOSTPORT" -d mysql.default_user=$DBUSER -d mysql.default_password=$DBPASS GenCode.php $SCHEMA '' $GENCODE_CMS
-fi
-
-# someone might want to use empty password for development,
-# let's make it possible - we asked before.
-if [ -z $DBPASS ]; then # password still empty
-  PASSWDSECTION=""
-else
-  PASSWDSECTION="-p$DBPASS"
-fi
-
-HOSTSECTTION=""
-if [ ! -z "$DBHOST" ]; then
-  HOSTSECTION="-h $DBHOST"
-fi
-
-PORTSECTION=""
-if [ ! -z "$DBPORT" ]; then
-  PORTSECTION="-P $DBPORT"
+  "$PHP5PATH"php -d mysql.default_host="$PHP_MYSQL_HOSTPORT" -d mysql.default_user=$DBUSER -d mysql.default_password=$DBPASS GenCode.php $SCHEMA '' ${GENCODE_CMS}
 fi
 
 cd "$CALLEDPATH/../sql"
 echo; echo "Dropping civicrm_* tables from database $DBNAME"
 # mysqladmin -f -u $DBUSER $PASSWDSECTION $DBARGS drop $DBNAME
-MYSQLCMD="mysql -u$DBUSER $PASSWDSECTION $HOSTSECTION $PORTSECTION $DBARGS $DBNAME"
+MYSQLCMD=$(mysql_cmd)
 echo "SELECT table_name FROM information_schema.TABLES  WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'VIEW'" \
   | $MYSQLCMD \
   | grep '^\(civicrm_\|log_civicrm_\)' \