#!/bin/bash
set -e # If any command fails, stop execution of the hook with that error
apt-get install -y apache2 php5-cgi php5-mysql curl php5-gd wget libapache2-mod-php5 unzip
dl="https://github.com/salesagility/SuiteCRM/archive/master.zip"
# Grab SuiteCRM from upstream.
juju-log "Fetching $dl"
wget "$dl" -O /tmp/master.zip
# IDEMPOTENCY is very important in all charm hooks, even the install hook.
if [ -f /var/www/suitecrm/config.php ]; then
cp /var/www/suitecrm/config.php /tmp/
rm -rf /var/www/suitecrm
fi
# Extract to a known location
juju-log "Extracting SuiteCRM"
unzip -C /tmp/master.zip -d /var/www/
mv /var/www/SuiteCRM-master* /var/www/suitecrm
if [ -f /tmp/config.php ]; then
mv /tmp/config.php /var/www/suitecrm
fi
if [ -f /var/www/suitecrm/config.php ]; then
chmod 777 /var/www/suitecrm/config.php
fi
chmod -R 777 /var/www/suitecrm/upload
juju-log "Creating apache2 configuration"
cat <<EOF > /etc/apache2/sites-available/suitecrm
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/suitecrm
<Directory /var/www/suitecrm>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/suitecrm.log
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
a2dissite 000-default
a2ensite suitecrm
service apache2 reload
juju-log "Files extracted, waiting for other events before we do anything else!"