#!/bin/sh
#
# Set up jwchat to work out of the box.

set -e

# Set hostname for ejabberd and jwchat
echo "ejabberd ejabberd/hostname string `cat /etc/hostname`" | debconf-set-selections
echo "jwchat jwchat/ApacheServerName string `cat /etc/hostname`" | debconf-set-selections

# An alternative XMPP server is prosody
apt-get install -y jwchat ejabberd

# Enable BOSH module for ejabberd
if ! grep -q mod_http_bind /etc/ejabberd/ejabberd.cfg ; then
    sed -i '/mod_last/i \
  {mod_http_bind, []},' /etc/ejabberd/ejabberd.cfg
fi

# We'll use another site to serve jwchat.
a2dissite jwchat

# Remove SSL keys from images, will be generated on first boot.
rm -f /etc/ejabberd/ejabberd.pem
