debian/noosfero.postinst
#!/bin/sh
set -e
makedir() {
if [ ! -d $1 ]; then
mkdir $1
fi
chown noosfero:noosfero $1
}
# migrate thin configuration to unicorn
unicorn_config=/etc/noosfero/unicorn.rb
thin_config=/etc/noosfero/thin.yml
thin_orig_sha1=47cee6728a7896a13f4d66544086ab88b02e89a7
if [ -r $thin_config ]; then
thin_sha1=$(sha1sum $thin_config | awk '{print $1}')
if [ "$thin_sha1" != "$thin_orig_sha1" ]; then
port=$(awk '{ if ($1 == "port:") { print($2) } }' $thin_config)
servers=$(awk '{ if ($1 == "servers:") { print($2) } }' $thin_config)
if test -n "$port" && test "$port" -ne 50000 || test -n "$servers" && test "$servers" -ne 1 ; then
# thin configuration was changed; update unicorn configuration
# accordingly
sed -i -e "s/listen.*/listen '127.0.0.1:$port'/" $unicorn_config
sed -i -e "s/worker_processes.*/worker_processes $servers/" $unicorn_config
fi
fi
mv $thin_config $thin_config.bak
fi
# create user noosfero in a portable way, while creating the log directory.
# (idea taken from the postfix package)
##############################################################################
if [ ! -d /var/log/noosfero ]; then
mkdir /var/log/noosfero
fi
chgrp noosfero /var/log/noosfero 2>/dev/null ||
addgroup --system noosfero
chown noosfero /var/log/noosfero 2>/dev/null ||
adduser --system --home /usr/share/noosfero --shell /bin/sh --no-create-home --disabled-password --ingroup noosfero noosfero
# Avoid "Not a git repository" error messages
# This happens due to gem dependencies that uses git on the gemspec file
##############################################################################
cd /usr/share/noosfero && git init > /dev/null
# Install unavailable dependencies with RubyGems
##############################################################################
cd /usr/share/noosfero && bundle > /dev/null
# create noosfero dynamic data directories
##############################################################################
noosfero_data_dir='/var/lib/noosfero-data'
makedir $noosfero_data_dir
makedir $noosfero_data_dir/index
makedir $noosfero_data_dir/cache
makedir $noosfero_data_dir/public
makedir $noosfero_data_dir/public/articles
makedir $noosfero_data_dir/public/image_uploads
makedir $noosfero_data_dir/public/thumbnails
# create noosfero tmp directory
##############################################################################
makedir /var/tmp/noosfero
. /usr/share/debconf/confmodule
db_get noosfero/default_database_config
if [ "$RET" = "true" ]; then
# Instruct dbconfig-common to generate database configuration file
##############################################################################
noosfero_database_yml="/etc/noosfero/database.yml"
dbc_generate_include="template:$noosfero_database_yml"
dbc_generate_include_args="-o template_infile=/usr/share/noosfero/config/database.yml.template"
dbc_generate_include_owner="root:noosfero"
dbc_generate_include_perms="640"
db_get noosfero/initial_domain
if [ ! -z "$RET" ]; then
# this is going to be used by the db:data:minimal rake task, called by
# /usr/lib/noosfero/dbinstall
export NOOSFERO_DOMAIN="$RET"
fi
/etc/init.d/noosfero setup
# dbconfig-common magic
. /usr/share/dbconfig-common/dpkg/postinst
dbc_go noosfero $@
# stop debconf to avoid the problem with infinite hanging, cfe
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=295477
db_stop
fi
#DEBHELPER#