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

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

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

# Update package information
apt-get update

# Install gnupg to required to add bigbluebutton package key
apt-get -y install gnupg

# Add the package key
wget http://archive.bigbluebutton.org/bigbluebutton.asc
apt-key add bigbluebutton.asc

# add the archive for BigBlueButton Ubuntu 10.04
echo "deb http://archive.bigbluebutton.org/lucid bigbluebutton-lucid main" > /etc/apt/sources.list.d/bigbluebutton.list

# Ensure the multiverse is in the souces list (needed for msttcorefonts)
echo "deb http://archive.ubuntu.com/ubuntu/ lucid multiverse" >> /etc/apt/sources.list.d/sources.list

#Install required packages
install asterisk bigbluebutton ghostscript

#Stop al running services
service mysql stop
service nginx stop
service tomcat6 stop
service red5 stop
service asterisk stop
service activemq stop
service bbb-openoffice-headless stop

#Clean apt cache
cleanup_apt
