#! /bin/sh
###############################################################################
#
# $Id: spamfilter,v 1.7 1998/04/11 20:02:56 bcwhite Exp $
#
# Spam filter installation script.
#
# Written by Brian White <bcwhite@pobox.com>
#


PROCMAILRC=$HOME/.procmailrc


#
# Usage information
#
usage() {
    echo " "
    echo "Usage: `basename $0`  (no parameters)"
    exit 1
}


#
# Process command-line args
#
if [ "$1" != "" ]; then
    usage
fi


#
# Don't destroy existing setup
#
if [ -e $PROCMAILRC ]; then
    echo "Error: you already have a $PROCMAILRC file"
    usage
fi

# Remove any dangling symlinks
rm -f $PROCMAILRC


echo
echo "You need to read the installation information before continuing."
echo
echo -n "Press <enter> to read documentation or <ctrl-c> to abort: "
read

zcat /usr/share/doc/PACKAGE/install.txt.gz | sensible-pager


echo
echo "==============================================================================="
echo
echo "You now need to edit the default config file to match your preferences."
echo "Once done, this script will create all the directories you've set up."
echo
echo "If you need to refer back to the installation instructions, you can find"
echo "them in /usr/share/doc/PACKAGE/install.txt.gz"
echo
echo -n "Press <enter> to start editing or <ctrl-c> to abort: "
read
echo

sed -e 's|^#INCLUDERC|INCLUDERC|' SPAMLIB/procmailrc >$PROCMAILRC
sensible-editor $PROCMAILRC
eval `grep ^PM_ $PROCMAILRC`


echo
echo "==============================================================================="
echo
echo "Installation is proceeding.  Any existing files that are not compatible with"
echo "the new setup (eg. a file where a directory needs to be) will be renamed to"
echo "have the extension '.old'."
echo
#echo -n "Press <enter> to start editing or <ctrl-c> to abort: "
#read
#echo


for dir in $PM_HOME $PM_ETC $PM_RULES $PM_TEXT $PM_VAR $PM_BACKUP $PM_LOCK $PM_LOG $PM_RUN $PM_MAIL; do
    if [ ! -d $dir ]; then
	mv $dir $dir.old
	mkdir -p $dir
    fi
done

cd $PM_RULES
for file in adjust.rules black.rules list.rules nopassword.rules password.rules priority.rules spam.rules user.rules white.rules vacation.rules; do
    if [ -e $file ]; then
	echo "(file $PM_RULES/$file already exists -- not touched)"
    else
	ln -s SPAMRULES/$file $file
    fi
done
cp SPAMRULES/default-settings $PM_RULES/default-settings.orig

cd $PM_ETC
for file in whitelist.db greylist.db blacklist.db; do
    if [ -e $file ]; then
	echo "(file $PM_ETC/$file already exists -- not touched)"
    else
	cp SPAMDEFS/$file $file
    fi
done

if [ -d $HOME/bin ]; then
    cd $HOME/bin;
    if [ -e from ]; then
	mv from from.old
    fi
    ln -sf SPAMBIN/from from
fi


echo
echo "==============================================================================="
echo
echo "Done.  If you have procmail as your default delivery agent, then everything"
echo "should be working.  Feel free to edit the rules files to suit your tastes."
echo
echo "If you don't have procmail as your delivery agent, put the following as"
echo 'your ~/.forward file:  "| /usr/bin/procmail -Yf-" (without the quotes)'
echo "For more information or if you have problems, consult the procmail(1)"
echo "man page."
echo
echo "To move mail from the filtered boxes to the inbox(es) your mailer uses,"
echo "try the SPAMBIN/movemail script or some modification thereof."
echo
echo "Some sample reply messages can be found in /usr/share/doc/PACKAGE/messages."
echo
echo "You must make sure a copy of all outgoing mail is copied or blind-copied"
echo "to you.  See /usr/share/doc/PACKAGE/install.txt.gz for more information."
echo
