~george-edison55/charms/oneiric/thinkup/update-to-1-0-2

« back to all changes in this revision

Viewing changes to hooks/db-relation-changed

  • Committer: Nathan Osman
  • Date: 2011-11-21 02:48:41 UTC
  • Revision ID: admin@quickmediasolutions.com-20111121024841-iq5201ijkgsid615
Switched to sed for manipulating the preferences files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
DB_PASS=`relation-get password`
22
22
DB_HOST=`relation-get private-address`
23
23
 
24
 
# Write the database configuration file to disk
25
 
juju-log "Creating database configuration file"
26
 
 
27
 
cat > /var/www/config.db.inc.php <<EOF
28
 
<?php
29
 
\$THINKUP_CFG['db_host']                  = '$DB_HOST';
30
 
\$THINKUP_CFG['db_type']                  = 'mysql';
31
 
\$THINKUP_CFG['db_user']                  = '$DB_USER';
32
 
\$THINKUP_CFG['db_password']              = '$DB_PASS';
33
 
\$THINKUP_CFG['db_name']                  = '$DATABASE';
34
 
\$THINKUP_CFG['db_socket']                = '';
35
 
\$THINKUP_CFG['db_port']                  = '';
36
 
\$THINKUP_CFG['table_prefix']             = 'tu_';
37
 
?>
38
 
EOF
39
 
 
40
 
# Make port 80 available
41
 
juju-log "Opening port 80"
42
 
open-port 80/tcp
 
24
# Update the data in the configuration file
 
25
juju-log "Updating configuration file"
 
26
sed -i -e "s/^\\\$THINKUP_CFG\['db_host'\](\s*)\=.*/\$THINKUP_CFG['db_host']$1= '${DB_HOST}';/" -e "s/^\\\$THINKUP_CFG\['db_user'\](\s*)\=.*/\$THINKUP_CFG['db_user']$1= '${DB_USER}';/" -e "s/^\\\$THINKUP_CFG\['db_password'\](\s*)\=.*/\$THINKUP_CFG['db_password']$1= '${DB_PASS}';/" -e "s/^\\\$THINKUP_CFG\['db_name'\](\s*)\=.*/\$THINKUP_CFG['db_name']$1= '${DATABASE}';/" /var/www/config.inc.php
 
27
 
 
28
# Execute the SQL that creates the tables
 
29
juju-log "Creating database tables"
 
30
mysql -u$DB_USER -p$DB_PASS -h$DB_HOST $DATABASE < /var/www/install/sql/build-db_mysql.sql