# SliTaz package receipt.

PACKED_SIZE="212.0K"
UNPACKED_SIZE="708.0K"
PACKAGE="ppp"
VERSION="2.4.7"
CATEGORY="network"
SHORT_DESC="Implements the Point-to-Point Protocol (PPP)."
MAINTAINER="pankso@slitaz.org"
LICENSE="BSD GPL"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://ppp.samba.org/"
WGET_URL="https://github.com/paulusmack/ppp/archive/$TARBALL"
CONFIG_FILES="/etc/ppp/options /etc/ppp/*secrets"
HOST_ARCH="i486 arm"

BUILD_DEPENDS="wget"
SUGGESTED="tazpanel"

# Rules to configure and make the package.
compile_rules()
{
	case "$ARCH" in
	arm*)
		export PATH=/cross/arm/tools/arm-slitaz-linux-gnueabi/bin:$PATH
	esac
	./configure --prefix=/usr \
		$CONFIGURE_ARGS &&
	make &&
	make DESTDIR=$DESTDIR/usr install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr $fs/var/www/tazpanel/menu.d/network/VPN
	cp -a $install/usr/sbin $fs/usr
	[ -d "$install/usr/lib" ] && cp -a $install/usr/lib $fs/usr
	cp -a $stuff/ppp.cgi $fs/var/www/tazpanel
	ln -s ../../ppp.cgi $fs/var/www/tazpanel/menu.d/network/ppp
	ln -s ../../../ppp.cgi $fs/var/www/tazpanel/menu.d/network/VPN/ppp
	
	# Config files.
	mkdir -p $fs/etc/ppp/scripts $fs/etc/ppp/ip-up.d $fs/etc/ppp/ip-down.d
	cp $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/scripts/ppp-on-dialer:' \
		$fs/etc/ppp/scripts/ppp-on
	
	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
	cat >> $fs/etc/ppp/ip-up <<EOT
#!/bin/sh

if [ -x /etc/ppp/ip-up.d/\$6 ]; then
	. /etc/ppp/ip-up.d/\$6 "\$@"
elif [ -n "\$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
	rm -f /etc/ppp/resolv.prev
	if [ -f /etc/resolv.conf ]; then
		cp /etc/resolv.conf /etc/ppp/resolv.prev
		grep domain /etc/ppp/resolv.prev > /etc/resolv.conf
		grep search /etc/ppp/resolv.prev >> /etc/resolv.conf
		cat /etc/ppp/resolv.conf >> /etc/resolv.conf
		chmod 644 /etc/resolv.conf
	else
		cp /etc/ppp/resolv.conf /etc
		chmod 644 /etc/resolv.conf
	fi
fi
EOT
	cat >> $fs/etc/ppp/ip-down <<EOT
#!/bin/sh

if [ -x /etc/ppp/ip-down.d/\$6 ]; then
	. /etc/ppp/ip-down.d/\$6 "\$@"
elif [ -n "\$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
	if [ -f /etc/ppp/resolv.prev ]; then
		cp -f /etc/ppp/resolv.prev /etc/resolv.conf
		chmod 644 /etc/resolv.conf
	else
		rm -f /etc/resolv.conf
	fi
fi
EOT
	# cp -a $src/scripts/ip-up.local.add $fs/etc/ppp/ip-up
	# cp -a $src/scripts/ip-down.local.add $fs/etc/ppp/ip-down
	chmod 711 $fs/etc/ppp/ip-up $fs/etc/ppp/ip-down

	# insert #!/bin/sh  on top line in ip* scripts
	sed -i '1i\#!/bin/sh' $fs/etc/ppp/ip* 2>/dev/null	
	# add empty peers dir
	mkdir -p $fs/etc/ppp/peers
	# hide login/pass from regular users
	chmod go-rwx $fs/etc/ppp/*secrets
	chmod go-rwx $fs/etc/ppp/options
	chmod 711 $fs/etc/ppp/scripts/*
}

post_install()
{
	rm -f $1/var/cache/tazpanel/header.* 2>/dev/null || true
	chroot "$1/" chgrp dialout /usr/sbin/pppd
	chmod 4750 $1/usr/sbin/pppd
	echo
	echo " ADD yourself to group dialout to use pppd: addgroup tux dialout"
}
