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

EAPI="2"
SUPPORT_PYTHON_ABIS="1"

inherit eutils distutils

WOL_PV="0.7.1"
MY_P="${P/_p/-}"
MY_PV="${PV/_p*/}"

DESCRIPTION="Open Source Computer System Management !"
HOMEPAGE="http://pulse2.mandriva.org/"
SRC_URI="http://mds.mandriva.org/pub/pulse2/server/sources/${PV}/pulse2-${PV}.tar.gz
	 mirror://sourceforge/ahh/wol-${WOL_PV}.tar.gz"

LICENSE="GPL-2"
KEYWORDS="~alpha ~amd64 ~arm ~ppc ~ppc64 ~sparc ~x86 ~x86-fbsd"
IUSE=""

SLOT="0"

RDEPEND=">=app-admin/mmc-core-${PV}
	!app-admin/pulse2-common
	!app-admin/pulse2-launcher
	!app-admin/pulse2-package-server
	!app-admin/pulse2-inventory-server
	!app-admin/pulse2-mmc-plugins
	!app-admin/pulse2-scheduler
"

DEPEND="sys-apps/lsb-release"

S="${WORKDIR}/pulse2-${PV}/services"

src_prepare() {
	pushd "${WORKDIR}"/pulse2-${PV}
	epatch "${FILESDIR}"/pulse2-1.3.0-makefile-1.patch
	epatch "${FILESDIR}"/pulse2-1.3.0-python_fix-1.patch
	popd
	distutils_src_prepare
}

src_configure() {
	pushd "${WORKDIR}"/wol-${WOL_PV}
	econf || die "configure failed"
	popd
	distutils_src_configure
}

src_compile() {
	pushd "${WORKDIR}"/wol-${WOL_PV}
	emake || die "make failed"
	popd
	distutils_src_compile
}


# from marienz's setuptools.eclass:
src_install() {
	cp "${WORKDIR}"/wol-${WOL_PV}/src/wol bin/pulse2-wol
	emake install_nopy PREFIX=/usr DESTDIR=${D}
	distutils_src_install
	newinitd "${FILESDIR}"/pulse2-inventory-server.initd pulse2-inventory-server
	newinitd "${FILESDIR}"/pulse2-imaging-server.initd pulse2-imaging-server
	newinitd "${FILESDIR}"/pulse2-launchers.initd pulse2-launchers
	newinitd "${FILESDIR}"/pulse2-package-server.initd pulse2-package-server
	newinitd "${FILESDIR}"/pulse2-scheduler.initd pulse2-scheduler
}

pkg_postinst() {
	elog "To disable some plugin in your pulse2 environments, you have to set"
	elog "disable to 1 in /etc/mmc/plugins/*.ini"
	elog "(one config file per service)"
	elog "You can't disable the base plugin."
}