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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash

set -e

# Retrieve this machine's hostname
HOSTNAME=`unit-get public-address`
juju-log "Hostname: $HOSTNAME"

# Retrieve the settings from the database
juju-log "Retrieving database relationship"
DATABASE=`relation-get database`

if [ -z "$DATABASE" ] ; then
    juju-log "No database relationship set"
    exit 0
fi

# Fetch the database configuration
juju-log "Retrieving database configuration"
DB_USER=`relation-get user`
DB_PASS=`relation-get password`
DB_HOST=`relation-get private-address`

# Update the data in the configuration file
juju-log "Updating configuration file"
update_thinkup_config <<EOD
db_host='$DB_HOST'
db_user='$DB_USER'
db_password='$DB_PASS'
db_name='$DATABASE'
EOD

# Execute the SQL that creates the tables
juju-log "Creating database tables"
mysql -u$DB_USER -p$DB_PASS -h$DB_HOST $DATABASE < /var/www/install/sql/build-db_mysql.sql