# Copyright (c) 2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

DESCRIPTION="Newsstar is a flexible multithreaded suck replacement for very fast news up- and download"
HOMEPAGE="http://newsstar.sourceforge.net"
SRC_URI="mirror://sourceforge/newsstar/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86"
IUSE="ssl"

# Well, I did not test with other libc's up to now...
# Other newsservers were not tested with newsstar up to now...
DEPEND="sys-libs/glibc
	>=net-news/inn-2.3.5
	ssl? ( dev-libs/openssl )
	dev-lang/perl"

src_compile() {
	econf \
		--sharedstatedir=/var/lib \
		--with-rc-dir=/etc/newsstar \
		`use_enable ssl ssl` \
		--disable-dependency-tracking \
		--with-conf-dir=/etc/newsstar \
		--with-spool-dir=/var/spool/news \
		--with-outgoing-dir=/var/spool/news/outgoing \
		--with-incoming-dir=/var/spool/news/newsstar-incoming \
		--with-inn-path=/usr/lib/news/bin \
		--with-articles-dir=/var/spool/news/articles \
			|| die 'Configure failed.'

	emake -j1 || die "emake failed"
}

src_install() {
	dodir /var/spool/news/newsstar-incoming
	einstall \
		CONF_DIR=${D}/etc/newsstar \
		RC_DIR=${D}/etc/newsstar \
		INCOMING_DIR=${D}/var/spool/news/newsstar-incoming \
		ACTIVE_FILE=/var/spool/news/db/active \
			|| die 'Install failed.'
	keepdir /var/spool/news/newsstar-incoming
	chown news:news /var/spool/news/newsstar-incoming
# Now we use one short perl line to install the sample-configs. Etc-update will do the rest.
	perl -e '$D="$ARGV[0]/etc/newsstar"; $SO=`ls sample_config/*.sample`; $SO =~ s/([^\/]*\/)(.*)(\.sample)\n/cp $1$2$3 $D\/$2\n/g; @SO=split("\n", $SO); for ($SO){print `$SO`;}' -- ${D}
}

pkg_postinst() {
	echo ''
	einfo 'Do not forget to adjust the config files in /etc/newsstar'
	einfo 'and maybe you want to add some entries to your crontab. For'
	einfo 'more information see "man newsstar".'
	echo ''
}