cirandas.net

ref: master

debian/noosfero-chat.postinst


#!/bin/bash

set -e

. /usr/share/debconf/confmodule

db_get noosfero-chat/environment
if [ ! -z "$RET" ]; then
  environment="${RET}_production"
else
  environment="production"
fi

domain=$(noosfero-runner 'puts Environment.default.default_hostname(true)' $environment)
echo " [domain = $domain]"

db_get noosfero-chat/admin
if [ ! -z "$RET" ]; then
  admin="$RET@$domain"
else
  admin="admin@$domain"
fi
echo " [admin = $admin]"

ejabberd_config='/etc/ejabberd/ejabberd.yml'
if test -f $ejabberd_config; then
  sed -i "s/HOST_DOMAIN/$domain/" /etc/ejabberd/ejabberd.yml
  sed -i "s/ACL_ADMIN_ACCOUNT/$admin/" /etc/ejabberd/ejabberd.yml
fi

echo -n 'Fetching noosfero database name ...'
noosfero_database=$(noosfero-runner 'puts Environment.connection_config[:database]' $environment)
echo " [database = $noosfero_database]"

echo 'Creating ejabberd schema ...'
. /etc/default/noosfero
noosfero_user="$NOOSFERO_USER"

if dpkg -s postgresql &> /dev/null ; then
  su - postgres -c "psql -c 'GRANT CREATE ON DATABASE $noosfero_database TO $noosfero_user;' > /dev/null"
else
  echo "[W]: No postgres installed. You're probably using noosfero's database in another machine. Make sure user $noosfero_user has CREATE permissions on $noosfero_database database by running:"
  echo " => GRANT CREATE ON DATABASE $noosfero_database TO $noosfero_user;"
fi

su - $noosfero_user -c "rails dbconsole $environment < /usr/share/noosfero/util/chat/postgresql/ejabberd.sql > /dev/null"

if which update-noosfero-odbc &> /dev/null ; then
  update-noosfero-odbc
fi

ejabberd_default='/etc/default/ejabberd'
noosfero_chat_default='/etc/default/noosfero-chat'

if test -f $ejabberd_default; then
  if ! cat $ejabberd_default | grep "^\. $noosfero_chat_default" > /dev/null ; then
    echo 'Extending ejabberd defaults with noosfero-chat defaults ...'
    echo ". $noosfero_chat_default" >> $ejabberd_default
  fi
fi

a2enmod proxy_http

invoke-rc.d ejabberd restart
invoke-rc.d noosfero restart
invoke-rc.d apache2  restart

# stop debconf to avoid the problem with infinite hanging, cfe
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=295477
db_stop

#DEBHELPER#