#!/bin/sh
# you have:
#  daemontools
#  ucspi-tcp
#  cdb
#  checkpassword
#  openssl
#
# we build:
#  - qmail-1.03.tar.gz
#  - some patches

QCFLAGS="-DTLS=20021228 -I$SSL/include"

# untar qmail
test -d qmail-1.03 && rm -rf qmail-1.03
ut qmail-1.03.tar.gz
cd qmail-1.03

# create user + groups
echo " -> creating groups and users ..."
[ `cat /etc/group |grep '^qmail:'`   ] || groupadd -g 3000 qmail
[ `cat /etc/passwd|grep '^qmailq:'`  ] || useradd  -u 3000 -g qmail   -d /var/qmail qmailq
[ `cat /etc/passwd|grep '^qmailr:'`  ] || useradd  -u 3001 -g qmail   -d /var/qmail qmailr
[ `cat /etc/passwd|grep '^qmails:'`  ] || useradd  -u 3002 -g qmail   -d /var/qmail qmails
[ `cat /etc/group |grep '^nofiles:'` ] || groupadd -g 3001 nofiles
[ `cat /etc/passwd|grep '^qmaila:'`  ] || useradd  -u 3003 -g nofiles -d /var/qmail/alias qmaila
[ `cat /etc/passwd|grep '^qmaild:'`  ] || useradd  -u 3004 -g nofiles -d /var/qmail qmaild
[ `cat /etc/passwd|grep '^qmaill:'`  ] || useradd  -u 3005 -g nofiles -d /var/qmail qmaill
[ `cat /etc/passwd|grep '^qmailp:'`  ] || useradd  -u 3006 -g nofiles -d /var/qmail qmailp
echo -e "qmail\nnofiles" > conf-groups
echo -e "qmaila\nqmaild\nqmaill\nroot\nqmailp\nqmailq\nqmailr\nqmails" > conf-users

# add latest stable patch
cat ../stable.diff | patch -p1

# configure compiling stuff
cat Makefile | sed -e sö/opt/sslö${SSL}ög > Makefile2
mv -f Makefile2 Makefile
echo "$CC $CFLAGS $QCFLAGS" > conf-cc
echo "$CC $CFLAGS $QCFLAGS -s" > conf-ld

make it
#qmail start
#qmail stop
#echo "Make sure qmail is not running, hen press ENTER"
#read x
make setup check

# make /command symlinks + strip /var/qmail/bin/*
for i in /var/qmail/bin/*; do
 rm -f "/command/`basename $i`"
 ln -s "$i" "/command/`basename $i`"
done
strip -R .note -R .comment /var/qmail/bin/* 2>/dev/null

# who the fuck needs preformatted manpages!
rm -f -r /var/qmail/man/cat*

# we want gzipped pages
gzip -rf9 /var/qmail/man
sync

#qmail start
