#! /bin/sh
# postinst script for spip
#
# see: dh_installdeb(1)

set -e

. /usr/share/debconf/confmodule

case "$1" in
    configure)

        db_get spip/webserver || true
        webserver=$RET

        webserver=`echo $webserver|sed -e 's/,  */ /g'`

        for i in $webserver; do
            if [ "$webserver" != "cherokee" ]; then
                if [ ! -d /etc/$i/conf.d/ ]; then
                        install -d -m755 /etc/$i/conf.d/
                fi
                if [ ! -e /etc/$i/conf.d/spip.conf ]; then
                        ln -s /etc/spip/apache.conf \
                        /etc/$i/conf.d/spip.conf
                        if [ -f /etc/init.d/$i ]; then
                                if which invoke-rc.d >/dev/null 2>&1; then
                                        invoke-rc.d $i reload
                                else
                                        /etc/init.d/$i reload
                                fi
                        fi
                fi
             else
                if [ ! -d /etc/cherokee/sites-available/ ]; then
                        install -d -m755 /etc/cherokee/sites-available/
                fi
                if [ ! -e /etc/cherokee/sites-available/spip ]; then
                        ln -s /etc/spip/cherokee.conf \
                        /etc/cherokee/sites-available/spip
                        if [ -f /etc/init.d/$i ]; then
                                if which invoke-rc.d >/dev/null 2>&1; then
                                        invoke-rc.d $i reload
                                else
                                        /etc/init.d/$i reload
                                fi
                        fi
                fi
             fi
        done

	chown -R www-data /var/lib/spip/sites/default/IMG
	chown -R www-data /var/lib/spip/sites/default/tmp
	chown -R www-data /var/lib/spip/sites/default/local
	chown -R www-data /var/lib/spip/sites/default/config
	chown -R www-data /var/lib/spip/plugins
	chown -R www-data /var/lib/spip/local
	chown -R www-data /var/lib/spip/IMG

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


