#!/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

# setup jwchat apache conf
cat > /etc/apache2/conf-available/jwchat.conf <<'EOF'
Alias /jwchat /usr/share/jwchat/www

<Directory /usr/share/jwchat/www>
    Options +Indexes +Multiviews +FollowSymLinks
</Directory>

# proxy for BOSH server
ProxyPass /http-bind/ http://localhost:5280/http-bind/
ProxyPassReverse /http-bind/ http://localhost:5280/http-bind/
<Proxy *>
    Allow from all
</Proxy>
EOF

a2dissite jwchat
a2enconf jwchat

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