#!/bin/bash
set -e # If any command fails, stop execution of the hook with that error
apt-get install -y unzip apache2 php5-cgi php5-mysql curl php5-gd wget libapache2-mod-php5
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 666 /var/www/suitecrm/config.php
fi
mkdir /var/www/suitecrm/cache
chown -R www-data:www-data .
chmod -R 777 /var/www/suitecrm/cache /var/www/suitecrm/custom /var/www/suitecrm/upload /var/www/suitecrm/data /var/www/suitecrm/modules /var/www/suitecrm/include /var/www/suitecrm/config_override.php
juju-log "Creating apache2 configuration"
cat <<EOF > /etc/apache2/sites-available/suitecrm.conf
<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