#!/bin/sh

#An automation script to start the installation of qmail, ucspi-tcp and daemontools
#Specially formulated for Redhat, Fedora, RHEL and Whitebox Linux. :)


echo "Creating initial qmail directories..."
echo
sleep 2

cd /downloads/qmailrocks

mkdir -p /var/qmail

mkdir /usr/src/qmail

echo "Done!"
echo
sleep 2
echo "Creating all needed users and groups..."
echo
sleep 2

#######
#Script to add users and groups for FreeBSD

#Add all need Qmail users and groups
pw groupadd nofiles
pw useradd alias -g nofiles -d /var/qmail/alias -s /sbin/nologin
pw useradd qmaild -g nofiles -d /var/qmail -s /sbin/nologin
pw useradd qmaill -g nofiles -d /var/qmail -s /sbin/nologin
pw useradd qmailp -g nofiles -d /var/qmail -s /sbin/nologin
pw groupadd qmail
pw useradd qmailq -g qmail -d /var/qmail -s /sbin/nologin
pw useradd qmailr -g qmail -d /var/qmail -s /sbin/nologin
pw useradd qmails -g qmail -d /var/qmail -s /sbin/nologin
#Add vpopmail users/groups
pw groupadd vchkpw
pw useradd vpopmail -g vchkpw -m -d /usr/home/vpopmail -s /sbin/nologin

#######

echo "Done!"
echo
sleep 2
echo "Unpacking qmail, ucspi-tcp and daemontools..."
echo
sleep 2

cd /usr/src/qmail

tar zxvf /downloads/qmailrocks/qmail-1.03.tar.gz

tar zxvf /downloads/qmailrocks/ucspi-tcp-0.88.tar.gz

mkdir -p /package

chmod 1755 /package

cd /package

tar zxvf /downloads/qmailrocks/daemontools-0.76.tar.gz

echo "Done!"
echo
sleep 2
echo "Next, we setup special logging directories..."
echo
sleep 2

mkdir /var/log/qmail

cd /var/log/qmail

mkdir qmail-send qmail-smtpd qmail-pop3d

chown -R qmaill:wheel /var/log/qmail

chmod -R 750 /var/log/qmail

echo "Done!"
echo
sleep 2
echo "And set up the supervise script directories..."
echo
sleep 2

mkdir /var/qmail/supervise

cd /var/qmail/supervise

mkdir -p qmail-smtpd/log qmail-send/log qmail-pop3d/log

chmod +t qmail-smtpd qmail-send qmail-pop3d

echo "Setting conf-split and conf-spawn"
echo
sleep 2

echo 211 > /usr/src/qmail/qmail-1.03/conf-split

echo 255 > /usr/src/qmail/qmail-1.03/conf-spawn

echo "All steps completed!"
echo
sleep 2