#!/bin/sh
#
# pptp.SlackBuild
# 2010-09-22
#
# PPTP Client is a Linux, FreeBSD, NetBSD and OpenBSD client for
# the proprietary Microsoft Point-to-Point Tunneling Protocol, PPTP.

PRGNAM=pptp
VERSION=1.7.1

# automatically determine the architecture
if [ -z "$ARCH" ]; then
  ARCH=$(uname -m)
fi

BUILD=${BUILD:-1}
TAG=${TAG:-scr}

HOMEPAGE="http://pptpclient.sourceforge.net/"
SOURCE="${PRGNAM}-${VERSION}.tar.gz"
DOWNLOAD="http://mesh.dl.sourceforge.net/sourceforge/pptpclient/${SOURCE}"
MD5SUM="b47735ba5d6d37dfdbccb85afc044ede"

REQUIRES=""

MAINTAINER="Gernot WALZL"
EMAIL="gernot.walzl@gmx.at"

DESC="PPTP Client

PPTP Client is a Linux, FreeBSD, NetBSD and OpenBSD client for
the proprietary Microsoft Point-to-Point Tunneling Protocol, PPTP.
Allows connection to a PPTP based Virtual Private Network (VPN)
as used by employers and some cable and ADSL internet service
providers.

${HOMEPAGE}"

DOCS="$(pwd)/$0 AUTHORS COPYING ChangeLog DEVELOPERS Documentation INSTALL NEWS
PROTOCOL-SECURITY README Reference TODO USING"

# EOF info


# set initial variables
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# download the source if needed
if [ ! -f $CWD/$SOURCE ]; then
  wget -O $CWD/$SOURCE $DOWNLOAD || exit 1
fi

# check for correct source file
if [ "$(md5sum $CWD/$SOURCE | cut -f 1 -d ' ')" != "$MD5SUM" ]; then
  exit 1
fi

# extract the application source
cd $TMP || exit 1
tar xvf $CWD/$SOURCE || exit 1

# change to the application source directory
cd $PRGNAM-$VERSION || exit 1

# fix permissions
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# compile the source
make || exit 1

# install everything into the package directory
rm -rf $PKG
mkdir -p $PKG/install
make install DESTDIR=$PKG MANDIR=$PKG/usr/man/man8 || exit 1

# add documentation
if [ "$DOCS" != "" ]; then
  mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION
  find $PKG/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 644 {} \;
fi

# compress man pages
if [ -d $PKG/usr/man ]; then
  find $PKG/usr/man -type f -name "*.?" -exec gzip -9 {} \;
  for i in $(find $PKG/usr/man -type l -name "*.?") ; do
    ln -s $(readlink $i).gz $i.gz
    rm $i
  done
fi

# strip binaries
find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

# add some description to the package
if [ "$DESC" != "" ]; then
  echo "$DESC" | sed 's/^/'$PRGNAM': /g' > $PKG/install/slack-desc
fi

# append dependency information to the package
if [ "$REQUIRES" != "" ]; then
  for REQ in $REQUIRES; do
    echo "$REQ" >> $PKG/install/slack-required
  done
fi

# build the package
cd $PKG
makepkg -l y -c n \
  $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} \
  || exit 1

# make everything clean
cd $CWD
rm -rf $PKG
rm -rf $TMP/$PRGNAM-$VERSION
