4 CALLEDPATH
=`dirname $0`
6 # Convert to an absolute path if necessary
9 CALLEDPATH
="$PWD/$CALLEDPATH"
13 if [ ! -f "$CALLEDPATH/setup.conf" ]; then
15 echo "Missing configuration file. Please copy $CALLEDPATH/setup.conf.txt to $CALLEDPATH/setup.conf and edit it."
19 source "$CALLEDPATH/setup.conf"
20 source "$CALLEDPATH/setup.lib.sh"
22 if [ "$1" = '-h' ] ||
[ "$1" = '--help' ]; then
24 echo "Usage: setup.sh [options] [schema file] [database data file] [database name] [database user] [database password] [database host] [database port] [additional args]"
25 echo "[options] is a mix of zero or more of following:"
26 echo " -a (All) Implies -Dgsdf (default)"
27 echo " -D (Download) Download depdencies"
28 echo " -g (GenCode) Generate DAO files, SQL files, etc"
29 echo " -s (Schema) Load new schema in DB"
30 echo " -d (Data) Load default data in DB"
31 echo " -f (Flush) Flush caches and settings"
33 echo "Example: Perform a full setup"
36 echo "Example: Setup all the code but leave the DB alone"
39 echo "Example: Keep the existing code but reset the DB"
44 ###############################################################################
45 ## Parse command line options
54 while getopts "aDgsdf" opt
; do
85 echo "Invalid option: -$OPTARG" >&2
89 echo "Option -$OPTARG requires an argument." >&2
94 if [ -z "$FOUND_ACTION" ]; then
104 # fetch command line arguments if available
105 if [ ! -z "$1" ] ; then SCHEMA
="$1"; fi
106 if [ ! -z "$2" ] ; then DBLOAD
="$2"; fi
107 if [ ! -z "$3" ] ; then DBNAME
="$3"; fi
108 if [ ! -z "$4" ] ; then DBUSER
="$4"; fi
109 if [ ! -z "$5" ] ; then DBPASS
="$5"; fi
110 if [ ! -z "$6" ] ; then DBHOST
="$6"; fi
111 if [ ! -z "$7" ] ; then DBPORT
="$7"; fi
113 # verify if we have at least DBNAME given
114 if [ -z $DBNAME ] ; then
115 echo "No database name defined!"
118 if [ -z $DBUSER ] ; then
119 echo "No database username defined!"
122 if [ -z $DBPASS ] ; then
123 read -p "Database password:"
127 MYSQLCMD
=$
(mysql_cmd
)
128 ###############################################################################
132 if [ -n "$DO_DOWNLOAD" ]; then
133 pushd "$CALLEDPATH/.."
135 # Install npm and bower modules
140 # run code generator if it's there - which means it's
141 # checkout, not packaged code
142 if [ -n "$DO_GENCODE" -a -d "$CALLEDPATH/../xml" ]; then
143 pushd "$CALLEDPATH/../xml"
144 if [ -z "$DBPORT" ]; then
145 PHP_MYSQL_HOSTPORT
="$DBHOST"
147 PHP_MYSQL_HOSTPORT
="$DBHOST:$DBPORT"
149 "$PHP5PATH"php
-d mysql.default_host
="$PHP_MYSQL_HOSTPORT" -d mysql.default_user
=$DBUSER -d mysql.default_password
=$DBPASS GenCode.php
$SCHEMA '' ${GENCODE_CMS}
153 if [ -n "$DO_SCHEMA" ]; then
154 pushd "$CALLEDPATH/../sql"
155 echo; echo "Dropping civicrm_* tables from database $DBNAME"
156 echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'VIEW'" \
158 |
grep '^\(civicrm_\|log_civicrm_\)' \
159 |
awk -v NOFOREIGNCHECK
='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop view " $1 ";"}' \
161 echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'BASE TABLE'" \
163 |
grep '^\(civicrm_\|log_civicrm_\)' \
164 |
awk -v NOFOREIGNCHECK
='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}' \
167 echo; echo Creating database structure
168 $MYSQLCMD < civicrm.mysql
172 if [ -n "$DO_DATA" ]; then
173 pushd "$CALLEDPATH/../sql"
174 # load civicrm_generated.mysql sample data unless special DBLOAD is passed
175 if [ -z $DBLOAD ]; then
176 echo; echo Populating database with example data
- civicrm_generated.mysql
177 $MYSQLCMD < civicrm_generated.mysql
179 echo; echo Populating database with required data
- civicrm_data.mysql
180 $MYSQLCMD < civicrm_data.mysql
181 echo; echo Populating database with
$DBLOAD data
185 # load additional script if DBADD defined
186 if [ ! -z $DBADD ]; then
187 echo; echo Loading
$DBADD
193 if [ -n "$DO_FLUSH" ]; then
194 pushd "$CALLEDPATH/.."
195 # run the cli script to build the menu and the triggers
196 "$PHP5PATH"php bin
/cli.php
-e System
-a flush
--triggers 1 --session 1
198 # reset config_backend and userFrameworkResourceURL which gets set
199 # when config object is initialized
200 $MYSQLCMD -e "UPDATE civicrm_domain SET config_backend = NULL; UPDATE civicrm_setting SET value = NULL WHERE name = 'userFrameworkResourceURL';"
204 echo; echo "NOTE: Logout from your CMS to avoid session conflicts."