5
## no local DB so we're gonna run this at config-changed for now
8
juju-log "We've got a db"
9
hostname=`unit-get public-address`
10
private_name=`hostname -f`
11
juju-log "Retrieved hostname: $hostname"
13
# Check we haven't already been setup.
14
wp_install_path="/var/www/omgubuntu.co.uk"
15
config_file_path="$wp_install_path/wp-config.php"
16
config_info_path="$wp_install_path/wp-info.php"
18
if [ -f "$config_file_path" ]; then
19
juju-log "OMG Ubuntu is already setup, just silently going away"
23
#database=`relation-get database`
24
#user=`relation-get user`
25
#password=`relation-get password`
26
#host=`relation-get private-address`
30
password='omgnolove68';
31
host='ohso-omgdb.chxmcwfnhnyn.eu-west-1.rds.amazonaws.com';
33
if [ -z "$database" ] ; then
37
S3_BUCKET=`config-get s3-bucket`
39
secret_key=`pwgen 10 1`
40
secret_key='ileingeiru';
42
source "/usr/share/charm-helper/sh/net.sh"
45
# OH COME ON WORDPRESS.ORG NO VALID SSL CERTIFICATE?
46
# Psh, whatever, plain-text for now. #blamenacin
47
# https://twitter.com/#!/marcoceppi/status/181570187655520260
48
LATEST_WORDPRESS="http://wordpress.org/latest.tar.gz"
49
DOWNLOAD=`ch_get_file "$LATEST_WORDPRESS" "http://wordpress.org/latest.tar.gz.sha1"`
52
if [ ! -f "$DOWNLOAD" ] || [ -z "$DOWNLOAD" ]; then
53
juju-log "Failed to retrieve $LATEST_WORDPRESS"
57
juju-log "Extract ALL THE FILES"
60
mkdir -p $wp_install_path
62
juju-log "Move them in to place, but just 'drop' them in place."
63
rsync -az wordpress/ $wp_install_path
68
juju-log "Dropping OMG specific files: Themes, plugins, etc in to position"
69
rsync -az files/wordpress/ $wp_install_path
71
juju-log "Writing wordpress config file $config_file_path"
72
# Write the wordpress config
73
cat > $config_info_path <<EOF
75
define('DB_NAME', 'omgubuntu');
76
define('DB_USER', 'omgubu');
77
define('DB_PASSWORD', 'omgnolove68');
78
define('DB_HOST', 'ohso-omgdb.chxmcwfnhnyn.eu-west-1.rds.amazonaws.com');
79
define('SECRET_KEY', 'ileingeiru');
81
define('WP_CACHE', true);
84
define('AUTH_KEY', '$secret_key');
85
define('SECURE_AUTH_KEY', '$secret_key');
86
define('LOGGED_IN_KEY', '$secret_key');
87
define('NONCE_KEY', '$secret_key');
90
\$table_prefix = 'wp_';
94
cat > $config_file_path <<EOF
97
/* That's all, stop editing! Happy blogging. */
99
/** Absolute path to the WordPress directory. */
100
if ( !defined('ABSPATH') )
101
define('ABSPATH', dirname(__FILE__) . '/');
103
/** Pull in the config information */
104
require_once(ABSPATH . 'wp-info.php');
106
/** Sets up WordPress vars and included files. */
107
require_once(ABSPATH . 'wp-settings.php');
109
remove_filter('template_redirect', 'redirect_canonical');
112
chmod 0644 $config_file_path
114
juju-log "Enabling apache site: $hostname"
116
chown -R www-data.www-data $wp_install_path
118
#if [ ! -f /etc/cron.daily/omg-backup ]; then
119
# uju-log "Put the backup process in place"
120
# rsync -az files/omg-backup /etc/cron.daily/
121
# chmod 0755 /etc/cron.daily/omg-backup
124
#sed -i -e "s@DB_HOST=\".*\"@DB_HOST=\"$host\"@" \
125
# -e "s@DB_USER=\".*\"@DB_USER=\"$user\"@" \
126
# -e "s@DB_PASS=\".*\"@DB_PASS=\"$password\"@" \
127
# -e "s@DB_NAME=\".*\"@DB_NAME=\"$database\"@" \
128
# -e "s@S3_BUCKET=\".*\"@S3_BUCKET=\"$S3_BUCKET\"@" \
129
# /etc/cron.daily/omg-backup
131
cat "* * * * * /usr/bin/php -q /var/www/omgubuntu.co.uk/cron/post_flush.php" > /var/spool/cron/crontabs/root
134
juju-log "Restarting cron"
138
juju-log "Restarting nginx service"
139
service nginx restart
140
service php5-fpm restart
142
# Make it publicly visible, once the wordpress service is exposed