#Maintainer: Richard Lapointe <richard~at~laprjns~dot~com>
#Former Maintainer(s): Name <email@address.com>
#Anything commented out is optional and can be deleted.

pkgname=btpd	
pkgver=0.16
pkgrel=2rl
#$arch=
source=("http://cloud.github.com/downloads/btpd/btpd/btpd-0.16.tar.gz" \
		"rc.btpd")
sourcetemplate=http://people.salixos.org/laprjns/$pkgname/$pkgver/
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo")
url=https://github.com/btpd/btpd/wiki/
dotnew=(/etc/btpd.conf)
#CFLAGS=
#CXXFLAGS=
#options=('noautodotnew')

doinst() {
# Create btpd user
        if ! getent passwd btpd >/dev/null; then
        	useradd --system --home /srv/btpd --shell /bin/sh btpd
        fi

        # Create torrent files dir
        if ! [ -d /srv/btpd/files ]; then
            mkdir -p /srv/btpd/files
        fi
        chmod 775 /srv/btpd/files
        chown -h -R btpd:users /srv/btpd

        # Create log file and fix permissions
        if ! [ -e /var/log/btpd ]; then
            touch /var/log/btpd.log
        fi
        chmod 644 /var/log/btpd.log
        chown btpd:nogroup /var/log/btpd.log
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"btpd (BitTorrent Protocol Daemon)"
"Btpd is a utility for sharing files over the BitTorrent network"
"protocol. It runs in daemon mode, thus needing no controlling terminal"
"or gui. Instead, the daemon is controlled by the btcli command line"
"utility, or other programs capable of sending commands and queries on"
"the btpd control socket. See the README file in /usr/doc/btpd-016/"
""
"This Salix build of btpd includes both a configuration file found in"
"/etc to control how btpd works and a rc script in /etd/rc.d to start"
"btpd as a service under the user btpd"
)


build() {
	cd $startdir/src/$pkgname-$pkgver

	./configure \
	  --prefix=/usr \
	  --libdir=/usr/lib${LIBDIRSUFFIX} \
	  --localstatedir=/var \
	  --sysconfdir=/etc

#	./autogen.sh || return 1
	make || return 1
	make install DESTDIR=$startdir/pkg
	
	# create directories
	mkdir -p $startdir/pkg/etc
	mkdir -p $startdir/pkg/etc/rc.d
	
	# service start script
	install -m 755 $startdir/rc.btpd $startdir/pkg/etc/rc.d/
	
	# create a config file
	cat << "EOC" > $startdir/pkg/etc/btpd.conf
	
# Defaults for btpd service script
# sourced by /etc/rc.d/rc.btpd

#
# This is a POSIX shell fragment
#

# TCP port the daemon will listen to
PORT=6881

# Maximum bandwidth allowed for downloading
BWIN=50

# Maximum bandwidth allowed to uploading peers
BWOUT=10

# Maximum peers allowed
PEERS=20



#######################################################################################################
# *DON'T* edit this line, use single variables above instead                                          #
DAEMON_OPTS="--bw-out $BWOUT --bw-in $BWIN --max-peers $PEERS --port $PORT --logfile /var/log/btpd.log"
#######################################################################################################

EOC
} 
