From: Tim Otten Date: Wed, 29 Oct 2014 01:54:49 +0000 (-0700) Subject: regen.sh - Add support for alternate ports (using same configuration as setup.sh) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=55f7d1ec9cef77db8e66550026bd59862a213157;p=civicrm-core.git regen.sh - Add support for alternate ports (using same configuration as setup.sh) --- diff --git a/bin/regen.sh b/bin/regen.sh index 378be1c62a..3717b33dc2 100755 --- a/bin/regen.sh +++ b/bin/regen.sh @@ -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 index 0000000000..8ee4db00ad --- /dev/null +++ b/bin/setup.lib.sh @@ -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 diff --git a/bin/setup.sh b/bin/setup.sh index 45bffaed47..96049cb970 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -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_\)' \