#!/bin/sh
#-----------------------------------------------------------------------------#
# FF_INSTALL.SH: Streamlined fastfoward Configuration and Installation Script #
# AUTHOR  : Jay D. Dyson, Treachery Unlimited <jdyson@treachery.net>          #
# VERSION : 2.0 - Accompanies "Qmail for Newbies" publication.                #
# REVISED : 04/20/2001 - Release version, commented for general use.          #
#-----------------------------------------------------------------------------#
# WARNING / DISCLAIMER:                                                       #
#=============================================================================#
#  By use of this script, you agree to hold myself and the site where this    #
#  document is hosted harmless from any consequence arising from use and/or   #
#  misuse of the instructions contained herein.  (I have to say this because  #
#  there are always people out there whose utterly incomprehensible lack of   #
#  common sense is ripe fodder for bottom-feeding lawyer types.)  When in     #
#  doubt, *always* consult Qmail's original documentation.                    #
#=============================================================================#
# 
# GLOBAL DEFAULT VARIABLES
#
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/ucb:/usr/local/bin" ; export PATH
PI=""                           # Condition initialization
CC=`cc -v |grep "not "`         # Show-stoppers, if missing
AR=`which ar |grep -v "no "`    #
LD=`which ld |grep -v "no "`    #
NR=`which nroff |grep -v "no "` #
ETEST=`echo -e`                 # Test for echo
if [ "$ETEST" = "-e" ]; then
  SECHO="echo"
else
  SECHO="echo -e"
fi
#
# PREINSTALLATION CHECKS
#
echo "Streamlined fastforward Installation Script v2.0 - by Jay D. Dyson"
echo ""
echo "------------------------------------------------------------"
echo " By running this script, you acknowledge that you have read"
echo " and  agreed to the  terms and conditions  of the  WARNING/"
echo " DISCLAIMER  at the head of this  shell script.   IF YOU DO"
echo " NOT AGREE, ABORT NOW.  Otherwise, hit ENTER to start."
echo "------------------------------------------------------------"
echo ""
$SECHO "[Hit ENTER to agree to the terms and begin installation]\c"
read temp
# Must be root to install
ROOT=`id |cut -f2 -d'=' |cut -f1 -d"("`
if [ $ROOT -gt 0 ]; then
  echo "ERROR: You MUST be root to install Qmail!" ; echo ""
  exit 0
fi
# Make sure we have the needed utilities to compile.  Show-stoppers if not present.
if [ "$CC" = "" ]; then echo "Found: `which cc` (`which gcc`)"
  if [ -n "$AR" ]; then echo "Found: $AR"
    if [ -n "$LD" ]; then echo "Found: $LD"
      if [ -n "$NR" ]; then echo "Found: $NR"
        echo "Looks like everything necessary to compile is here."
      else echo "ERROR: Nroff missing!  Cannot make man pages."; echo ""; exit 0; fi
    else echo "ERROR: Link-editor missing!  Cannot compile."; echo ""; exit 0; fi
  else echo "ERROR: Cannot create/update library files!"; echo ""; exit 0; fi
else echo "ERROR: Working compiler not found!"; echo ""; exit 0
fi
#
# COMPILE AND INSTALL
#
echo "" ; echo "Compiling fastforward..." ; echo ""
make setup check
#
echo "Creating /var/qmail/alias/.qmail-default"
echo "| fastforward -d /etc/aliases.cdb" > /var/qmail/alias/.qmail-default
chmod 644 /var/qmail/alias/.qmail-default
echo "Disabling old newaliases binary."
cp -p /usr/bin/newaliases /usr/bin/newaliases.old
chmod 0000 /usr/bin/newaliases.old
rm -f /usr/bin/newaliases
echo "Creating symlink from /usr/bin/newaliases to /var/qmail/bin/newaliases"
ln -s /var/qmail/bin/newaliases /usr/bin/newaliases
#
# CONFIGURATION
#
while [ "$PI" = "" ]; do
  echo "" ; echo "Please scroll up and review the fastforward compilation." ; echo ""
  $SECHO "Did fastforward appear to successfully compile? (y/n) \c"
  read PI
  case "$PI" in
    n*|N*)
      echo "" ; echo "Since all preinstall checklists passed, your system has a problem"
      echo "I didn't encounter.  Please e-mail me ALL the output that this script"
      echo "generated and I'll see if I can help you resolve it.  You can reach"
      echo "me at jdyson\@treachery.net." ; echo ""
      exit 0
    ;;
    y*|Y*)
      echo ""
      echo "To start /etc/aliases support for your users, you will need to"
      echo "edit your current /etc/aliases per the specifications as outlined"
      echo "in the ALIASES document in this directory.  Gone are the days of"
      echo "directing mail to /dev/null and root.  It's best that such mail"
      echo "goes to the 'alias' user from now on."
      echo ""
      echo "Once you have completed the appropriate changes to /etc/aliases,"
      echo "be sure to run 'newaliases'."
      echo ""
      echo "Installation complete."
      echo ""
    ;;
    *)
      PI="" ; echo "" ; echo "Answer 'y' for yes or 'n' for no." ; echo ""
    ;;
  esac
done
echo "Installation complete."
# End

