# ebuild for Trustees 3.0 by M Stegman
# Distributed under the terms of the GNU General Public License v2

inherit linux-mod

MY_PP=${PN}-${PV}-gentoo
DESCRIPTION="Advanced permission management system for Linux"
HOMEPAGE="http://trustees.sourceforge.net/"
SRC_URI="http://umn.dl.sourceforge.net/sourceforge/trustees/${PN}-${PV}.tar.bz2
       http://www.ephess.net/gentoo/${MY_PP}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="x86"
IUSE=""
RESTRICT="nomirror"

DEPEND="virtual/libc
	virtual/linux-sources"

pkg_setup() {
	# linux-mod inherits linux-info !
	linux-mod_pkg_setup
	# check prerequisites for Trustees 3.0:
	#    CONFIG_SECURITY is enabled
	#    kernel is 2.6.XXX
	linux_chkconfig_builtin "SECURITY" || die "You must have CONFIG_SECURITY built in to use trustees!"
	if ! kernel_is 2 6; then
		einfo "Your kernel version is ${KV}!"
		die "Trustees 3.0 is for kernel 2.6 only!"
	fi
	
	# I guess we're OK!
	MODULE_NAMES="trustees(security:${S}/module)"
	BUILD_TARGETS="clean all"
}

src_compile() {
	linux-mod_src_compile
	cd "${S}/src"
	make
}

src_install() {
	linux-mod_src_install
	dodir /etc
	dodir /trustees
	GENTOO_DIR="${WORKDIR}/gentoo-extra"
	newinitd ${GENTOO_DIR}/trustees-init.d trustees
	newconfd ${GENTOO_DIR}/trustees-conf.d trustees
	dodoc README
	docinto examples
	dodoc examples/*
	dodoc ${GENTOO_DIR}/trustees3.conf
	exeinto /sbin
	doexe src/settrustees
}

pkg_postinst() {
	linux-mod_pkg_postinst
	
	einfo "You need to create /etc/trustees.conf.  See examples in"
	einfo "/usr/share/doc/${PF}/examples.  After setting up your config"
	einfo "file, simply use the initscript to start using trustees:"
	einfo "    /etc/init.d/trustees start"
	einfo "After starting trustees, if you modify /etc/trustees.conf,"
	einfo "you need to reload trustees for the changes to take effect:"
	einfo "    /etc/init.d/trustees reload"
}

pkg_prerm() {
	/etc/init.d/trustees stop
        # just in case something broke...
        umount -a -t trusteesfs
        rmmod trustees
}