#!/bin/bash 
install()
{
    apt-get update
    DEBIAN_FRONTEND=noninteractive apt-get -y \
        -o DPkg::Options::=--force-confdef \
        -o DPkg::Options::=--force-confold \
        install $@
}

cleanup_apt()
{
    rm -r /var/cache/apt/*
    mkdir /var/cache/apt/archives
    mkdir /var/cache/apt/archives/partial
}

# Set Hostname
HOSTNAME=plone
echo "$HOSTNAME" > /etc/hostname
sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts
hostname plone

# Install required packages
install python-dev python-imaging postfix ssl-cert build-essential libjpeg-dev libreadline-dev apache2

# Get Plone 4 installer and untar
wget http://launchpad.net/plone/4.0/4.0.0/+download/Plone-4.0-UnifiedInstaller.tgz
tar xvzf Plone-4.0-UnifiedInstaller.tgz
cd Plone-4.0-UnifiedInstaller/

#install plone
./install.sh --with-python=/usr/bin/python --password=turnkey zeo
update-rc.d plone defaults

#Enable apache modules
a2enmod proxy_http rewrite ssl

#Enable site
a2dissite default
a2dissite default-ssl
a2ensite plone
a2ensite plone-ssl

#Remove unused files
cd ..
rm -Rf Plone-4.0-UnifiedInstaller

# Clean apt cache and sources
cleanup_apt
