#!/bin/sh
PKGNAM=vsftpd
VERSION=2.0.5
BUILD=2

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG
cd $TMP
rm -rf $PKGNAM-$VERSION
tar xzvf $CWD/$PKGNAM-$VERSION.tar.gz
cd $PKGNAM-$VERSION

# Make sure ownerships and permissions are sane:
chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;

zcat $CWD/vsftpd.builddefs.diff.gz | patch -p1 --verbose || exit 1
zcat $CWD/vsftpd.conf.diff.gz | patch -p1 --verbose || exit 1

# Patch from LFS - needed to build on kernels >= 2.6.18
zcat $CWD/vsftpd-2.0.5-syscall.patch.gz | patch -p1 --verbose || exit 1

# Without this, it builds fine as long as you have 32-bit stuff installed
sed -i "s#lib/#lib$LIBSUFFIX/#g" vsf_findlibs.sh || exit 1

make -j3 || exit 1
mkdir -p $PKG/usr/sbin
cp vsftpd $PKG/usr/sbin
chmod 755 $PKG/usr/sbin/vsftpd
mkdir -p $PKG/usr/man/man{5,8}
cat vsftpd.conf.5 > $PKG/usr/man/man5/vsftpd.conf.5
cat vsftpd.8 > $PKG/usr/man/man8/vsftpd.8
mkdir -p $PKG/etc
cat vsftpd.conf > $PKG/etc/vsftpd.conf.new
mkdir -p $PKG/etc/logrotate.d
zcat $CWD/vsftpd.log.gz > $PKG/etc/logrotate.d/vsftpd.new
mkdir -p $PKG/usr/share/empty
mkdir -p $PKG/home/ftp

mkdir -p $PKG/usr/doc/vsftpd-$VERSION
cp -a \
  AUDIT BENCHMARKS BUGS COPYING COPYRIGHT Changelog EXAMPLE FAQ \
  INSTALL LICENSE README* REFS REWARD SECURITY SIZE SPEED TODO TUNING \
  $PKG/usr/doc/vsftpd-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
pkghelpers_fixup
pkghelpers_makepkg