#!/bin/sh
#
# kTm port by Juzer
#
#       regards to hns & psych
#

# local config:
BUILD="1"
PACKAGE="postfix"

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED="`ls -1 $PACKAGES/packages/|grep $PACKAGE|cut -d "-" -f 1,2`"
$WGET -q ftp://ftp.porcupine.org/mirrors/postfix-release/official/
NEW=`grep $PACKAGE-2.1 index.html|grep .tar|cut -d / -f 7|cut -d '"' -f 1|sed -e s/.tar.*//|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL ftp://ftp.porcupine.org/mirrors/postfix-release/official/$SRC.tar.gz
}

build() {
# Creating new
tar zxvf $DOWNL/$SRC.tar.gz
cd $SRC
make makefiles \
CCARGS="-DUSE_SASL_AUTH -DHAS_PCRE -DUSE_SSL -I/usr/include/sasl -I/usr/include/openssl -I/usr/include" \
AUXLIBS="-L/usr/lib -lsasl2 -lpcre -lssl -lcrypto" || exit
make || exit
make install install_root=$PKG non_interactive=1 || exit
mkdir -p $PKG/etc/rc.d/
cp $CWD/rc.postfix $PKG/etc/rc.d/
if [ -r /etc/rc.d/rc.postfix ];then
mv $PKG/etc/rc.d/rc.postfix $PKG/etc/rc.d/rc.postfix.new
fi
if [ -d /etc/postfix ]; then
mv $PKG/etc/postfix $PKG/etc/postfix.new
fi
chown postfix.postdrop $PKG/usr/sbin/postqueue
chown postfix.postdrop $PKG/usr/sbin/postdrop
chown postfix.postdrop $PKG/var/spool/postfix -R
chown root.root $PKG/var/spool/postfix
chmod +s $PKG/usr/sbin/postqueue
chmod +s $PKG/usr/sbin/postdrop
mv $PKG/usr/local/man/ $PKG/usr/man/
rm -r $PKG/usr/local/
strip --strip-unneeded $PKG/usr/libexec/postfix/*
    postbuild
}

source "${DATA:-/usr/lib/ktm}/ktm.ports.sh"

