#Maintainer: Thorsten Muehlfelder <thenktor(at)gmx.de>

pkgname=opennap-ng
pkgver=0.49.1
pkgrel=2tm
source=("http://switch.dl.sourceforge.net/sourceforge/opennap-ng/${pkgname}-${pkgver}-src.tar.gz" "rc.opennap")
dotnew=('usr/share/opennap-ng/opennap-block-ban.txt' 'usr/share/opennap-ng/opennap-block.txt' 'usr/share/opennap-ng/opennap-channels.txt' 'usr/share/opennap-ng/opennap-config.txt' 'usr/share/opennap-ng/opennap-filter.txt' 'usr/share/opennap-ng/opennap-motd.txt' 'usr/share/opennap-ng/opennap-servers.txt' 'usr/share/opennap-ng/opennap-users.txt')
url="http://opennap-ng.sourceforge.net/"

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (a P2P filesharing server)"
"Opennap NG is a free, non-commercial open source server software,"
"serving the original Napster peer 2 peer filesharing protocol, to be"
"used with clients such as Lopster/WinLop, XNap, WinMX and others."
"This project is not affiliated to http://opennap-ng.org, which was"
"created recently, based on an older Opennap NG source version with"
"less features and bugfixes (compare changelogs)."
"Please have a look at"
"/usr/doc/opennap-ng-$pkgver/README.Slackware"
)

build() {
	cd $startdir/src/${pkgname}-$pkgver
	./autogen.sh || return 1
	./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --sysconfdir=/etc --docdir=/usr/doc/opennap-ng-$pkgver \
		--with-uid=nobody \
		--with-gid=nogroup \
		--enable-resume \
		--enable-email || return 1

	make -j $numjobs || return 1
	make DESTDIR=$startdir/pkg install || return 1

	# install the rc file
	mkdir -p -m 755 $startdir/pkg/etc/rc.d/ || return 1
	install -m 755 $startdir/rc.opennap $startdir/pkg/etc/rc.d/rc.opennap.new || return 1

	# mv doc files to the correct location
	mkdir -p $startdir/pkg/usr/doc/opennap-ng-$pkgver/
	mv $startdir/pkg/usr/share/docs/opennap-ng/* $startdir/pkg/usr/doc/opennap-ng-$pkgver/
	rm -r $startdir/pkg/usr/share/docs/

	# create the README.Slackware file
	cat << EOF > $startdir/pkg/usr/doc/opennap-ng-$pkgver/README.Slackware
opennap-ng will run as user nobody, group nogroup
Please check your config files in /usr/share/opennap-ng and make sure the
files have the right permission (chown -R nobody:nogroup /usr/share/opennap-ng).

IMPORTANT: do not start the server without at least basic customization
of the files opennap-config.txt and opennap-users.txt!
1. customize your server configuration (file opennap-config.txt),
   set at least params like servername, IP address, ports, GotNap account.
   Newbies should prefer using the Opennap NG config tool (onngconf).     
2. create Elite account (i.e. via doc/scripts/init-userdb.sh)

See opennap-ng-0.49-manual.html for a complete setup manual.
EOF
}

doinst() {
	if [ -r etc/rc.d/rc.opennap -a -r etc/rc.d/rc.opennap.new ]; then
		chmod --reference=etc/rc.d/rc.opennap etc/rc.d/rc.opennap.new
	fi
	mv etc/rc.d/rc.opennap.new etc/rc.d/rc.opennap
}