# SliTaz package receipt.

PACKAGE="ppp-pam"
VERSION="2.4.5"
CATEGORY="network"
SHORT_DESC="Implements the Point-to-Point Protocol (PPP) with PAM support."
MAINTAINER="pascal.bellard@slitaz.org"
SOURCE="ppp"
TARBALL="$SOURCE-$VERSION.tar.gz"
WEB_SITE="http://ppp.samba.org/"
WGET_URL="ftp://ftp.samba.org/pub/ppp/$TARBALL"
DEPENDS="pam"
BUILD_DEPENDS="pam pam-dev"
CONFIG_FILES="/etc/ppp"
PROVIDE="ppp:pam"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	if ! grep -qs pppol2tpv3_addr include/linux/if_pppol2tp.h ; then
		sed -i /#endif/d include/linux/if_pppol2tp.h
		cat >> include/linux/if_pppol2tp.h <<EOT
/* The L2TPv3 protocol changes tunnel and session ids from 16 to 32
 * bits. So we need a different sockaddr structure.
 */
struct pppol2tpv3_addr {
	pid_t	pid;			/* pid that owns the fd. 0 => current */
	int	fd;			/* FD of UDP or IP socket to use */
	struct sockaddr_in addr;	/* IP address and port to send to */
	__u32 s_tunnel, s_session;	/* For matching incoming packets */
	__u32 d_tunnel, d_session;	/* For sending outgoing packets */
};
#endif
EOT
	fi
	sed -i 's/#USE_PAM/USE_PAM/' pppd/Makefile.linux
	./configure --prefix=/usr --mandir=/usr/share/man \
	$CONFIGURE_ARGS &&
	make &&
	make DESTDIR=$DESTDIR/usr install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr
	cp -a $_pkg/usr/lib $fs/usr
	# Config files.
	mkdir -p $fs/etc/ppp/scripts
	cp ../$SOURCE/stuff/README.scripts $fs/etc/ppp
	cp -a $src/etc.ppp/* $fs/etc/ppp
	# PPP scripts.
	cp -a $src/scripts/ppp-on $fs/etc/ppp/scripts
	cp -a $src/scripts/ppp-on-dialer $fs/etc/ppp/scripts
	sed -i 's,ppp/ppp-on-dialer,ppp/script/ppp-on-dialer,' $fs/etc/ppp/scripts/ppp-on-dialer
	cp -a $src/scripts/ppp-off $fs/etc/ppp/scripts
	cp -a $src/scripts/callback $fs/etc/ppp/scripts
	cp -a $src/scripts/redialer $fs/etc/ppp/scripts
	
	cp -a $src/scripts/ip-up.local.add $fs/etc/ppp/scripts/ip-up
	cp -a $src/scripts/ip-down.local.add $fs/etc/ppp/scripts/ip-down
	chmod +x $fs/etc/ppp/scripts/ip*
	# insert #!/bin/sh  on top line in ip* scripts
	sed -i '1i\#!/bin/sh' $fs/etc/ppp/scripts/ip*
}

pre_remove()
{
    tazpkg get-install  ${PACKAGE%-pam}
}