#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-sendmail

VERSION=8.12.10
ARCH=i486
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_sendmail.tar.gz

echo "+=================+"
echo "| sendmail.$VERSION |"
echo "+=================+"
OSCPU="`uname -srm | tr ' ' '.'`"
cd $TMP
tar xzvf $CWD/sendmail.$VERSION.tar.gz
cd sendmail-$VERSION

# Add TLS support to the sendmail binary:
cat $CWD/site.config.m4 > devtools/Site/site.config.m4

# Build .cf files for Linux:
cd $TMP/sendmail-$VERSION/cf/cf
cp $CWD/*.mc .
cp linux.uucp.mc config.mc
sh Build config.cf
mv config.cf $PKG/usr/share/sendmail/linux.uucp.cf
cp sendmail-slackware.mc config.mc
sh Build config.cf
mv config.cf $PKG/usr/share/sendmail/sendmail-slackware.cf
cp sendmail-slackware-tls.mc config.mc
sh Build config.cf
mv config.cf $PKG/usr/share/sendmail/sendmail-slackware-tls.cf

# Add a sample sendmail.cf:
cat $PKG/usr/share/sendmail/sendmail-slackware.cf > $PKG/etc/mail/sendmail.cf.new
cat submit.cf > $PKG/etc/mail/submit.cf.new

cd $TMP/sendmail-$VERSION
## All "Build" does is call make while screwing up the options  :-)
## sh Build
make O="-O2 -march=i486 -mcpu=i686"
#O="-O2 -march=i486 -mcpu=i686" sh Build
cat sendmail/mailq.1 | gzip -9c > $PKG/usr/man/man1/mailq.1.gz
cat sendmail/newaliases.1 | gzip -9c > $PKG/usr/man/man1/newaliases.1.gz
wget -N -k -r http://www.sendmail.org/faq/faq.txt
mkdir -p $PKG/usr/doc/sendmail-$VERSION
cp -a www.sendmail.org/faq/faq.txt $PKG/usr/doc/sendmail-$VERSION
cp -a FAQ INSTALL KNOWNBUGS LICENSE PGPKEYS README RELEASE_NOTES $PKG/usr/doc/sendmail-$VERSION
( cd doc ; cp -a op $PKG/usr/doc/sendmail-$VERSION )
( cd $PKG/usr/doc/sendmail-$VERSION ; chown -R root.root . ; find . -type d -exec chmod 755 {} \; ; find . -type f -exec chmod 644 {} \; )
cd obj.$OSCPU/sendmail
strip sendmail
cat sendmail > $PKG/usr/sbin/sendmail.new
cat aliases.5 | gzip -9c > $PKG/usr/man/man5/aliases.5.gz
cat sendmail.8 | gzip -9c > $PKG/usr/man/man8/sendmail.8.gz
cat statistics > $PKG/etc/mail/statistics
cat ../../sendmail/helpfile > $PKG/etc/mail/helpfile
cd ../makemap
strip makemap
cat makemap > $PKG/usr/sbin/makemap
cat makemap.8 | gzip -9c > $PKG/usr/man/man8/makemap.8.gz
cd ../mailstats
strip mailstats
cat mailstats > $PKG/usr/sbin/mailstats
cat mailstats.8 | gzip -9c > $PKG/usr/man/man8/mailstats.8.gz
cd ../praliases
strip praliases
cat praliases > $PKG/usr/bin/praliases
cat praliases.8 | gzip -9c > $PKG/usr/man/man8/praliases.8.gz
cd ../rmail
strip rmail
cat rmail > $PKG/usr/bin/rmail
cat rmail.8 | gzip -9c > $PKG/usr/man/man8/rmail.8.gz
cd ../smrsh
strip smrsh
cat smrsh > $PKG/usr/sbin/smrsh
cat smrsh.8 | gzip -9c > $PKG/usr/man/man8/smrsh.8.gz
cd ../mail.local
strip mail.local
cat mail.local > $PKG/usr/sbin/mail.local
cat mail.local.8 | gzip -9c > $PKG/usr/man/man8/mail.local.8.gz
cd ../vacation
strip vacation
cat vacation > $PKG/usr/bin/vacation
cat vacation.1 | gzip -9c > $PKG/usr/man/man1/vacation.1.gz
cd ../editmap
strip editmap
cat editmap > $PKG/usr/sbin/editmap
cat editmap.8 | gzip -9c > $PKG/usr/man/man8/editmap.8.gz

mkdir -p $PKG/install
cat $CWD/slack-desc.sendmail > $PKG/install/slack-desc

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/sendmail-$VERSION-$ARCH-$BUILD.tgz

## Clean up the extra stuff:
#if [ "$1" = "--cleanup" ]; then
#  rm -rf $TMP/sendmail-$VERSION
#  rm -rf $PKG
#fi