Get the distmaker working with npm and bower.
[civicrm-core.git] / bin / setup.sh
CommitLineData
6a488035 1#!/usr/bin/env bash
5e43f8f4 2set -e
55f7d1ec 3set -x
6a488035
TO
4
5CALLEDPATH=`dirname $0`
6
7# Convert to an absolute path if necessary
8case "$CALLEDPATH" in
9 .*)
10 CALLEDPATH="$PWD/$CALLEDPATH"
11 ;;
12esac
13
ea16a823
TO
14if [ ! -f "$CALLEDPATH/setup.conf" ]; then
15 echo
16 echo "Missing configuration file. Please copy $CALLEDPATH/setup.conf.txt to $CALLEDPATH/setup.conf and edit it."
17 exit 1
18fi
19
6a488035 20source "$CALLEDPATH/setup.conf"
55f7d1ec 21source "$CALLEDPATH/setup.lib.sh"
6a488035
TO
22
23if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
28c32cc5 24 echo; echo Usage: setup.sh [schema file] [database data file] [database name] [database user] [database password] [database host] [database port] [additional args]; echo
6a488035
TO
25 exit 0
26fi
27
28
29# fetch command line arguments if available
5e43f8f4
TO
30if [ ! -z "$1" ] ; then SCHEMA="$1"; fi
31if [ ! -z "$2" ] ; then DBLOAD="$2"; fi
32if [ ! -z "$3" ] ; then DBNAME="$3"; fi
33if [ ! -z "$4" ] ; then DBUSER="$4"; fi
34if [ ! -z "$5" ] ; then DBPASS="$5"; fi
28c32cc5
PH
35if [ ! -z "$6" ] ; then DBHOST="$6"; fi
36if [ ! -z "$7" ] ; then DBPORT="$7"; fi
6a488035
TO
37
38# verify if we have at least DBNAME given
39if [ -z $DBNAME ] ; then
40 echo "No database name defined!"
41 exit 1
42fi
43if [ -z $DBUSER ] ; then
44 echo "No database username defined!"
45 exit 1
46fi
47if [ -z $DBPASS ] ; then
48 read -p "Database password:"
49 DBPASS=$REPLY
50fi
51
52# run code generator if it's there - which means it's
53# checkout, not packaged code
5e43f8f4
TO
54if [ -d "$CALLEDPATH/../xml" ]; then
55 cd "$CALLEDPATH/../xml"
f3a22910
TO
56 if [ -z "$DBPORT" ]; then
57 PHP_MYSQL_HOSTPORT="$DBHOST"
58 else
59 PHP_MYSQL_HOSTPORT="$DBHOST:$DBPORT"
60 fi
55f7d1ec 61 "$PHP5PATH"php -d mysql.default_host="$PHP_MYSQL_HOSTPORT" -d mysql.default_user=$DBUSER -d mysql.default_password=$DBPASS GenCode.php $SCHEMA '' ${GENCODE_CMS}
28c32cc5
PH
62fi
63
5e43f8f4 64cd "$CALLEDPATH/../sql"
6a488035
TO
65echo; echo "Dropping civicrm_* tables from database $DBNAME"
66# mysqladmin -f -u $DBUSER $PASSWDSECTION $DBARGS drop $DBNAME
55f7d1ec 67MYSQLCMD=$(mysql_cmd)
6a488035
TO
68echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'VIEW'" \
69 | $MYSQLCMD \
70 | grep '^\(civicrm_\|log_civicrm_\)' \
71 | awk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop view " $1 ";"}' \
72 | $MYSQLCMD
73echo "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_TYPE = 'BASE TABLE'" \
74 | $MYSQLCMD \
75 | grep '^\(civicrm_\|log_civicrm_\)' \
76 | awk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}' \
77 | $MYSQLCMD
78
79
80echo; echo Creating database structure
28c32cc5 81$MYSQLCMD < civicrm.mysql
6a488035
TO
82
83# load civicrm_generated.mysql sample data unless special DBLOAD is passed
84if [ -z $DBLOAD ]; then
85 echo; echo Populating database with example data - civicrm_generated.mysql
28c32cc5 86 $MYSQLCMD < civicrm_generated.mysql
6a488035
TO
87else
88 echo; echo Populating database with required data - civicrm_data.mysql
28c32cc5 89 $MYSQLCMD < civicrm_data.mysql
6a488035 90 echo; echo Populating database with $DBLOAD data
28c32cc5 91 $MYSQLCMD < $DBLOAD
6a488035
TO
92fi
93
94# load additional script if DBADD defined
95if [ ! -z $DBADD ]; then
96 echo; echo Loading $DBADD
28c32cc5 97 $MYSQLCMD < $DBADD
6a488035
TO
98fi
99
100# run the cli script to build the menu and the triggers
863efcd6 101cd "$CALLEDPATH/.."
6a488035
TO
102"$PHP5PATH"php bin/cli.php -e System -a flush --triggers 1 --session 1
103
783f84c9 104# reset config_backend and userFrameworkResourceURL which gets set
6a488035 105# when config object is initialized
28c32cc5 106$MYSQLCMD -e "UPDATE civicrm_domain SET config_backend = NULL; UPDATE civicrm_setting SET value = NULL WHERE name = 'userFrameworkResourceURL';"
6a488035
TO
107
108echo; echo "Setup Complete. Logout from your CMS to avoid session conflicts."
109