# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="Ebox is an easy to setup LDAP/Samba/PDC-server, firewall, ... especially suited for SOHO use"
HOMEPAGE="http://ebox-platform.com/"
SRC_URI="http://ebox-platform.com/releases/${PV}/${P}.tar.gz"

LICENSE="gpl2"
SLOT="0"
KEYWORDS="~x86"

IUSE=""
DEPEND="app-admin/libebox
	=www-apache/mod_perl-1*
	net-www/mod_ssl
	dev-perl/Apache-AuthCookie
	perl-gcpan/Sys-CpuLoad
	perl-gcpan/Sys-CPU
	dev-perl/gnome2-gconf
	dev-perl/Proc-ProcessTable
	dev-perl/Class-Singleton
	perl-gcpan/Apache-Singleton
	sys-process/runit"

src_compile() {
	econf --localstatedir=${ROOT}/var/ || die "Configure died"
	emake || die "Make failed"
}

src_install() {
	GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=yes make install DESTDIR=${D} || die "Install failed"
	dodir ${ROOT}/var/lib/ebox/tmp
	dodir ${ROOT}/var/lib/ebox/log
	dodir ${ROOT}/etc/init.d
	exeinto /etc/init.d
	doexe tools/ebox
}

pkg_postinst() {
        enewgroup ebox
        enewuser ebox -1 -1 ${ROOT}/var/lib/ebox ebox
	chown -R ebox:ebox ${ROOT}/var/lib/ebox

	echo "installing gconf schemas:"
	SCHEMA_LOCATION="${ROOT}/etc/gconf/schemas"
	SCHEMA_FILES="global.schemas sysinfo.schemas apache.schemas "
	for SCHEMA in $SCHEMA_FILES; do
		if [ -e $SCHEMA_LOCATION/$SCHEMA ]; then
		echo "installing ${SCHEMA}"
		HOME=/var/lib/ebox GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
		gconftool-2 --makefile-install-rule $SCHEMA_LOCATION/$SCHEMA && \
		echo "${SCHEMA} installed" || die "installation of schema ${SCHEMA} failed"
		fi
	done
}