#!/bin/sh
#
# st patch 20100626

#Pipe into bash if it's present

if [ "`bash --version 2>&1|grep 'GNU bash'`" != "" -a "$BASH_VERSION" = "" ]; then
    exec bash $0 $*
    exit 1
fi

umask 007

OLD_LANG="$LANG" 
LANG=C  
export LANG OLD_LANG

JH_VERSION=`grep 'my $VERSION' qmail-scanner-queue.template|cut -d= -f2|sed -e 's/\"//g' -e 's/\;//g'`
ST_VERSION=`grep 'my $st_version' qmail-scanner-queue.template|cut -d= -f2|sed -e 's/\"//g' -e 's/\;//g'`
QS_VERSION="st-$ST_VERSION"
QS_VERSION="$JH_VERSION$QS_VERSION"

export QS_VERSION

echo
echo "   Building Qmail-Scanner $QS_VERSION..."

if [ "`id |grep root`" = "" ]; then
    cat<<EOF

   Sorry, but this must be run as root, as several operations require - well
   root access :-)


EOF
    exit 1
fi

# st: different check for setuidgid ahead

# st: Simple way to set spamc to check a remote server
#     This was undocumented, maybe the way was  SPAMC_HOST='remote.spmd.com' ./configure
#     I am adding it as a configuration option for P-O Yliniemi
SA_HN=""
if [ "$SPAMC_HOST" != "" ]; then 
  SA_HN="-d $SPAMC_HOST" 
fi

#VERSION=`grep '^# Version: ' qmail-scanner-queue.template`
#VERSION=`echo $VERSION|awk '{print $NF}'`

SUPPORTED_SCANNERS="avgd,avast,clamdscan,clamscan,bitdefender,nod32,esets,clamuko,savscan,sweep,sophie,vscan,trophie,uvscan,csav,antivir,kavscanner,AvpLinux,kavdaemon,AvpDaemonClient,fsav,fpscan,fpscand,inocucmd,ravlin,vexira,verbose_spamassassin,fast_spamassassin,altermime"

SILENT_VIRUSES="klez,bugbear,hybris,yaha,braid,nimda,tanatos,sobig,winevar,palyh,fizzer,gibe,cailont,lovelorn,swen,dumaru,sober,hawawi,hawaii,holar-i,mimail,poffer,bagle,worm.galil,mydoom,worm.sco,tanx,novarg,\@mm,cissy,cissi,qizy,bugler,dloade,netsky,spam"

PWD=${PWD:-`pwd`}
TMPDIR=${TMPDIR:-/tmp}

QSLANG=${OLD_LANG:-en_GB}

if [ "`echo $QSLANG|egrep -i '^en_|^C$'`" != "" ]; then
    #reset all English to en_GB
    QSLANG="en_GB"
fi

if [ ! -d "./locale/$QSLANG" ]; then
    echo "

                ***** NOTE ******

Qmail-Scanner doesn't have language translations for $QSLANG, 
- so defaulting to english...

[Hit <RETURN> to continue]
"
    read ans
    QSLANG="en_GB"
fi

export QSLANG

#Let's grab the list of languages supported

LANGUAGES="`ls  -d locale/[a-z]*|sed 's?^locale\/??g'`"
LANGUAGES=`echo $LANGUAGES`

SPOOLDIR="/var/spool/qscan"
QMAILDIR="/var/qmail"

BINDIR="$QMAILDIR/bin"

VIRUS_MAILDIR="viruses"
SPAM_MAILDIR="spam"
POLICY_MAILDIR="policy"

#QMAILQUEUE_BIN="$BINDIR/qmail-queue"
NORMALIZE_MSG="yes"
ARCHIVEIT="0"
ARCHIVEDIR="archives"
REDUNDANT="1"
FIX_MIME="2"
DISABLE_EOL_CHECK="0"
DEBUG_LEVEL="1"
Q_REJECT_FD="6"
Q_REJECT_EXITCODE="31"
FORCE_UNZIP="0"
DESCRIPTIVE_HEADERS="0"
ADMIN_DESCRIPTION="System Anti-Virus Administrator"
NOTIFY_ADDRESSES="psender,nmlvadm"
USERNAME="$USER"
MANUAL_INSTALL="0"
INSTALLIT="0"
DONOTCONFIRM="0"
LOG_DETAILS="syslog"
LOG_CRYPTO="0"
SKIP_TEXT_MSGS="1"
QS_USER="qscand"
SKIP_SETUID_TEST=""
MAX_ZIP_SIZE="1000000000"
MAX_SCAN_SIZE="100000000"
SA_MAXSIZE="256000"
SA_TIMEOUT="120"
SA_FT="1";
SA_TEMPFAIL=1
ETCDIR="$SPOOLDIR"
LOGDIR="$SPOOLDIR"

MAX_UNPACKED_FILES="10000"

# st patch options
QS_GROUP=""
SETUIDGID=""
DESCR_HEADERS_TEXT="X-Qmail-Scanner"
SETTINGS_P_D="0"
VIRUS_DELETE="0"
SA_FAST=""
SA_SQL="0"
SA_DELTA="0"
SA_SUBJECT=""
SA_FORWARD_IN=""
SA_FORWARD=""
SA_FWD_VERBOSE="0"
SA_QUARANTINE="0"
SA_DELETE="0"
SA_REJECT="0"
SA_ALT="0"
SA_DEBUG="0"
SA_HDR_REPORT="0"
SPAMD_SOCKET=""
SPAMD_REMOTE=""

VIRUS_TO_DELETE="mydoom|worm\\.|novarg|tanx|bagle|netsky|somefool|roca|agobot|dumaru|sober|lovgate|klez|rox|(PIF|SCR|CPL|COM) files|zafi|mabutu|mytob|forbot|nyxem|strat|stradr|hckpk|dorf|psyme|virut|yar-a|ecard|webaccount|faketube|foolball|dropper|pushu"

## st: functions to catch the configure options

boolean_opt () {
  # If empty or looks like true, set option to '1'
  if [ "`echo $1 | egrep -i '^y|^1|^true|^on|^\-'`" != "" -o "$1" = "" ] ; then
      RET_VAL="1"
  elif [ "`echo $1 | egrep -i '^n|^0|^fal|^off'`" != "" ] ; then
      RET_VAL="0"
  else
      echo
      echo "  Oops, unexpected value in option '$2'"
      echo "  Must be [yes|no|1|0], and it is: '$1'"
      echo
      exit
  fi
}

##

while [ -n "$1" ]
do
    case $1 in
        --qs-user) if [ "$2" != "" ] ; then  shift ; fi ; QS_USER="$1" ;; 
        --spooldir) if [ "$2" != "" ] ; then  shift ; fi ; SPOOLDIR="$1" ;;
	--etcdir) if [ "$2" != "" ] ; then  shift ; fi ; ETCDIR="$1" ;;
	--logdir) if [ "$2" != "" ] ; then  shift ; fi ; LOGDIR="$1" ;;
	--docdir) if [ "$2" != "" ] ; then  shift ; fi ; DOCDIR="$1" ;;
	--qmaildir) if [ "$2" != "" ]; then shift ; fi ; QMAILDIR="$1" ;;
	--virusdir) if [ "$2" != "" ]; then shift ; fi ; VIRUS_MAILDIR="$1" ;;
	--bindir) if [ "$2" != "" ] ; then  shift ; fi ; BINDIR="$1" ;;
	--user|--admin) if [ "$2" != "" ] ; then  shift ; fi ; USERNAME="$1" ;;
	--domain) if [ "$2" != "" ] ; then  shift ; fi ; MAILDOMAIN="$1" ;;
	--admin-description|--admin-fromname)
	    if [ "$2" != "" ] ; then  shift ; fi ; ADMIN_DESCRIPTION="$1" ;;
	--notify) if [ "$2" != "" ]; then shift ; fi ; NOTIFY_ADDRESSES="$1" ;;
	--batch)
	    boolean_opt $2 $1 ; DONOTCONFIRM="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--silent-viruses) if [ "$2" != "" ]; then shift ; fi ; FIND_SILENT_VIRUSES="$1" ;;
	--local-domains) if [ "$2" != "" ]; then shift ; fi ; LOCAL_DOMAINS_ARRAY="$1" ;;
	--max-scan-size) if [ "$2" != "" ]; then shift ; fi ; MAX_SCAN_SIZE="$1" ;;
	--lang) if [ "$2" != "" ]; then shift ; fi ; QSLANG="$1" ;;
	--debug|--minidebug) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; fi ; DEBUG="$1" ;;
	--unzip)
	    boolean_opt $2 $1 ; FORCE_UNZIP="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--max-zip-size) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" -a "`echo $2|egrep '^[0-9]+$'`" != "" ] ; then shift ; fi ; MAX_ZIP_SIZE="$1" ;;
	--max-unpacked-files) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" -a "`echo $2|egrep '^[0-9]+$'`" != "" ] ; then shift ; fi ; MAX_UNPACKED_FILES="$1" ;;
	--add-dscr-hdrs) if [ "$2" != "" ] ; then  shift ; fi ; DESCRIPTIVE_HEADERS="$1" ;;
	--scanners) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then shift ; fi ; FIND_SCANNERS="$1" ;;
	--skip-text-msgs)
	    boolean_opt $2 $1 ; SKIP_TEXT_MSGS="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--normalize)
	    boolean_opt $2 $1 ; NORMALIZE_MSG="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
        --archive) ARCHIVEIT="1" ; if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; if [ "`echo $1|egrep -i '^0|^no'`" != "" ]; then ARCHIVEIT="0" ; else  if [ "`echo $1|egrep -i '^1|^yes'`" != "" ]; then ARCHIVEIT="1" ; else  ARCHIVEIT="$1" ; fi ;  fi ; fi ;;
	--redundant)
	    boolean_opt $2 $1 ; REDUNDANT="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--log-details) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; LOG_DETAILS="$1" ;  fi ;;
	--log-crypto) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; LOG_CRYPTO="$1" ;  fi ;;
        --fix-mime) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; if [ "`echo $1|egrep -i '^0|^no'`" != "" ]; then FIX_MIME="0" ; fi ;  if  [ "`echo $1|egrep -i '^[1-9]+$'`" != "" ]; then FIX_MIME="$1" ; fi ;  fi ;;
	--ignore-eol-check)
	    boolean_opt $2 $1 ; DISABLE_EOL_CHECK="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--no-QQ-check) MANUAL_INSTALL="1";;
	--skip-setuid-test) SKIP_SETUID_TEST=1 ; if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; if [ "`echo $1|egrep -i '^1|^yes'`" != "" ]; then SKIP_SETUID_TEST="1" ; fi ;  if  [ "`echo $1|egrep -i '^[1-9]+$'`" != "" ]; then SKIP_SETUID_TEST="$1" ; fi ; if [ "`echo $1|egrep -i '^0|^no'`" != "" ]; then SKIP_SETUID_TEST="0" ; fi ; fi ;;
	--qmail-queue-binary) if [ "$2" != "" ] ; then  shift ; fi ; QMAILQUEUE_BIN="$1" ;;
        --mime-unpacker) if [ "$2" != "" ] ; then  shift ; fi ; MIME_UNPACKER="$1" ;;
        --altermime-disclaimer) if [ "$2" != "" ]; then shift ; fi ; ALTERMIME_DISC="$1" ;;
        --altermime-disclaimer-html) if [ "$2" != "" ]; then shift ; fi ; ALTERMIME_DISC_HTML="$1" ;;
        --altermime-regex) if [ "$2" != "" ]; then shift ; fi ; ALTERMIME_REGEX="$1" ;;
	--sa-timeout) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then  shift ; fi ; SA_TIMEOUT="$1";;
        --sa-maxsize) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ]; then shift ; fi ; SA_MAXSIZE="$1" ;;
        --sa-faulttolerant) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ]; then shift ; fi ; SA_FT="$1";;
	--sa-tempfail) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ]; then shift ; fi ; SA_TEMPFAIL="$1";;
	--install)
	    boolean_opt $2 $1 ; INSTALLIT="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--qs-group) if [ "$2" != "" ] ; then  shift ; fi ; QS_GROUP="$1" ;;
	--setuidgid-path) if [ "$2" != "" ] ; then  shift ; fi ; SETUIDGID="$1" ;;
	--dscr-hdrs-text) if [ "$2" != "" ] ; then  shift ; fi ; DESCR_HEADERS_TEXT="$1" ;;
	--settings-per-domain|--setting-per-domain)
	    boolean_opt $2 $1 ; SETTINGS_P_D="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--virus-to-delete)
	    boolean_opt $2 $1 ; VIRUS_DELETE="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--spamdir) if [ "$2" != "" ]; then shift ; fi ; SPAM_MAILDIR="$1" ;;
	--sa-sql)
	    boolean_opt $2 $1 ; SA_SQL="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-delta) if [ "$2" != "" ] ; then  shift ; fi ; SA_DELTA="$1" ;;
	--sa-subject) if [ "$2" != "" ] ; then  shift ; fi ; SA_SUBJECT="$1" ;;
	--sa-forward) if [ "$2" != "" ] ; then  shift ; fi ; SA_FORWARD_IN="$1" ;;
	--sa-fwd-verbose)
	     boolean_opt $2 $1 ; SA_FWD_VERBOSE="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-quarantine) if [ "$2" != "" ] ; then  shift ; fi ; SA_QUARANTINE="$1" ;;
	--sa-delete) if [ "$2" != "" ] ; then  shift ; fi ; SA_DELETE="$1" ;;
	--sa-reject|--quarantine-reject)
	    boolean_opt $2 $1 ; SA_REJECT="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-alt)
	    boolean_opt $2 $1 ; SA_ALT="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-debug)
	    boolean_opt $2 $1 ; SA_DEBUG="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-report)
	    boolean_opt $2 $1 ; SA_HDR_REPORT="$RET_VAL" ; if [ "`echo $2 | egrep -i '^\-'`" = "" ] ; then shift ; fi ;;
	--sa-socket)  if [ "$2" != "" ] ; then  shift ; fi ; SPAMD_SOCKET="$1" ;;
	--sa-remote)  if [ "$2" != "" ] ; then  shift ; fi ; SPAMD_REMOTE="$1" ;;
        *) cat <<EOF >&2

   Invalid option: $1        [ --help is a valid option ;-) ]

valid options:

  --qs-user <username>            (default: qscand)
                   User that Qmail-Scanner runs as.

  --qs-group <usergroup>          (default: same as qs-user)
                   Group that Qmail-Scanner runs as, qs-user must
                   be member of this group.

  --qmaildir <top of qmail>       (defaults to /var/qmail)

  --spooldir <spooldir>           (defaults to $SPOOLDIR)

  --bindir <installdir>           (defaults to /var/qmail/bin)
                   Where to install Qmail-Scanner programs

  --setuidgid-path <path to setuidgid program>
                   Defaults to nothing, the configure script will
                   search for it, this option is only necessary if
                   'setuidgid' from daemontools packet is installed
                   in an unusual path.

  --admin <username>              (default: $USERNAME)
                   User to Email alerts to

  --domain <domain name>
                   "user"@"domain" makes up Email address to Email alerts to

  --admin-description <"description">  (default: "System Anti-Virus Administrator")
                   From line  information used when making reports, the input
                   must be quoted. i.e. --admin-description "Antivirus Admin"

  --scanners <list of installed content scanners>
                   Defaults to "auto" - will use whatever scanners are found
                   on system.
                   Use this option to override "auto" - set to one or more
                   of the following:

                   [auto|none|$SUPPORTED_SCANNERS]

                   Note the special-case "none". This will disable all but
                   the internal perlscanner module.

  --skip-text-msgs [yes|no]       (defaults to "yes")
                   Q-S will skip running any anti-virus scanner on any messages
                   it works out are text-only. i.e. don't have any attachments.
                   Set to "no" if you want them to be scanned anyway.

  --normalize [yes|no]            (defaults to "$NORMALIZE_MSG")
                   This decides if base64/qp attachment 
                   filenames and/or Subject: headers should 
                   be "normalized" back to their decoded form 
                   before being checked against entries in
                   quarantine-events.txt.

  --notify [none|sender|recips|precips|admin|nmladm|nmlvadm|all] (defaults to "$NOTIFY_ADDRESSES")
                   Comma-separated list (no spaces!) of addresses to which
                   alerts should be sent to. "nmladm" means only notify
                   admin for "user infections", 
                   i.e. non-mailing-list mail.
                   "nmlvadm" is the same as nmladm - except that it also doesn't
                   notify for viral e-mails.
                   i.e. just "policy" quarantines get e-mails.
                   This allows you to still notify people when an e-mail is
                   blocked due to a policy decision (such as blocking
                   password-protected zip files), but a message tagged as viral
                   by an AV system will *not* trigger notification.
                   Similarly, "psender"/"precips" means notify the 
                   sender/recips only  if their e-mail was blocked for policy
                   reasons. i.e. if an AV system  found a virus, then don't
                   notify the sender/recip as the address was probably forged.

  --local-domains "one.domain,two.domain"
                   Defaults to the value of the "--domain" setting.
                   Comma-separated list (no spaces!)  of domains that are
                   classified as "local". This is needed to ensure alerts
                   are only sent to local users and not remote when
                   '--notify "*recips"' is chosen. This will drastically
                   reduce the chance of alerts being sent to mailing-lists.

  --silent-viruses "virus1,virus2"     (defaults to "auto")
                   (This option is almost deprecated)
                   This option allows you to tell  Qmail-Scanner *not* to
                   notify senders when it quarantines one of these viruses.
                   Viruses such as Klez alter the sender address so that it
                   has no relation to the actual sender - so there's no point
                   in responding to Klez messages - it just confuses people.
                   The admin and recips will still be notified as set
                   by "--notify". Use this option to override "auto".
                   By default this is set to:
                   "$SILENT_VIRUSES"

  --lang <lang>                   (defaults to "$QSLANG")
                  "$LANGUAGES"

  --archive [yes|no|regex]        (defaults to "no")
                   Whether to archive mail after it as been processed.
                   If "yes", all copies of processed mail will be moved into
                   the maildir "$SPOOLDIR/$ARCHIVEDIR/".
                   Any other string besides "yes" and "no" will be treated
                   as a REGEX. Only mail from or to an address that contains
                   that regex will be archived. e.g. "jhaar|harry" or
                   "\@our.domain".
                   Be careful with this option, a badly written regex
                   will cause Qmail-Scanner to crash.

  --redundant [yes|no]            (defaults to "yes")
                   Whether or not to let the scanners also scan any zip files
                   and the original "raw" Email file.

  --unzip    [yes|no]             (defaults to "no" - off)
                   Whether or not to forcibly unzip all zip files.
                   Off by default as most AV's do unzip'ping themselves.

  --altermime-disclaimer [filename.txt]
                   Sets the filename for altermime to use for plain text emails.
                   If you only set this variable and not the one below
                   then this disclaimer will be used on all messages.

  --altermime-disclaimer-html [filename.txt|filename.html]
                    Sets the filename for altermime to use for html emails.
                    You must set the variable above and not just this one.
   
  --altermime-regex "regex"       (defaults to off)
                    Sets the regular expression on what domains to add the
                    disclaimer text.

  --max-zip-size <number-bytes>   (defaults to 1 Gbytes)
                   This setting allows you to control the maximum size you
                   are willing to allow zip file attachments to unpack to.
                   This is to enable you to limit DoS attacks against your
                   Qmail-Scanner installation (someone could send you a small
                   zip file that unpacks to Gbytes of useless files - filling
                   your harddisk). Set to whatever value you think is
                   appropriate for your system. The default value of 1Gb is
                   set so large so as not to assume anything about your
                   system - YOU WILL NEED TO SET THIS VALUE IN ORDER TO GAIN
                   ANY PROTECTION.
                   Something like "100000000" (100 Mb) might be appropriate.

  --max-unpacked-files <number-files>   (defaults to 10000 files)

  --max-scan-size <number-bytes>        (defaults to 100 Mbytes)
                   Email messages (raw size) larger than this 
                   number (in bytes) will skip all AV and Spam 
                   scanning checks. It's to stop Q-S scanning
                   300Mbyte TIFF file messages and the like.

  --log-crypto [yes|no]           (defaults to "no")
                   Whether or not to log the presence
                   of cryptographic (both signing and encrypting)
                   technologies in the "log-details". Q-S can flag
                   PGP, S/MIME and password-protected zip files. This
                   is informational logging only.

  --fix-mime [yes|no|num]         (defaults to "2")
                   Whether or not to attempt to "fix" broken MIME messages
                   before doing anything else. Should be safe, but *may* break
                   some strange, old mailers (none known yet). If you see
                   blocks occurring due to this setting, try "--fix-mime 1"
                   first before "--fix-mime no".
                   Defaults to "2" enables a bunch of extra MIME checks that
                   have proven to be very useful.

  --ignore-eol-check [yes|no]     (defaults to "no")
                   Making this "yes" stops Qmail-Scanner
                   from treating "\r" or "\0" chars in the headers of 
                   MIME mail messages as being suspicious enough to quarantine
                   mail over.
                   st: Unfortunately there are too many mailers that send
                   some "\r" in their headers so, the option is enabled
                   by default.

  --add-dscr-hdrs [yes|no|all]    (defaults to "no")
                   This adds the now old-fashion X-Qmail-Scanner headers to
                   the message. "all" adds the "rcpt to" headers too - this is
                   a privacy hole.

  --dscr-hdrs-text <"Descrip-Headers-Text">   (defaults to "X-Qmail-Scanner")
                   Input must be quoted and must not contain spaces.
                   i.e. --dscr-hdrs-text "X-Antivirus-MYDOMAIN"

  --log-details [yes|syslog|no]   (defaults to "syslog")
                   Whether or not to log to mailstats.csv/via syslog the
                   attachment structure of every Email message.

  --debug [0|1|2|3|4|5]           (defaults:1)
                   Whether or not debugging is turned on. Can be also set to
                   a number. Numbers over 100 cause Q-S to not cleanup working
                   files. Thus allowing for offline debugging...
                   debug >= 5, all info is logged.

  --batch [yes|no]                 (default: no = ask for confirm)
                   Do not confirm configure information (mainly for scripting)
                   Set to yes if you are doing scripting.

  --install [yes|no]               (default: no)
                   Create directory paths, install perl script, and
                   change ownerships to match.

  --mime-unpacker "reformime"     (defaults to reformime)

  --spamdir <maildir name>        (defaults to "$SPAM_MAILDIR")
                   This will be the maildir directory structure
                   into which spam mails are quarantined 
                   (under $SPOOLDIR/quarantine/$SPAM_MAILDIR)
                   It is possible to set it per user/domain enabling the
                   feature settings-per-domain, see the docs.

  --sa-timeout [num]              (defaults to "$SA_TIMEOUT")
                   This is the max number of seconds
                   you will allow spamc to take on processing
                   a mail message. Anything longer implies
                   spamd has hung on some narly DNS lookup
                   or the like, and will cause QS to give
                   the message a SPAM score of (?/?)

  --sa-faulttolerant [yes|no]     (defaults to "$SA_FT")
                   This can be used in addition to sa-timeout
                   as a way of telling Qmail-Scanner to let
                   SA "have another go" at processing a message
                   if it was unable to get it right the first time.
                   It will cause Q-S to run SA up to THREE TIMES
                   on a particular email - if SA fails to return any
                   value (in the past this used to lead to Q-S reporting
                   (?/?)). This can get around emails from far-off domains
                   that "hang" SA due to DNS lookups - and *may* allow SA
                   to operate correctly the next time it is called on the same
                   message. See "--sa-tempfail" for even more
                   reliability options

  --sa-maxsize [num]              (defaults to "$SA_MAXSIZE")
                   This size (in bytes) sets the
                   max size email that will be
                   processed by SpamAssassin.

  --sa-tempfail [yes|no]          (defaults to "$SA_TEMPFAIL")
                   Should Qmail-Scanner treat SpamAssassin
                   like AV products and tempfail if it 
                   fails to return a score?


  --settings-per-domain [yes|no]        (defaults to "no")
                   Enable or disable the domain-wise mode, each user/domain
                   will have a customized settings (@scanner_array and
                   sa_settings). If the user/domain haven't a custom 
                   settings, qmail-scanner will fall to the defaults
                   site settings (@scanner_array and sa_site_settings).

  --virus-to-delete [yes|no]      (defaults to "no")
                   Enable this option if you want to delete some viruses
                   (i.e. mydoom) without notifying anyone. If you don't enable
                   it now, you can later edit qmail-scanner-queue.pl and add
                   the virus you want to the list virus_to_delete.

  --sa-sql [yes|no]               (defaults to "no")
                   Whether to run spamassassin with the 'rcpt to' as option,
                   only useful if you are running spamassassin with user
                   settings in mysql.
                   If you enable 'settings-per-domain' a message with multiples
                   recipients will be scanned for each recipient with his
                   own spamassassin settings.

  --sa-delta [num]                (default: 0)
                   If $spamc_subject is defined, and fast_spamassassin mode is
                   selected, a tag will be added to the subject indicating how
                   the message is to be considered as spam, in this way:
                   LOW: required_hits < score < required_hits + sa_delta
                   MEDIUM: required_hits + sa_delta < score < required_hits + 2 * sa_delta
                   HIGH: required_hits + 2 * sa_delta < score
                   Be aware, sa_max+2*sa_delta must be lower than sa_quarantine.
                   'required_hits' is the value set in the SpamAssassin
                   configuration file.

  --sa-subject <"some text">   (defaults to nothing)
                   This is an alternative way to set the tag that qmail-scanner
                   add to subject of spam mails, to some text.
                   Spamassassin must be working in *fast_spamassassin* mode
                   Be sure that is better to tag the subject, of spam messages,
                   through qmail-scanner than with the rewrite_subject
                   of SpamAssassin.
                   The input must be quoted i.e. "SPAM *** ". 

  --sa-forward <username@domain>              (defaults to nothing)
                   User to redirect spam mails 'being quarantined' for
                   admin purposes...
                   The message is forwarded almost unmodified so you can
                   use 'sa-learn' with them.
                   If you prefer that the message includes the spam headers
                   enable the next option.
                   (i.e.  --sa-forward antispam@mydomain.com)

  --sa-fwd-verbose [yes|no]       (default: no)
                   Whether to add the X-Spam headers to the forwarded message.

  --sa-quarantine [num]           (default: 0)
                   Spam messages with a score higher than
                   (required_hits + sa_quarantine) should be quarantined.
                   Only relevant if SpamAssassin is used.
                   Score of 0 means deliver all messages.

  --sa-delete [num]               (default: 0)
                   Spam messages with a score higher than
                   (required_hits + sa_delete) should be deleted.
                   Only relevant if SpamAssassin is used.
                   Score of 0 means deliver all messages.

  --sa-reject [yes|no]            (default: no)
  --quarantine-reject [yes|no]
                   If you enable sa-reject and sa-delete is properly set,
                   messages with a score higher than sa-delete will be rejected
                   before the smtp session is closed. Otherwise they are just
                   dropped silently. (1/0)
                   Different from the official version, only spam mails are
                   rejected, if your installation has the 'custom error patch'
                   a nice little text message is sent, those without just
                   produce a generic Qmail error. BE CAREFUL IF ENABLING AND
                   YOUR Q-S SERVER ISN'T DIRECTLY FACING THE INTERNET

  --sa-alt [yes|no]               (default: no)
                   Use the alternative subroutine for spamassassin, it runs in
                   *fast_spamassassin* mode and doesn't pass the '-u' option
                   to spamc. (1/0)

  --sa-debug [yes|no]             (default: no)
                   If sa-alt is enabled an you enable this option, you will
                   have a beautiful log with the tests and the scores of
                   spamassassin in the file qmail-queue.log (1/0)

  --sa-report [yes|no]            (default: no)
                   If sa-alt is enabled you can add the X-Spam-Report header
                   to the messages enabling this option.

  --sa-socket <path to spamd socket>    (defaults to nothing)
                   Actually the configure script can automatically discover
                   if spamd is running in unix-socket mode, but,
                   if for some reasson the socket couldn't be
                   found properly you can set the path with this option.
                   i.e. --sa-socket /var/run/spamd

  --sa-remote remote.spamd.host[,port]  (defaults to nothing)
                   You can use the hostname or the ip address, if not specified
                   the default port is 783

       ****************
         Rarely Used
       ****************

  --no-QQ-check
                   Do not check that the QMAILQUEUE patch is installed.
                   This explicitly disables any "--install" reference
                   as that is NOT POSSIBLE with a manual install.
                   Use ONLY IF YOU MUST. The QMAILQUEUE patch is REALLY
                   a GOOD THING!!!!

  --skip-setuid-test
                   don't test for setuid perl. Only of use for those wanting
                   to run the C-wrapper version.

  --qmail-queue-binary
                   Set this to the FULL PATH to the Qmail qmail-queue
                   binary. This is only EVER set when doing a manual install.


This script must be run as root so it can detect problems with setuid
perl scripts! 

invalid option: $1        [ --help is a valid option ;-) ]

See above for the valid options

EOF
           exit 1 ;;
    esac
    shift
done


DOCDIR="/usr/share/doc/Qmail-Scanner-${VERSION}"


if [ "$QS_GROUP" = "" ]; then QS_GROUP=$QS_USER ; fi

# st: will this always work?
# st: Solaris 10 has the standard 'id' command in an unsual PATH
# thanks to Lorenzo Patocchi for the hint
PATH="/usr/xpg4/bin:$PATH" export PATH

UU="`id -u $QS_USER 2>/dev/null`"
UG="`id -gn $QS_USER 2>/dev/null`"
GG="`id -Gn $QS_USER 2>/dev/null`"
CHKGG="`echo /$GG/ | sed -e 's: :/:g' | grep /$QS_GROUP/`"


# st: I don't need that QS_USER belongs to QS_GROUP but I don't find
# a way to check the QS_GROUP even with NIS/LDAP

if [ "$UU" = "" -o "$CHKGG" = "" ]; then
echo "######################################################
Fatal Error: Qmail-Scanner must be installed and run as
a separate account and proper group. See below
for details.
"

  if [ "$CHKGG" = "" ]; then
echo "GROUP ERROR

User '$QS_USER' does not belong to group '$QS_GROUP', or
group '$QS_GROUP' does not exist.

To create it, e.g.:

   groupadd $QS_GROUP
"

     if [ "$UU" != "" -a "$UG" != "" ]; then
echo "If group '$QS_GROUP' exists you can try to add '$QS_USER' to it
with the 'usermod' command, but it won't work if you are in a 
LDAP or NIS enviroment.

Alternatively install with options:

   ./configure --qs-user $QS_USER --qs-group $UG [...]
"
     fi
  fi

  if [ "$UU" = "" ]; then
echo "USER ERROR

user '$QS_USER' doesn't exist, please create it. e.g.

useradd -c \"Qmail-Scanner Account\" -g $QS_GROUP -d $SPOOLDIR -s /bin/false $QS_USER
"
  fi

echo "(If your are using NIS/LDAP you will know how and where
adding new users and/or groups, I suppose...)
######################################################"
exit 1
fi

#Reset these Qmail vars again so that any changes made during configure time 
#come out here too

#QMAILQUEUE_BIN="${QMAILQUEUE_BIN:-$BINDIR/qmail-queue}"

#Sanity check that suid is allowed on the Qmail "/bin" partition
QMNT=`df $BINDIR|head -2|tail -1|awk '{print $1}'`
SUIDSTATUS=`mount|egrep "^$QMNT "|grep nosuid`
if [ "$SUIDSTATUS" != "" ]; then
	cat<<EOF
	
            *** FATAL ERROR ***

As far as I can tell, $BINDIR is mounted on a nonsuid file partition ($QMNT).

This means even Qmail will not operate correctly!

Please sort out your system before trying to install this...

EOF
	exit 1
fi

if [ "$SPAMD_SOCKET" != "" -a "$SPAMD_REMOTE" != "" ]; then
echo "
######################################################
Error: you have set 'sa-socket' and 'sa-remote', 
this configure script cannot work with both set.
Please fix it and try again.
######################################################
"
exit 1
fi

if [ "$SPAMD_REMOTE" != "" -a "$SA_HN" = "" ]; then
    if [ "`echo $SPAMD_REMOTE | grep ','`" != "" ]; then
        SA_HN="`echo $SPAMD_REMOTE | cut -d ',' -f1`"
        SA_HNPORT="`echo $SPAMD_REMOTE | cut -d ',' -f2`"
        SA_HN="-d $SA_HN -p $SA_HNPORT"
    else
        SA_HN="-d $SPAMD_REMOTE"
    fi
fi

if [ "$FIND_SILENT_VIRUSES" = "" -o "`echo $FIND_SILENT_VIRUSES|grep auto`" != "" ]; then
    FIND_SILENT_VIRUSES="$SILENT_VIRUSES"
fi

if [ "$FIND_SILENT_VIRUSES" != "" ]; then
    FIND_SILENT_VIRUSES="`echo $FIND_SILENT_VIRUSES|sed -e 's/\"//g'  -e 's/ //g'`"
    if [ "$FIND_SILENT_VIRUSES" != "" ]; then
	VLA=""
	for virus in `echo $FIND_SILENT_VIRUSES|sed 's/,/ /g'`
	do
	    VLA="$VLA,'$virus'"
	done
	FIND_SILENT_VIRUSES_ARRAY="`echo $VLA|sed 's/^,//g'`"
    fi
fi

if [ "$FIND_SCANNERS" = "" -o "`echo $FIND_SCANNERS|grep auto`" != "" ]; then
    FIND_SCANNERS="$SUPPORTED_SCANNERS"
    AUTO_FIND_SCANNERS=1
fi

if [ "`echo $FIND_SCANNERS|grep none`" != "" ]; then
    FIND_SCANNERS="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
fi


FIND_SCANNERS="_ $FIND_SCANNERS _"

if [ "$MANUAL_INSTALL" != "0" ]; then
    INSTALLIT="0"
fi

if [ ! -d "./locale/$QSLANG" ]; then
    echo "

                ***** NOTE ******

Qmail-Scanner doesn't have language translations for $QSLANG, 
- so setting back to english...
"
    if [ "$DONOTCONFIRM" != "1" ]; then
      echo "[Hit <RETURN> to continue]
"
      read ans
    fi
    QSLANG="en_GB"
fi

export QSLANG


cat<<EOF

This script will search your system for the virus scanners it knows
about, and will ensure that all external programs
qmail-scanner-queue.pl uses are explicitly pathed for performance
reasons.

EOF

if [ "$INSTALLIT" != "1" ]; then 
 cat<<EOF

It will then generate qmail-scanner-queue.pl - it is up to you to install it
correctly.

EOF
fi
if [ "$DONOTCONFIRM" != "1" ]; then
 cat<<EOF
Continue? ([Y]/N)
EOF
 read ans
 if [ "`echo $ans|grep -i n`" != "" ]; then
    exit 1
 fi
fi
echo -n "Searching ."

 PATH="$PATH:$QMAILDIR/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/etc/iscan:/usr/local/uvscan:/usr/lib/AntiVir:/usr/lib/uvscan:/usr/local/av:/opt/AV:/opt/AVP:/opt/f-prot:/usr/local/rav8/bin:/usr/lib/Vexira:/opt/bdc:/opt/kav/bin:/usr/local/nod32:/usr/local/esets:/opt/sophos-av/bin" export PATH

if [ "$MIME_UNPACKER" != "" ]; then
	if [ "`echo $MIME_UNPACKER |egrep -v '^(reformime|ripmime)$'`" != "" ]; then
	    cat<<EOF


                *************************

Sorry, but your "--mime-unpacker" definition contains invalid options. 

The only valid options are:

reformime
ripmime

               **************************
EOF
	    exit 1
	fi
else
	MIME_UNPACKER="reformime"
fi



NOTIFY_ADDRESSES="`echo $NOTIFY_ADDRESSES|sed -e 's/\"//g'  -e 's/ //g'`"

if [ "$NOTIFY_ADDRESSES" = "all" ]; then
    NOTIFY_ADDRESSES="sender,admin,recips"
fi

if [ "$NOTIFY_ADDRESSES" ]; then
     for addr in `echo $NOTIFY_ADDRESSES|sed 's/,/ /g'`
     do
	if [ "`echo $addr|egrep -v '^(admin|nmladm|nmlvadm|none|sender|psender|recips|precips|all)$'`" != "" ]; then
	    cat<<EOF


                *************************

Sorry, but your "--notify" definition contains invalid options. 

The only valid options are:

none
admin
nmladm
nmlvadm
sender
psender
recips
precips
all

               **************************
EOF
	    exit 1
	fi
     done
fi

echo -n "."

#Check out command line

SCANNERS=`echo $FIND_SCANNERS|sed -e 's/^_ //' -e 's/ _$//'`

if [ "$SCANNERS" = "$SUPPORTED_SCANNERS" ]; then
    SCANNERS="auto"
fi

FIND_SCANNERS=" `echo $FIND_SCANNERS|sed 's/,/ /g'` "

rm -f 1234.* 2> /dev/null
DD="`mktemp -d 1234.XXXXXX  2>&1`"
if [ "`ls 1234.* 2>/dev/null`" != "" ]; then
    if test -d "$DD" ; then
	TMP_DIR="`mktemp -d /tmp/mkt_qs.XXXXXX`"
    fi
fi
if [ "$TMP_DIR" = "" ]; then
    TMP_DIR="/tmp/mkt_qs.$$-`date +%s`"
    mkdir $TMP_DIR
fi

rm -rf 1234* "$DD"

TMPFILE="$TMP_DIR/tempfile"
touch $TMPFILE
chmod -R 775 $TMP_DIR/

#Let's create a test EICAR virus to ensure
#the installed virus scanners are working
echo  'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > $TMP_DIR/eicar.com
chown $QS_USER:$QS_GROUP $TMP_DIR/eicar.com
chmod 644  $TMP_DIR/eicar.com

# st: We need 'setuidgid' to test the antivirus, so let
# check if daemontools are installed...

if [ "$SETUIDGID" = "" ]; then
    if test -x /usr/local/bin/setuidgid ; then
        SETUIDGID="/usr/local/bin/setuidgid"
    elif test -x /usr/local/daemontools/bin/setuidgid ; then
        SETUIDGID="/usr/local/daemontools/bin/setuidgid"
    elif test -x /usr/bin/setuidgid ; then
        SETUIDGID="/usr/bin/setuidgid"
    elif test -x /commands/setuidgid ; then
        SETUIDGID="/commands/setuidgid"
    elif [ "`setuidgid 2>&1|grep 'setuidgid account child'`" != "" ]; then
        cat<<EOF

                *************************
It seems that 'setuidgid' it is installed in your system,
but not where this configure script expected it might be.

Please use the option '--setuidgid-path /path/to/setuidgid'
                *************************

EOF
exit

    else
        cat<<EOF

                *************************
It seems that 'setuidgid' it is not installed in your system,
this configure script use it to perform some tests with your
antivirus and check the 'suidperl' behaviour.

You can continue the installation but the tests of your antivirus
won't be run as $QS_USER, this is not essential but it is important. 

You can install any version of daemontools:
http://cr.yp.to/daemontools.html
http://cr.yp.to/daemontools/daemontools-0.70.tar.gz
http://cr.yp.to/daemontools/daemontools-0.76.tar.gz

Maybe you will need this patch:
http://djbware.csi.hu/patches/daemontools-0.76.errno.patch

You don't need to use the daemontools to start qmail, this script
only needs 'setuidgid', so I personally recommend version 0.70 the
patch could be applied also to version 0.70
                *************************

   Continue anyway? (Y/[N])

EOF
        read ans
        if [ "`echo $ans|grep -i y `" == "" ]; then
           exit
        fi
    fi
else
    if [ "`$SETUIDGID 2>&1|grep 'setuidgid account child'`" = "" ]; then
        cat<<EOF

                *************************
'setuidgid' it is not installed in the path you have
supplied: '$SETUIDGID'

Please fix it or let me to look for it in the usual paths:
/usr/local/bin/setuidgid
/usr/local/daemontools/bin/setuidgid
/usr/bin/setuidgid
/commands/setuidgid
                *************************

EOF
        exit
    fi
fi

if [ "$SETUIDGID" != "" ] ; then
   SETUIDGID_QS="$SETUIDGID $QS_USER"
   SETUIDGID_QQ="$SETUIDGID qmailq"
else
   SETUIDGID_QS=""
   SETUIDGID_QQ=""
fi

# st: trying to reduce the elapsed time for the search
SEARCHED=""

for dir in `echo $PATH|sed 's/:/ /g'`
do
  echo -n "."
  # st: check if $dir exist and we haven't search in it
  if [ -d $dir -a "`echo $SEARCHED | grep :$dir`" = "" ]; then
    if test -x $dir/perl
    then
	PERLRELEASE_DETAILS=${PERLRELEASE_DETAILS:-`$dir/perl -V 2>&1|grep perl5 |head -1`}
	if [ "$?" = "0" ]; then	
	    PERL5="${PERL5:-$dir/perl}"
	fi
    fi    
    if test -x $dir/suidperl
    then
	SUIDPERL="${SUIDPERL:-$dir/suidperl}"
    fi
    if test -x $dir/rm ; then RM_BINARY="${RM_BINARY:-$dir/rm}" ; fi
    if test -x $dir/grep ; then GREP_BINARY="${GREP_BINARY:-$dir/grep}" ; fi
    if test -x $dir/hostname
    then
	HOST="${HOST:-`$dir/hostname`}"
    fi
    if test -x $dir/uname
    then
	UNAME="${UNAME:-`$dir/uname -n`}"
    fi

    if test -x $dir/qmail-inject
    then
	QMAILINJECT_BIN="${QMAILINJECT_BIN:-$dir/qmail-inject}"
    fi

    if test -x $dir/qmail-queue
    then
	QMAILQUEUE_BIN="${QMAILQUEUE_BIN:-$dir/qmail-queue}"
    fi

    if test -x $dir/qmail-smtpd
    then
	QMAILSMTPD="${QMAILSMTPD:-$dir/qmail-smtpd}"
    fi

#    if test -x $dir/setuidgid
#    then
#	SETUIDGID="${SETUIDGID:-$dir/setuidgid}"
#    fi
    if test -x $dir/strings
    then
	STRINGS="${STRINGS:-$dir/strings}"
    fi

if [ "$MIME_UNPACKER" = "reformime" ]; then
    if test -x $dir/reformime
    then
	UNMIME_BINARY="${UNMIME_BINARY:-$dir/reformime}"
        DD=`reformime -s1.2 -xTEST- < ./contrib/reformime-test.eml`
	if [ "`grep hello TEST-hello.txt`" = "" ]; then
	   echo "** FATAL ERROR ***"
	   echo ""
	   echo "$UNMIME_BINARY contains bugs. Please upgrade to a release"
	   echo "that post-dates Mar 22 2002 (e.g. 1.3.8)"
	   echo ""
	   rm -f TEST-hello.txt
	   exit 1
	fi
	rm -f TEST-hello.txt
    fi    
    if test -x $dir/maildrop
    then
	MAILDROP_BINARY="${MAILDROP_BINARY:-$dir/maildrop}"
    fi    
    #Note that TNEF is only defined if using reformime as
    #ripmime does TNEF support internally
    if test -x $dir/tnef
    then
	TNEF_BINARY="${TNEF_BINARY:-$dir/tnef}"
	#There's a LOCALE bug in uudecode - workaround...
	if [ "`$TNEF_BINARY --help 2>&1|grep number-backups`" = "" ]; then
	    TNEF_BINARY=""
	    cat<<EOF

Old tnef binary found on your system!

Please upgrade ASAP to a version supporting the "--number-backups" option.

EOF
	    exit 1
	fi
    fi
fi
if [ "$MIME_UNPACKER" = "ripmime" ]; then
    if test -x $dir/ripmime
    then
	UNMIME_BINARY="${UNMIME_BINARY:-$dir/ripmime}"
        DD=`ripmime -i - < ./contrib/reformime-test.eml`
	if [ "`grep hello hello.txt`" = "" ]; then
	   echo "** FATAL ERROR ***"
	   echo ""
	   echo "$UNMIME_BINARY contains bugs. Please upgrade to a newer release."
	   echo ""
	   rm -f hello.txt textfile*
	   exit 1
	fi
	rm -f hello.txt textfile*
    fi
fi
    if test -x $dir/unzip
    then
	UNZIP_BINARY="${UNZIP_BINARY:-$dir/unzip}"
	#Now check for password support
	UNZIP_PASSWD="xx${RANDOM}$$xx"
	DD=`unzip -Ptest -t contrib/test_password.zip 2>&1|egrep 'testing:.*OK'`
	if [ "$DD" != "" ]; then
	 UNZIP_OPTIONS="-P$UNZIP_PASSWD"
	else
	 UNZIP_OPTIONS=""
	fi
	#Now check we can get filesizes out
	EE=`unzip -Ptest -lv contrib/test_password.zip 2>&1|egrep '80688.*test/ls'`
	if [ "$EE" = "" ]; then
	    echo "**FATAL ERROR ***"
	    echo ""
	    echo "$UNZIP_BINARY doesn't support the \"-lv\" option to view file details"
	    echo ""
	    echo "Please upgrade to another version of unzip"
	    echo ""
	    exit 1
	fi
    fi    

    if test -x $dir/avgscan
    then
	if [ "`echo $FIND_SCANNERS | grep ' avgd '`" != "" ]; then
	    AVGD_CONFIG_FILE="/etc/avg.conf"
	    AVGD_PORT="55555"
	    if [ -e $AVGD_CONFIG_FILE  ]; then
		AVGD_PORT_TMP="`cat /etc/avg.conf | grep -e port[[:space:]]*=[[:space:]]*[[:digit:]]* | sed s/[[:space:]]//g | cut -f2 -d'='`"
		if [ "$AVGD_PORT_TMP" = "" ]; then
		  AVGD_PORT=$AVGD_PORT_TMP
		  echo "Warning: Can not find the port number option in the $AVGD_CONFIG_FILE configuration file (using default $AVGD_PORT)"
		fi
		TEST_OUTPUT=`perl ./contrib/test-avgd.pl -p $AVGD_PORT -d $TMP_DIR 2>&1`
		if [ "`echo $TEST_OUTPUT | egrep -i '403'`" != "" ]; then
		    AVGD="${AVGD:-$dir/avgscan}"
		    INSTALLED_SCANNERS="$INSTALLED_SCANNERS avgd"
		else
		    if [ "$ERROR_ONCE" != "done" ]; then
			echo
			echo "Error: The AVG Anti-Virus daemon test failed. Please see the output below."
			echo "       Probably the AVG Anti-Virus daemon in not running!"
			echo
			echo "output from the AVG Anti-Virus daemon test skript:"
			echo "$TEST_OUTPUT"
			echo
			echo "Please fix this and run the qmail-scanner configure script again!"
			echo
			ERROR_ONCE="done"
		    fi
		fi
	    else
		echo "Error: Can not find the AVG Anti-Virus configuration file $AVGD_CONFIG_FILE"
	    fi
	fi
    fi	
	
    if test -x $dir/uvscan 
    then
	if [ "`echo $FIND_SCANNERS|grep ' uvscan '`" != "" -a "$UVSCAN" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/uvscan -r --secure --fam --unzip --macro-heuristics -v $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		UVSCAN="${UVSCAN:-$dir/uvscan}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
uvscan"
	    fi
	fi
    fi    
    if test -x $dir/csav
    then
	if [ "`echo $FIND_SCANNERS|grep ' csav '`" != "" -a "$CSAV" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/csav -list -nomem -packed -archive -noboot $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		CSAV="${CSAV:-$dir/csav}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
csav"
	    fi
	fi
    fi
    if [ "`echo $FIND_SCANNERS|grep ' sophie '`" != "" -a "$SOPHIE" = "" ]; then
    if test -x $dir/sophie
    then
	SOCKET="`$SETUIDGID_QS $dir/sophie -d -f README 2>&1|grep 'Socket path'|awk '{print $NF}'|sed 's/\"//g'`"	
	if [ "$SOCKET" != "" ]; then
	    DD=
	    if [ "`$SETUIDGID_QS perl ./contrib/test-sophie.pl -s $SOCKET -f $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		SOPHIE="${SOPHIE:-$dir/sophie}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
sophie"
		SSOCKET="$SOCKET"
	    else 
	        echo "
Something like sophie for Sophos detected - but is not correctly installed or operational. 
Please read Q-S FAQ if you want it - especially check that sophie daemon 
can read files owned by $QS_USER (i.e. run it as $QS_USER).
".
	    fi
	fi
    fi
    fi
    if [ "`echo $FIND_SCANNERS|egrep ' (sophie|savscan|sweep) '`" != "" ]; then
    if test -x $dir/savscan
    then
	if [ "`$dir/savscan -h 2>&1|grep LAM`" = "" -a "$SAVSCAN" = "" ]; then
	   if [ "`setuidgid $QS_USER $dir/savscan -f -eec -all -sc -nc -ss -nb -archive $TMP_DIR  2>&1|egrep -i 'virus|test'`" != "" ]; then
		SAVSCAN="$dir/savscan"
		SWEEP="$SAVSCAN"
		INSTALLED_SCANNERS="`echo \"$INSTALLED_SCANNERS\"|grep -v sweep`"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
savscan"
	   fi
	   if [ "$SAV_IDE" = "" ]; then
                if [ ! -f "/etc/sav.conf" ]; then
                  if [ -d "/opt/sophos-av/lib/sav" ]; then
                    SAV_IDE="/opt/sophos-av/lib/sav"
                  fi
               else
                    SAV_IDE_CONF="1"
                fi
            fi
	fi
    fi
    if test -x $dir/sweep
    then
	if [ "`$dir/sweep -h 2>&1|grep LAM`" = "" -a "$SWEEP" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/sweep -f -eec -all -sc -nc -ss -nb -archive $TMP_DIR  2>&1|egrep -i 'virus|test'`" != "" ]; then
		SWEEP="${SWEEP:-$dir/sweep}"	
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
sweep"
	    fi
	    if [ "$SAV_IDE" = "" ]; then
		if [ ! -f "/etc/sav.conf" ]; then
		  if [ -d "/usr/local/sophos" ]; then
		    SAV_IDE="/usr/local/sophos"
		  fi
		  if [ -d "/usr/local/sav" ]; then
		    SAV_IDE="/usr/local/sav"
		  fi
		else 
		    SAV_IDE_CONF="1"
		fi
	    fi
	fi
    fi    
    fi
    if [ "`echo $FIND_SCANNERS|grep ' trophie '`" != "" -a "$TROPHIE" = "" ]; then
    if test -x $dir/trophie
    then
	SOCKET="`$SETUIDGID_QS $dir/trophie -d -f README 2>&1|grep 'Socket path'|awk '{print $NF}'|sed 's/\"//g'`"
	if [ "$SOCKET" != "" ]; then
	    if [ "`$SETUIDGID_QS perl ./contrib/test-trophie.pl -s $SOCKET -f $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		TROPHIE="${TROPHIE:-$dir/trophie}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
trophie"
		TSOCKET="$SOCKET"
	    else 
	        echo "
Something like trophie for Trend detected - but not correctly installed or operational. 
Please read Q-S FAQ if you want it - especially check that trophie daemon 
can read files owned by $QS_USER (i.e. run it as $QS_USER).
".
	    fi
	fi
    fi
    fi
    if [ "`echo $FIND_SCANNERS|egrep ' (vscan|trophie) '`" != "" -a "$ISCAN" = "" ]; then
    if test -x $dir/vscan
    then
	if [ "`$SETUIDGID_QS $dir/vscan -p/etc/iscan/ -za -a -u -nl -v $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
vscan"
	    ISCAN="${ISCAN:-$dir/vscan}"
	fi
    fi    
    fi
    if [ "`echo $FIND_SCANNERS|grep ' antivir '`" != "" -a "$HBEDV" = "" ]; then
    if test -x $dir/antivir
    then
	if [ "`$SETUIDGID_QS $dir/antivir -allfiles -s -tmp. -z -v $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	    HBEDV="${HBEDV:-$dir/antivir}"
	    HBEDV_OPTIONS="-allfiles -s -tmp. -z -v"
	    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
antivir"
	elif [ "`$SETUIDGID_QS $dir/antivir -allfiles -s -tmp. -v $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	    HBEDV="${HBEDV:-$dir/antivir}"
	    HBEDV_OPTIONS="-allfiles -s -tmp. -v"
	    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
antivir"
	fi
    fi
    fi
    if test -x $dir/kavscanner
    then
	if [ "`echo $FIND_SCANNERS|grep ' kavscanner '`" != "" -a "$AVPSCAN" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/kavscanner  $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		AVPSCAN="${AVPSCAN:-$dir/kavscanner}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
kavscanner"
	    fi
	fi
    else 
        if test -x $dir/AvpLinux
	then
	    if [ "`echo $FIND_SCANNERS|grep ' AvpLinux '`" != "" -a "$AVPSCAN" = "" ]; then
		if [ "`$SETUIDGID_QS $dir/AvpLinux -Y $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		    AVPSCAN="${AVPSCAN:-$dir/AvpLinux}"
		    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
AvpLinux"
		fi
	    fi
	fi   
    fi
    if test -x $dir/kavdaemon
    then
       if [ "`echo $FIND_SCANNERS|grep ' kavdaemon '`" != "" -a "$AVPDAEMON" = "" ]; then
	if test -f "sub-avpdaemon.pl"
	then
	    if [ "`$SETUIDGID_QS $dir/kavdaemon $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		AVPSCAN=""
		AVPDAEMON="${AVDAEMON:-$dir/kavdaemon}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
kavdaemon"
	    fi
	fi
       fi
    else 
       if test -x $dir/AvpDaemonClient
       then
	    if [ "`echo $FIND_SCANNERS|grep ' AvpDaemonClient '`" != "" -a "$AVPDAEMON" = "" ]; then
		if test -f "sub-avpdaemon.pl"
		then
		    if [ "`$SETUIDGID_QS $dir/AvpDaemonClient $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
			AVPSCAN=""
			AVPDAEMON="${AVDAEMON:-$dir/AvpDaemonClient}"
			INSTALLED_SCANNERS="$INSTALLED_SCANNERS
AvpDaemonClient"
		    fi
		fi
	    fi
       fi
    fi
    if test -x $dir/fsav
    then
        if [ "`echo $FIND_SCANNERS|grep ' fsav '`" != "" -a "$FSECURE" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/fsav --list --archive --auto --dumb $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		FSECURE="${FSECURE:-$dir/fsav}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
fsav"
	    fi
	fi
    fi    
    if test -x $dir/fpscan
    then
        if [ "`echo $FIND_SCANNERS|egrep ' (fpscan|fpscand) '`" != "" -a "$FPSCAN" = "" ]; then
	    if [ "`setuidgid $QS_USER $dir/fpscan --adware --applications $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		FPSCAN="${FPSCAN:-$dir/fpscan}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
fpscan"
	    fi
	fi
    fi
    if test -x $dir/fpscand
    then
	if [ "`echo $FIND_SCANNERS|grep ' fpscand '`" != "" -a "$FPSCAND" = "" ]; then
	 #Test to see if the daemon is running
	 FPSCAND_DAEMON=`ps -ef  2>/dev/null|egrep fpscand|grep -v grep`
	 if [ "$FPSCAND_DAEMON" == "" ]; then
	  FPSCAND_DAEMON=`ps ax -ww 2>/dev/null|egrep fpscand|grep -v grep`
	 fi
	 if [ "$FPSCAND_DAEMON" != "" ]; then
	  FPSCAND_LISTENADDRESS=`grep ^FPSCAND_LISTENADDRESS /etc/f-prot.conf 2>/dev/null|sed -e 's/FPSCAND_LISTENADDRESS="//' -e 's/"$//'|grep :`
	  FPSCAND_SERVER=`echo $FPSCAND_LISTENADDRESS|cut -d: -f1`
	  FPSCAND_PORT=`echo $FPSCAND_LISTENADDRESS|cut -d: -f2`
	  if [ "$FPSCAND_SERVER" != "" -a "$FPSCAND_PORT" != "" ]; then
		sed -e "s/FPSCAND_SERVER/$FPSCAND_SERVER/g" -e "s/FPSCAND_PORT/$FPSCAND_PORT/g" sub-fpscand.template > sub-fpscand.pl
		cp -f sub-fpscand.pl sub-fpscand-test.pl
		(cat<<EOF
##
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
use POSIX;

sub debug
{
	my(\$msg)=@_;
	print "DBG: \$msg\n";
}
&fpscand_scanner();
print "quarantine_event=\$quarantine_event\n";
EOF
) >> sub-fpscand-test.pl
		OLD_TMPDIR="$TMPDIR"
		TMPDIR="$TMP_DIR"
		export TMPDIR
            	if [ "`perl sub-fpscand-test.pl 2>&1|egrep 'FPSCAND:'`" != "" ]; then
                 FPSCAND="${FPSCAND:-$dir/fpscan}"
                 INSTALLED_SCANNERS="$INSTALLED_SCANNERS
fpscand"
            	fi
	    	rm -f sub-fpscand-test.pl
		TMPDIR="$OLD_TMPDIR"
		export TMPDIR
	 fi
        fi
      fi
    fi
    if test -x $dir/bdc
    then
        if [ "`echo $FIND_SCANNERS|grep ' bitdefender '`" != "" -a "$BITDEFENDER" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/bdc --all --alev=10 --flev=10 --arc --mail $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	       BITDEFENDER="${BITDEFENDER:-$dir/bdc}"
	       INSTALLED_SCANNERS="$INSTALLED_SCANNERS
bdc"
	    fi
	fi
    fi
    if test -x $dir/nod32cli
    then
	if [ "`echo $FIND_SCANNERS|grep ' nod32 '`" != "" ]; then
	    if [ "`$dir/nod32cli --subdir $TMP_DIR 2>&1|egrep -i 'virus='`" != "" ]; then
		 NOD32="${NOD32:-$dir/nod32cli}"
		 UPDNOD="${NOD32:-$dir/nod32upd}"
		 INSTALLED_SCANNERS="$INSTALLED_SCANNERS
nod32"
	    fi
	fi
    fi
    if test -x $dir/esets_cli
    then
	if [ "`echo $FIND_SCANNERS|grep ' esets '`" != "" ]; then
	    if [ "`$dir/esets_cli --subdir $TMP_DIR 2>&1|egrep -i 'virus='`" != "" ]; then
		 ESETS="${ESETS:-$dir/esets_cli}"
		 #UPDESETS="${ESETS:-$dir/esets_cliupd}"
		 INSTALLED_SCANNERS="$INSTALLED_SCANNERS
esets"
	    fi
	fi
    fi
    if test -x $dir/inocucmd
    then
        if [ "`echo $FIND_SCANNERS|grep ' inocucmd '`" != "" -a "$INOCUCMD" = "" ]; then
	    if [ "`$SETUIDGID_QS $dir/inocucmd  -SEC -NEX $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		INOCUCMD="${INOCUCMD:-$dir/inocucmd}"
		INSTALLED_SCANNERS="$INSTALLED_SCANNERS
inocucmd"
	    fi
	fi
    fi  
#    if test -x $dir/ravav
#    then
#	if [ "`echo $FIND_SCANNERS|grep ' ravlin '`" != "" ]; then
#	   if [ "`$SETUIDGID_QS $dir/ravav --mail --archive --heuristics=on --all $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
#	      RAVLIN="${RAVLIN:-$dir/ravav}"
#	      INSTALLED_SCANNERS="$INSTALLED_SCANNERS
#ravlin"
#	   fi
#	fi
#    fi
    if test -x $dir/vexira
    then
	if [ "`echo $FIND_SCANNERS|grep ' vexira '`" != "" -a "$VEXIRA" = "" ]; then
	   if [ "`$SETUIDGID_QS $dir/vexira --allfiles  -s -z -nolnk -noboot -nombr -nodef -r1 $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	      VEXIRA="${VEXIRA:-$dir/vexira}"
	      INSTALLED_SCANNERS="$INSTALLED_SCANNERS
vexira"
	   fi
	fi
    fi
    if test -x $dir/avastlite
    then
	if [ "`echo $FIND_SCANNERS|grep ' avast '`" != "" -a "$AVASTLITE" = "" ]; then
	 if [ "`$SETUIDGID_QS $dir/avastlite $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
		AVASTLITE="${AVASTLITE:-$dir/avastlite}"
		AVASTCMD="$dir/avastcmd"
                INSTALLED_SCANNERS="$INSTALLED_SCANNERS
avast"
	 elif [ "`$SETUIDGID_QS $dir/avastlite $TMP_DIR 2>&1|egrep 'can.t connect to avast. server'`" != "" ]; then
		AVAST_PERMISSION_FAULT="/etc/avastd.conf needs editing: group needs to be qscand"
	 fi
	fi
    fi
    if test -x $dir/freshclam
    then
	export FRESHCLAM="$dir/freshclam"
    fi
    if [ "`echo $FIND_SCANNERS|grep ' clamdscan '`" != "" -a "$CLAMDSCAN" = "" ]; then
    if test -x $dir/clamdscan
    then
	DD="`$SETUIDGID_QS $dir/clamdscan --help 2>&1|grep -i Daemon`"
	if [ "$DD" = "" ]; then
	    echo "
Something like clamdscan for ClamAV detected - but not correctly installed. 
Please read Q-S FAQ if you want it - especially check that it is a recent
release and that the clamd daemon can read files owned by $QS_USER 
(i.e. make sure clamd runs as $QS_USER).
"
	fi
	DD="`$SETUIDGID_QS $dir/clamdscan -v $TMP_DIR 2>&1`|egrep -i 'virus|test'"	
	if [ "$DD" != "" ]; then
	    CLAMDSCAN="${CLAMDSCAN:-$dir/clamdscan}"
	    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
clamdscan"
	else 
	    echo "
Something like clamdscan for ClamAV detected - but not correctly installed. 
Please read Q-S FAQ if you want it - especially check that it is a recent
release and that the clamd daemon can read files owned by $QS_USER 
(i.e. make sure clamd runs as $QS_USER).
"
	fi
    fi
    fi
    if test -x $dir/clamscan
    then
	if [ "`echo $FIND_SCANNERS|grep ' clamscan '`" != "" -a "$CLAMSCAN" = "" ]; then
	   if [ "`$SETUIDGID_QS $dir/clamscan -v $TMP_DIR 2>&1|egrep -i 'virus|test'`" != "" ]; then
	      CLAMSCAN="${CLAMSCAN:-$dir/clamscan}"
	      INSTALLED_SCANNERS="$INSTALLED_SCANNERS
clamscan"
	   fi
	fi
    fi

    if [ "`echo $FIND_SCANNERS|grep altermime`" != "" -a "$ALTERMIME_BINARY" = "" ]; then
       if test -x $dir/altermime
       then
               ALTERMIME_BINARY="${ALTERMIME_BINARY:-$dir/altermime}"
               INSTALLED_SCANNERS="$INSTALLED_SCANNERS
altermime"
       fi
    fi 


    if [ "`echo $FIND_SCANNERS|grep spamassassin`" != "" -a "$SPAMASSASSIN_BINARY" = "" ]; then
       if test -x $dir/spamassassin
       then
	   SPAMASSASSIN_BINARY="${SPAMASSASSIN_BINARY:-$dir/spamassassin}"
       fi
       if [ "$SPAMASSASSIN_BINARY" != "" -a -x "$dir/spamc" -a "$SPAMC_BINARY" = "" ]
       then
	   #Test it out
	if [ "`$SETUIDGID_QS $dir/spamc -h 2>&1|grep 'spamd'`" != "" ] ;then
	      SPAMC_BINARY="${SPAMC_BINARY:-$dir/spamc}"

	      # st: is spamd running with sql per user settings?
	      SA_SQL_AUT=`ps ax -w 2>/dev/null | egrep 'spamd.*( \-q | \-Q | \-\-sql|with\-sql)' |grep -v grep`
	      if [ "$SA_SQL_AUT" = "" ]; then
		  SA_SQL_AUT=`ps -ef 2>/dev/null | egrep 'spamd.*( \-q | \-Q | \-\-sql|with\-sql)' |grep -v grep`
	      fi
	      if [ "$SA_SQL_AUT" = "" ]; then
		  SA_SQL_AUT=`ps aux 2>/dev/null | egrep 'spamd.*( \-q | \-Q | \-\-sql|with\-sql)' |grep -v grep`
	      fi

	      # st: are we using spamd in unix-socket mode?
	      if [ "$SPAMD_SOCKET" != "" ] ;then
		 if [ ! -S "$SPAMD_SOCKET" ] ;then
		    cat<<EOF

  Spamd socket not found in $SPAMD_SOCKET

  Are you really using spamd daemon with the '--socketpath' option?
  Check it or allow the configure script to look for
  it, just omiting the configure option --sa-socket ...

EOF
                    exit
		 fi
		 #SPAMC_BINARY="$SPAMC_BINARY -U $SPAMD_SOCKET"
		 SA_SKT=" -U $SPAMD_SOCKET"
	      elif [ "$SA_HN" = "" ]; then

		 #Test to see if spamc is calling Unix sockets instead of TCP
		 SPAMD_SOCKET=`ps -ef 2>/dev/null|egrep 'spamd.*socketpath'|grep -v grep|sed -e 's/^.*socketpath=//'|awk '{print $1}'`
		 if [ "$SPAMD_SOCKET" = "" ]; then
		     SPAMD_SOCKET=`ps ax -ww 2>/dev/null|egrep 'spamd.*socketpath'|grep -v grep|sed -e 's/^.*socketpath=//'|awk '{print $1}'`
		 fi

		 # st: in my RH7.3 servers this works...
		 if [ "$SPAMD_SOCKET" = "" ]; then
		     SPAMD_SOCKET=`ps ax -w 2>/dev/null|egrep 'spamd.*socketpath'|grep -v grep|sed -e 's/^.*socketpath=//'|awk '{print $1}'`
		 fi
		 if [ "$SPAMD_SOCKET" != "" ]; then
		    if [ -S "$SPAMD_SOCKET" ]; then
		        #SPAMC_BINARY="$SPAMC_BINARY -U $SPAMD_SOCKET"
		        SA_SKT=" -U $SPAMD_SOCKET"
		    else
		        cat<<EOF

  Oops... Spamd socket not found in $SPAMD_SOCKET

  It seems that you're running spamd in unix-socket mode, but the
  configure script couldn't find the socket properly.
  Try to set it manually using the configure option --sa-socket ...

EOF
		        exit
		    fi
		 fi
	      else
		    if [ "`$SETUIDGID_QS $SPAMC_BINARY $SA_HN -K`" = "" ]; then
		        echo "######################################################"
		        echo "   It seems that your 'spamd' runs in a remote host '$SA_HN'"
		        echo "   but this configure script couldn't connect to it"
		        echo "   Please fix it and try again."
		        echo "######################################################"
		        exit 1
		    fi
	      fi
	      DD="`$SETUIDGID_QS $SPAMC_BINARY $SA_HN $SA_SKT < ./contrib/spamc-nice.eml`"
              if [ "`echo $DD|grep '^From '`" != "" ]; then
                  cat<<EOF

SpamAssassin's spamd daemon is incorrectly installed. You need to run it as:

spamd -F 0 ....

Please try again.

EOF
                 exit
              fi
	      DD="`$SETUIDGID_QS $SPAMC_BINARY $SA_HN $SA_SKT < ./contrib/spamc-nice.eml`"
	      if [ "$?" != "0" -o "`echo $DD|grep 'X-Spam-Status: No'`" = "" ]; then
		 echo "
Something like spamc for SpamAssassin detected - but not correctly installed
(didn't include a \"X-Spam-Status\" line in output).
Please read Q-S FAQ if you want it - especially check that spamd daemon
is running. Ignoring...
"
		 SPAMC_BINARY=''
	      else
		 DD="`$SETUIDGID_QS $SPAMC_BINARY $SA_HN $SA_SKT < ./contrib/spamc-nasty.eml`"
		 if [ "$?" != "0" -o "`echo $DD|grep 'X-Spam-Status: Yes'`" = "" ]; then
		    echo "
Something like spamc for SpamAssassin detected - but not correctly installed
(didn't include a \"X-Spam-Status: Yes\" line in output) - ignoring...
"
		    SPAMC_BINARY=''
		 else
		DD="`$SETUIDGID_QS $SPAMC_BINARY $SA_HN $SA_SKT -c < ./contrib/spamc-nasty.eml`"
		    if [ "`echo $DD|tail -1|grep /`" != "" ]; then
		       SPAMASSASSIN_VERSION="fast_spamassassin"
		       SA_THRESHOLD=`echo $DD|tail -1|sed -e 's/\(.*\)\/\(.*\)/\2/'`
		    fi
		 fi
	      fi
	      if [ "$SPAMC_BINARY" != "" ]; then
		 if [ "`echo $FIND_SCANNERS|grep ' fast_spamassassin'`" != "" ]; then
		    if [ "$SPAMASSASSIN_VERSION" != "fast_spamassassin" ]; then
		       cat<<EOF
Fatal: You have asked for the "fast" SpamAssassin support, however
your system is NOT correctly configured for it.

Either upgrade and try again, or reconfigure for the potentially slower "verbose"
SpamAssassin support.

EOF
		       exit 1
		    fi
		    #SPAMC_OPTIONS="$SA_HN -c "
		    SA_FAST="1"
		    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
fast_spamassassin"
		    #See if they want fast_spamassassin to alter the 
		    #Subject: line too...
		    SPAMC_SUBJECT="`echo $FIND_SCANNERS|grep ' fast_spamassassin='|sed -e 's/^.*fast_spamassassin=//g' -e 's/ .*$//g'`"
		    if [ "$SPAMC_SUBJECT" = "" ]; then SPAMC_SUBJECT=$SA_SUBJECT ; fi
		 else
		    SPAMASSASSIN_VERSION="verbose_spamassassin"
		    # st: I don't think that '-f' is still supported...
		    #SPAMC_OPTIONS="$SA_HN -f "
		    SA_FAST="0"
		    SPAMC_OPTIONS="$SA_HN $SA_SKT "
		    INSTALLED_SCANNERS="$INSTALLED_SCANNERS
verbose_spamassassin"
		 fi
	      else
		 SPAMC_BINARY=''
	      fi
	   fi
       fi
    fi
    if test -x $dir/find
    then
	if [ "`find --help 2>&1|grep gnu`" != "" ]; then
	    GNU_FIND="${GNU_FIND:-$dir/find}"
	else
	    FIND="${FIND:-$dir/find}"
	fi
    fi
    if test -x $dir/egrep
    then
        GREP="${GREP:-$dir/grep}"
    fi
    if test -x $dir/uudecode
    then
        UUDECODE_BINARY="${UUDECODE_BINARY:-$dir/uudecode}"
    fi
  # st
  fi
  SEARCHED="$SEARCHED:$dir"
done

#Prefer GNU find to other OS's if available
if [ "$GNU_FIND" != "" ]; then
    FIND="$GNU_FIND"
fi

if [ "$FIND_SILENT_VIRUSES" = "$SILENT_VIRUSES" ]; then
    SILENT_VIRUSES="auto"
fi
if [ "$UNAME" ] ; then FQDN="$UNAME" ; fi
if [ "$HOST" ] ; then FQDN="$HOST" ; fi

MAILDOMAIN=${MAILDOMAIN:-$FQDN}
LOCAL_DOMAINS_ARRAY=${LOCAL_DOMAINS_ARRAY:-$MAILDOMAIN}

# st: I wish a shorter CMDLINE
CMDLINE="$0 --qs-user $QS_USER"

if [ "$QS_USER" != "$QS_GROUP" ] ; then CMDLINE="$CMDLINE --qs-group $QS_GROUP" ; fi
if [ "$SPOOLDIR" != "/var/spool/qscan" ] ; then CMDLINE="$CMDLINE --spooldir $SPOOLDIR" ; fi
if [ "$QMAILDIR" != "/var/qmail" ] ; then CMDLINE="$CMDLINE --qmaildir $QMAILDIR" ; fi
if [ "$BINDIR" != "$QMAILDIR/bin" ] ; then CMDLINE="$CMDLINE --bindir $BINDIR" ; fi
if [ "$QMAILQUEUE_BIN" != "$BINDIR/qmail-queue" ] ; then CMDLINE="$CMDLINE --qmail-queue-binary $QMAILQUEUE_BIN" ; fi

CMDLINE="$CMDLINE --admin $USERNAME --domain $MAILDOMAIN --admin-description \"$ADMIN_DESCRIPTION\" --notify $NOTIFY_ADDRESSES --local-domains $LOCAL_DOMAINS_ARRAY --silent-viruses $SILENT_VIRUSES --virus-to-delete $VIRUS_DELETE --skip-text-msgs $SKIP_TEXT_MSGS --lang $QSLANG --debug $DEBUG_LEVEL --add-dscr-hdrs $DESCRIPTIVE_HEADERS --dscr-hdrs-text \"$DESCR_HEADERS_TEXT\" --normalize $NORMALIZE_MSG --archive $ARCHIVEIT --settings-per-domain $SETTINGS_P_D --max-scan-size $MAX_SCAN_SIZE --unzip $FORCE_UNZIP --max-zip-size $MAX_ZIP_SIZE --max-unpacked-files $MAX_UNPACKED_FILES --redundant $REDUNDANT --log-details $LOG_DETAILS --log-crypto $LOG_CRYPTO --fix-mime $FIX_MIME --ignore-eol-check $DISABLE_EOL_CHECK"

#echo "configure called as: $CMDLINE"
echo -n "."

INSTALLED_SCANNERS="`echo \"$INSTALLED_SCANNERS\"|sort|uniq`"
INSTALLED_SCANNERS=`echo $INSTALLED_SCANNERS`
INSTALLED_SCANNERS=" $INSTALLED_SCANNERS "

#First off, check that the QMAILQUEUE patch is in place:


if [ "$STRINGS" != "" -a "$QMAILSMTPD" != "" -a "$MANUAL_INSTALL" = "0" ]; then
    DD=`$STRINGS -a $QMAILSMTPD|grep QMAILQUEUE`
    if [ "$DD" = "" ]; then
    cat<<EOF

               **************************

Cannot find evidence of QMAILQUEUE patch in $QMAILSMTPD!

This package REQUIRES that Qmail patch in order to operate.

Please read the README.html file again and download and install the patch
before continuing...

               **************************

EOF
    exit 1

    fi
fi


#Now check for evidence of the custom-error patch. Latest uses FD6
if [ "$SA_REJECT" = "1" ]; then
 Q_REJECT_EXITCODE="31"
 if [ "$Q_REJECT_EXITCODE" = "31" -a "$QMAILINJECT_BIN" != "" -a "$MANUAL_INSTALL" = "0" ]; then
	(cat<<EOF
#!/usr/bin/perl
open(FD6,">&6");
print FD6 "Dtesting custom error patch";
close FD6;
exit 82;
EOF
) > $TMP_DIR/qs-custom.pl
    chmod 755 $TMP_DIR/qs-custom.pl
    QMAILQUEUE="$TMP_DIR/qs-custom.pl"
    export QMAILQUEUE
    DD=`echo xxx|$QMAILINJECT_BIN 2>&1|grep 'fatal: testing custom error patch'`
    if [ "$DD" = "" ]; then
	Q_REJECT_EXITCODE="31"
    else
	Q_REJECT_EXITCODE="82"
	Q_REJECT_FD="6"
    fi
 fi
 if [ "$Q_REJECT_EXITCODE" = "31" -a "$QMAILINJECT_BIN" != "" -a "$MANUAL_INSTALL" = "0" ]; then
    #Nope, try with the FD4 option
    (cat<<EOF
#!/usr/bin/perl
open(FD4,">&4");
print FD4 "Dtesting custom error patch";
close FD4;
exit 82;
EOF
) > $TMP_DIR/qs-custom.pl
    chmod 755 $TMP_DIR/qs-custom.pl
    QMAILQUEUE="$TMP_DIR/qs-custom.pl"
    export QMAILQUEUE
    DD=`echo xxx|$QMAILINJECT_BIN 2>&1|grep 'fatal: testing custom error patch'`
    if [ "$DD" = "" ]; then
	Q_REJECT_EXITCODE="31"
    else
	Q_REJECT_EXITCODE="82"
	Q_REJECT_FD="4"
    fi
 fi
 #Try again with older custom-error patch that uses stderr
 if [ "$Q_REJECT_EXITCODE" = "31" -a "$QMAILINJECT_BIN" != "" -a "$MANUAL_INSTALL" = "0" ]; then
    (cat<<EOF
#!/usr/bin/perl
print STDERR "Dtesting custom error patch";
exit 82;
EOF
) > $TMP_DIR/qs-custom.pl
    chmod 755 $TMP_DIR/qs-custom.pl
    QMAILQUEUE="$TMP_DIR/qs-custom.pl"
    export QMAILQUEUE
    DD=`echo xxx|$QMAILINJECT_BIN 2>&1|grep 'fatal: testing custom error patch'`
    if [ "$DD" = "" ]; then
	Q_REJECT_EXITCODE="31"
    else
	Q_REJECT_EXITCODE="82"
	Q_REJECT_FD="2"
    fi
 fi
fi

unset QMAILQUEUE

if [ "$PERL5" = "" ]; then
    cat<<EOF

               **************************

Cannot find perl 5 on your system!

This package is a perl script - it won't get far without perl5 on your system...

               **************************

EOF
    exit 1
fi

DD=`$PERL5 -e 'use Time::HiRes;' 2>&1`
if [ "$?" != "0" ]; then
    cat<<EOF

               **************************

 perl doesn't have Time::HiRes module - cannot continue.

Get it from CPAN:

http://search.cpan.org/search?mode=module&query=time%3A%3Ahires

               **************************

Error reported was:

---
$DD
---
EOF
    exit 1
fi

DD=`$PERL5 -e 'use DB_File;' 2>&1`
if [ "$?" != "0" ]; then
    cat<<EOF

               **************************

 perl doesn't have DB_File module - cannot continue.

Get it from CPAN:

http://search.cpan.org/search?module=DB_File

               **************************


Error reported was:

---
$DD
---
EOF
    exit 1
fi

if [ "$MIME_UNPACKER" = "reformime" ]; then
#Check version of maildrop to ensure it's not the buggy version

DD="`$MAILDROP_BINARY -v 2>&1|grep '^maildrop'|grep ' 1\.0'`"
if [ "$DD" != "" ]; then
    cat<<EOF

               **************************

 You have a known bad version of maildrop (1.0). It is buggy and doesn't
work!

Please upgrade to a later release:

http://download.sourceforge.net/courier/

               **************************

EOF
    exit 1
fi
fi

#Find out if their uudecoder is supported
if [ "$UUDECODE_BINARY" != "" ]; then
if [ "`$UUDECODE_BINARY -h 2>&1|$GREP '\-o'`" != "" ]; then
    UUDECODE_PIPE="-o -"
elif [ "`$UUDECODE_BINARY -h  2>&1|$GREP '\-p'`" != "" ]; then
    UUDECODE_PIPE="-p"
elif [ "`$UUDECODE_BINARY -h  2>&1|$GREP 'cip'`" != "" ]; then 
    UUDECODE_PIPE="-p"
elif [ "`$UUDECODE_BINARY --help 2>&1|$GREP '\-o'`" != "" ]; then
    UUDECODE_PIPE="-o -"
elif [ "`$UUDECODE_BINARY --help  2>&1|$GREP '\-p'`" != "" ]; then
    UUDECODE_PIPE="-p"
fi


#What was this here for? DELETE
#if [ "$UUDECODE_PIPE" = "" ]; then
#    UUDECODE_PIPE="-xxx-junk--here"
#fi

#Now check if uudecode is useful

testfile="qmail-scan-$$.tst"
echo 'begin 664 $testfile
%=&5S=`H`
`
end
'> test-uudecode.uue
DD=`$UUDECODE_BINARY $UUDECODE_PIPE test-uudecode.uue > test-uudecode.tst`
if [ "$?" = "0" ] ; then
    if [ -f test-uudecode.tst -a ! -f $testfile ]; then
	#uudecode is good!
	echo "

$UUDECODE_BINARY works as expected on system...

"
    else
	UUDECODE_BINARY=''
	echo "

broken uudecoder on your system - cannot use uudecode component

"
    fi
else
	UUDECODE_BINARY=''
	echo "

broken uudecoder on your system - cannot use uudecode component

"
fi

rm -f test-uudecode.tst $testfile test-uudecode.uue

#Finish UUDECODE tests
fi

#Carry on...

if [ "`echo $LOCAL_DOMAINS_ARRAY|grep $MAILDOMAIN`" = "" ]; then
    LOCAL_DOMAINS_ARRAY="$MAILDOMAIN,$LOCAL_DOMAINS_ARRAY"
fi


LOCAL_DOMAINS_ARRAY="`echo $LOCAL_DOMAINS_ARRAY|sed -e 's/\"//g'  -e 's/ //g'`"

if [ "$LOCAL_DOMAINS_ARRAY" ]; then
     LDA=""
     for dom in `echo $LOCAL_DOMAINS_ARRAY|sed 's/,/ /g'`
     do
	LDA="$LDA,'$dom'"
     done
     LOCAL_DOMAINS_ARRAY="`echo $LDA|sed 's/^,//g'`"
fi

if [ "$MIME_UNPACKER" = "reformime" ]; then
if [ "$UNMIME_BINARY" = "" ]
then
    cat<<EOF

               **************************

 Cannot find reformime on your system!

This package relies on reformime (part of the maildrop package)
 to unpack MIME mail messages, please install it from
http://www.flounder.net/~mrsam/maildrop/

               **************************

EOF
    exit 1
fi
fi
if [ "$UNZIP_BINARY" = "" ]; then
    cat<<EOF

               **************************

Cannot find unzip on your system!

As this is probably a virus scanning package, there's not much point
in trying to detect PC-type viruses when you can't even unpack the
primary file type they arrive in...


               **************************

EOF
    exit 1
fi

if [ "$TNEF_BINARY" != "" ]; then
    cat<<EOF
    
Found tnef on your system! That means we'll be able to decode stupid
M$ attachments :-)

EOF
fi

echo "
==============================================================
The following binaries and scanners were found on your system:
==============================================================

"
if [ "$UNMIME_BINARY" != "" ]
then 
    echo "mimeunpacker=$UNMIME_BINARY"
    MIMEUNPACKER="$UNMIME_BINARY "
fi
if [ "$UUDECODE_BINARY" != "" ] 
then
    echo "uudecode=$UUDECODE_BINARY"
fi
if [ "$FORCE_UNZIP" = "1" -a "$UNZIP_BINARY" != "" ]
then
    echo "unzip=$UNZIP_BINARY"
    echo "max-zip-size=$MAX_ZIP_SIZE"
    echo "max-unpacked-files"="$MAX_UNPACKED_FILES"
fi
if [ "$TNEF_BINARY" != "" ] 
then
    echo "tnef=$TNEF_BINARY"
fi

echo ""
echo "Content/Virus Scanners installed on your System"
echo ""
if [ "$MAX_SCAN_SIZE" != "" ]; then
    echo "max-scan-size=$MAX_SCAN_SIZE"
fi

if [ "$CLAMDSCAN" != "" ]; then
    if [ "$FRESHCLAM" == "" ]; then
        echo "FATAL ERROR: found $CLAMDSCAN, but cannot find freshclam."
        exit 1
    fi
    echo "clamdscan=$CLAMDSCAN (which means clamscan won't be used as clamdscan is better)";
    SCANNER_ARRAY="$SCANNER_ARRAY,\"clamdscan_scanner\""
fi

if [ "$CLAMSCAN" != "" -a "$CLAMDSCAN" = "" ]; then
    if [ "$FRESHCLAM" == "" ]; then
	echo "FATAL ERROR: found $CLAMSCAN, but cannot find freshclam."
	exit 1
    fi
    echo "clamscan=$CLAMSCAN";
    SCANNER_ARRAY="$SCANNER_ARRAY,\"clamscan_scanner\""
fi

if [ "$AVGD" != "" ]; then
    echo "avgd=$AVGD"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"avgd_scanner\""
fi


if [ "$AVASTLITE" != "" ]; then
	echo "avast=$AVASTLITE"
	SCANNER_ARRAY="$SCANNER_ARRAY,\"avast_scanner\""
fi
if [ "$AVAST_PERMISSION_FAULT" != "" ]; then
	echo "avast=FAILED: $AVAST_PERMISSION_FAULT"
fi

if [ "$ISCAN" != "" -a "$TROPHIE" = "" ]; then 
    
    echo "vscan=$ISCAN" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"iscan_scanner\""
fi
if [ "$CSAV" != "" ]; then 
    echo "csav=$CSAV" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"csav_scanner\""
fi
if [ "$TROPHIE" != "" ]; then 
    echo "trophie=$TROPHIE (which means vscan won't be used as trophie is better)" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"trophie_scanner\""
fi
if [ "$UVSCAN" != "" ]; then 
    echo "uvscan=$UVSCAN" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"uvscan_scanner\""
fi
if [ "$NOD32" != "" ]; then
    echo "nod32=$NOD32"
    # st: thanks to Apro Krisztian
    echo "(NOTE: you should set the following values in /etc/nod32/nod32.cfg"
    echo "write_to_emails = 0"
    echo "action_on_infected = \"accept\""
    echo "quarantine = no   )"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"nod32_scanner\""
fi
if [ "$ESETS" != "" ]; then
    echo "esets=$ESETS"
    # st: thanks to Apro Krisztian
    echo "(NOTE: you should set the following values in /etc/esets/esets.cfg"
    echo "action_av_infected = \"reject\" or action_av_infected = \"discard\""
    echo "av_quarantine_enabled = no   )"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"esets_scanner\""
fi
if [ "$SAVSCAN" != "" -a "$SOPHIE" = "" ]; then
    echo "savscan=$SAVSCAN"
    unset SWEEP
    SCANNER_ARRAY="$SCANNER_ARRAY,\"savscan_scanner\""
fi
if [ "$SWEEP" != "" -a "$SOPHIE" = "" ]; then 
    echo "sweep=$SWEEP" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"sweep_scanner\""
fi
if [ "$SOPHIE" != "" ]; then 
    echo "sophie=$SOPHIE (which means savscan won't be used as sophie is better)" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"sophie_scanner\""
fi

if [ "$HBEDV" != "" ]; then 
    DD=''
    if [ "`echo $HBEDV_OPTIONS|grep '\-z'`" = "" ]; then
     DD="(NOTE: demo mode: no archive unpacking!!!)"
    fi
    echo "hbedv_antivir=$HBEDV $DD" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"hbedv_scanner\""
fi

if [ "$AVPSCAN" != "" ]; then 
    echo "avp_antivir=$AVPSCAN" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"avp_scanner\""
fi

if [ "$AVPDAEMON" != "" ]; then 
    echo "avpdaemon_antivir=$AVPDAEMON" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"avpdaemon_scanner\""
fi

if [ "$FPSCAN" != "" -a "$FPSCAND" == "" ]; then
    echo "fpscan=$FPSCAN"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"fpscan_scanner\""
fi

if [ "$FPSCAND" != "" ]; then
    echo "fpscand=$FPSCAND (which means fpscan is disabled as fpscand is better)"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"fpscand_scanner\""
fi

if [ "$FSECURE" != "" ]; then 
    echo "fsecure=$FSECURE" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"fsecure_scanner\""
fi

if [ "$INOCUCMD" != "" ]; then 
    echo "inoculate=$INOCUCMD" 
    SCANNER_ARRAY="$SCANNER_ARRAY,\"inocucmd_scanner\""
fi

if [ "$RAVLIN" != "" ]; then
    echo "ravlin=$RAVLIN"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"ravlin_scanner\""
fi

if [ "$VEXIRA" != "" ]; then
    echo "vexira=$VEXIRA"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"vexira_scanner\""
fi

if [ "$ALTERMIME_BINARY" != "" ]; then
    echo "altermime=$ALTERMIME_BINARY"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"altermime\""
    if [ "$ALTERMIME_DISC" != "" ]; then
       echo "altermime-disclaimer=$ALTERMIME_DISC"
    fi
    if [ "$ALTERMIME_DISC_HTML" != "" ]; then
       echo "altermime-disclaimer-html=$ALTERMIME_DISC_HTML"
    fi
fi


if [ "$BITDEFENDER" != "" ]; then
    echo "bitdefender=$BITDEFENDER"
    SCANNER_ARRAY="$SCANNER_ARRAY,\"bitdefender_scanner\""
fi

if [ "$SPAMC_BINARY" != "" ]; then
    if [ "$SPAMASSASSIN_VERSION" = "fast_spamassassin" ]; then
	echo "fast_spamassassin=$SPAMC_BINARY"
	SCANNER_ARRAY="$SCANNER_ARRAY,\"fast_spamassassin\""
    else 
	echo "verbose_spamassassin=$SPAMC_BINARY"
	SCANNER_ARRAY="$SCANNER_ARRAY,\"verbose_spamassassin\""
    fi
fi

USERNAME=${USERNAME:-$LOGNAME}

SCANNER_ARRAY=`echo $SCANNER_ARRAY|sed 's/^,//g'`

# If spamassassin is not found set SA_QUARANTINE and SA_DELETE back to 0
if [ "`echo $SCANNER_ARRAY|grep -v 'spamassassin'`" != "" ]; then
    SA_DELTA="0"
    SPAMC_SUBJECT=""
    SA_FORWARD_IN=""
    SA_FORWARD=""
    SA_QUARANTINE="0"
    SA_DELETE="0"
    SA_REJECT="0"
    SA_ALT="0"
    SA_DEBUG="0"
    SA_HDR_REPORT="0"
    SA_SQL="0"
fi

echo ""
echo "Qmail-Scanner details."
echo ""

if [ "`echo $LOG_DETAILS|egrep -i '^yes|^1|^y|^on|^true|^syslog'`" != "" ]; then
    if [ "`echo $LOG_DETAILS|egrep -i '^1|^yes|^y|^on|^true'`" != "" ]; then
        LOG_DETAILS="`echo $LOG_DETAILS | grep ',' | sed -e 's/^.*,//'`"
        if [ "$LOG_DETAILS" = "" ]; then
	    LOG_DETAILS="mailstats.csv"
	fi
    else
	LOG_DETAILS="syslog"
        DD=`$PERL5 -e 'use Sys::Syslog;' 2>&1`
        if [ "$?" != "0" ]; then
	  cat<<EOF

               **************************

 perl doesn't have Sys::Syslog module - therefore cannot configure with the
 "--log-details yes" option.

Your version of perl is too old to support this feature. Either upgrade or
configure again with "--log-details no".

               **************************

EOF
	  exit 1
        fi
     fi
else
   LOG_DETAILS=0
fi

if [ "$LOG_DETAILS" = "0" ]; then
    LOG_DETAILS="0"
    LOG_MSG_SUB="
sub log_msg() {};
"
fi

if [ "`echo $DEBUG_LEVEL|egrep -i '^1$|^y|^on|^true'`" != "" ]; then
    DEBUG_LEVEL="1"
elif [ "`echo $DEBUG_LEVEL|egrep -i '^[1-9]+$'`" != "" ]; then
    DEBUG_LEVEL=$DEBUG_LEVEL
else
    DEBUG_LEVEL="0"
fi
echo "debug=$DEBUG_LEVEL"

if [ "$LOG_DETAILS" != "" ]; then
    echo "log-details=$LOG_DETAILS"
fi
if [ "$LOG_CRYPTO" != "" ]; then
    echo "log-crypto=$LOG_CRYPTO"
fi
if [ "$FIX_MIME" != "" ]; then
    echo "fix-mime=$FIX_MIME"
fi
if [ "$DISABLE_EOL_CHECK" != "" ]; then
    echo "ignore-eol-check=$DISABLE_EOL_CHECK"
fi
if [ "$NOTIFY_ADDRESSES" != "" ]; then
    echo "notify=$NOTIFY_ADDRESSES"
fi
if [ "$REDUNDANT" != "" ]; then
    echo "redundant-scanning=$REDUNDANT" 
fi

if [ "$ARCHIVEIT" != "0" ]; then
    if [ "$ARCHIVEIT" = "1" ]; then 
     ASTRING="everything"
    else 
     ASTRING="($ARCHIVEIT) only"
    fi
    echo "archiving $ASTRING into $SPOOLDIR/$ARCHIVEDIR/"
fi

echo "virus-admin=$ADMIN_DESCRIPTION <$USERNAME@$MAILDOMAIN>"
echo "local-domains=$LOCAL_DOMAINS_ARRAY"
echo "silent-viruses=$FIND_SILENT_VIRUSES_ARRAY"
echo "scanners=`echo $SCANNER_ARRAY|sed 's/_scanner//g'`"

if [ "$SPAMC_BINARY" != "" ]; then
    echo
    if [ "$SPAM_MAILDIR" != "spam" ] ; then
       echo "spamdir =$SPOOLDIR/quarantine/$SPAM_MAILDIR"
       CMDLINE="$CMDLINE --spamdir $SPAM_MAILDIR"
    fi

    if [ "`echo $SA_TEMPFAIL|egrep -i '^[n|0]'`" != "" ]; then
       SA_TEMPFAIL=0
       CMDLINE="$CMDLINE --sa-tempfail $SA_TEMPFAIL"
    else
       SA_TEMPFAIL=1
    fi
    echo "sa-tempfail=$SA_TEMPFAIL"
    if [ "`echo $SA_FT|egrep -i '^[n|0]'`" != "" ]; then
       SA_FT=0
       CMDLINE="$CMDLINE --sa-faulttolerant $SA_FT"
    else
       SA_FT=1
    fi
    echo "sa-faulttolerant=$SA_FT"
    if [ $SA_MAXSIZE -gt 0 -a  "$SA_MAXSIZE" != "256000" ]; then
       CMDLINE="$CMDLINE --sa-maxsize $SA_MAXSIZE"
    else
       SA_MAXSIZE="256000"
    fi
    echo "sa-maxsize=$SA_MAXSIZE"
    if [ "$SA_TIMEOUT" != "30" ]; then
       CMDLINE="$CMDLINE --sa-timeout $SA_TIMEOUT"
    fi
    echo "timeout=$SA_TIMEOUT"
fi

echo
echo "----------------------------------------------"
echo "st: configuration options for  $QS_VERSION"
echo "----------------------------------------------"

if [ "$SETTINGS_P_D" != "" ]; then
    echo "settings-per-domain=$SETTINGS_P_D"
fi
if [ "$VIRUS_DELETE" != "0" ]; then
    echo "virus-to-delete=$VIRUS_DELETE"
else
    VIRUS_TO_DELETE=""
fi

if [ "$DESCRIPTIVE_HEADERS" != "" ]; then
    echo "dscr-hdrs-text='$DESCR_HEADERS_TEXT'" 
fi
if [ "$SPAMC_BINARY" != "" ]; then
    echo
    if [ "$SPAMD_SOCKET" != "" ] ; then
       echo "sa-socket =$SPAMD_SOCKET"
       CMDLINE="$CMDLINE --sa-socket $SPAMD_SOCKET"
    fi
    if [ "$SPAMD_REMOTE" != "" ] ; then
       echo "sa-remote =$SPAMD_REMOTE"
       CMDLINE="$CMDLINE --sa-remote $SPAMD_REMOTE"
    fi
    if [ "$SA_SQL" != "0" -o  "$SA_SQL_AUT" != "" ] ; then
       if [ "$SA_SQL_AUT" = "" ]; then
          echo
          echo "########################################################################"
          echo "   sa-sql is set to '1' but spamd doesn't seem to be running with"
          echo "   sql per user settings... Everything will work, but it is better"
          echo "   to disable this option for performance if it is really not active."
          echo "########################################################################"
          echo
       fi
       SA_SQL="1"
       echo "sa-sql =$SA_SQL     (Spamassassin per user settings active)"
       CMDLINE="$CMDLINE --sa-sql $SA_SQL"
    fi
    if [ "$SA_FORWARD_IN" != "" ] ;then
    # st: Add a '\' to the sa_forward mail address
       if [ "`echo $SA_FORWARD_IN | grep @ `" = "" ]; then
          SA_FORWARD_IN="$SA_FORWARD_IN@$MAILDOMAIN"
       fi
       SA_FORWARD=`echo "$SA_FORWARD_IN" | awk -F @ '{print $1 "\\\@" $2}'`
       CMDLINE="$CMDLINE --sa-forward $SA_FORWARD"
       echo "sa-forward=\"$SA_FORWARD_IN\"  (Is it a valid address?)"
       if [ "$SA_FWD_VERBOSE" != "0" ] ; then
          echo "sa-fwd-verbose=$SA_FWD_VERBOSE  (X-Spam headers will be added in the forwarded mail)"
       else
          echo "sa-fwd-verbose=$SA_FWD_VERBOSE  (X-Spam headers won't be added in the forwarded mail)"
       fi
       CMDLINE="$CMDLINE --sa-fwd-verbose $SA_FWD_VERBOSE"
    fi
    if [ "$SPAMASSASSIN_VERSION" != "verbose_spamassassin" -a "$SPAMC_SUBJECT" != "" ] ;then
       echo "sa-subject=\"$SPAMC_SUBJECT\""
       CMDLINE="$CMDLINE --sa-subject \"$SPAMC_SUBJECT\""
    fi
    echo
    echo "sa-delta  =$SA_DELTA"
    echo "sa-alt    =$SA_ALT"
    echo "sa-debug  =$SA_DEBUG    (only valid if sa-alt is enabled)"
    echo "sa-report =$SA_HDR_REPORT    (only valid if sa-alt is enabled)"
    echo
    echo "Spamassasin Required_Hits=$SA_THRESHOLD"
    if [ "$SA_QUARANTINE" != "0" ]; then
       SA_CONTROL="$SA_QUARANTINE $SA_DELETE"
       if [ "$SA_DELETE" != "0" -a "`echo $SA_CONTROL | awk '{if ($1 > $2) print 1}'`" ] ; then
          echo
          echo "########################################################################"
          echo "WARNING: sa-quarantine ($SA_QUARANTINE) is higher than"
          echo "         sa-delete ($SA_DELETE), resetting sa-delete and sa-reject to 0."
          echo "         You can fix this later editing qmail-scanner-queue.pl and"
          echo "         setting the appropriated values. No mail will be"
          echo "         deleted or rejected"
          echo "########################################################################"
          echo
          SA_DELETE="0"
          SA_REJECT="0"
       fi
       SA_QTINE=`echo "$SA_QUARANTINE $SA_THRESHOLD" | awk '{print $1+$2}'`
       echo "sa-quarantine=$SA_QUARANTINE  	(messages over $SA_QTINE hits will be quarantined)"
    else
       echo "sa-quarantine=0  	(no mail will be quarantined)"
    fi
    if [ "$SA_DELETE" != "0" ]; then
      SA_DLT=`echo "$SA_DELETE $SA_THRESHOLD" | awk '{print $1+$2}'`
      if [ "$SA_REJECT" != "0" ]; then
         echo "sa-delete    =$SA_DELETE     	(messages over $SA_DLT hits will be rejected)"
      else
         echo "sa-delete    =$SA_DELETE     	(messages over $SA_DLT hits will be deleted)"
      fi
    else
      echo "sa-delete    =0    	(no mail will be deleted/rejected)"
    fi
    echo "sa-reject    =$SA_REJECT"
    echo "-------------------------------------------------------------------------"
    CMDLINE="$CMDLINE --sa-delta $SA_DELTA --sa-alt $SA_ALT --sa-debug $SA_DEBUG --sa-report $SA_HDR_REPORT --sa-quarantine $SA_QUARANTINE --sa-delete $SA_DELETE --sa-reject $SA_REJECT"
else
    # st: if spamc it has not been detected there is no point in setting
    # this parametres, some people could be confused...
    SA_FAST=""
    SA_SQL="0"
    SA_DELTA="0"
    SA_SUBJECT=""
    SA_FORWARD_IN=""
    SA_FORWARD=""
    SA_FWD_VERBOSE="0"
    SA_QUARANTINE="0"
    SA_DELETE="0"
    SA_REJECT="0"
    SA_ALT="0"
    SA_DEBUG="0"
    SA_HDR_REPORT="0"
    SPAMD_SOCKET=""
    SA_MAXSIZE="256000"
    SA_TIMEOUT="30"
    SA_FT="0";
fi

CMDLINE="$CMDLINE --scanners \"$SCANNERS\""

SCANNER_ARRAY="`echo $SCANNER_ARRAY|sed -e 's/fast_spamassassin/spamassassin/g' -e 's/verbose_spamassassin/spamassassin/g'`"

if [ "$SCANNER_ARRAY" != "" ]; then
   SCANNER_ARRAY="$SCANNER_ARRAY,"
fi

cat<<EOF

If that looks correct, I will now generate qmail-scanner-queue.pl
for your system...
EOF

if [ "$MANUAL_INSTALL" = "1" ]; then
    CMDLINE="$CMDLINE --no-QQ-check $MANUAL_INSTALL"
fi
if [ "$INSTALLIT" = "1" ]; then
    CMDLINE="$CMDLINE --install $INSTALLIT"
fi

if [ "$DONOTCONFIRM" != "1" ]; then
 cat<<EOF
Continue? ([Y]/N) 
EOF
 read ans 
 if [ "`echo $ans|grep -i n`" != "" ]; then
    exit 1
 fi
fi

if [ "`echo $DESCRIPTIVE_HEADERS|egrep -i '1|yes|^y|on|true'`" != "" ]; then
    DESCRIPTIVE_HEADERS="1"
elif [ "`echo $DESCRIPTIVE_HEADERS|egrep -i 'all'`" != "" ]; then
    DESCRIPTIVE_HEADERS="2"
else
    DESCRIPTIVE_HEADERS="0"
fi


#Gather info about OS this is been run on.

HOST_OS=`uname -s`
HOST_RELEASE=`uname -r`
HOST_HARDWARE=`uname -m`

#Gather up locale info for translations

> .locale_vars
for i in ./locale/$QSLANG/*
do
    name=`basename $i`
    expr LOCALE_$name="\"`cat $i`\"" >> .locale_vars
    echo "export LOCALE_$name" >> .locale_vars
done

#For those systems that don't have suidperl installed, assume
#their "magic" systems still support that feature by
#redefining SUIDPERL to be PERL5...

#if [ "$SUIDPERL" = "" ]; then
    SUIDPERL="$PERL5"
#fi

if [ "$SKIP_SETUID_TEST" = "" ]; then
 if [ "$SETUIDGID" != "" ]; then
  echo "Testing suid nature of $SUIDPERL..."
  (cat<<EOF
#!$SUIDPERL
\$uid=\$>;
print "Checking for setuid nature of perl install\n";
print "\nWhat follows should be the UID of the $QS_USER acount...\n\n";
print "uid=\$uid\n";
print "\n";
EOF
)> .perl-test.pl
    chmod 0755 .perl-test.pl
    DD=`$SETUIDGID_QS $PERL5 ./.perl-test.pl 2>&1`
    QS_UID=`echo "$DD"|grep ^uid=|sed 's/^uid=//g'|egrep '^[0-9]+$'`
    #Now setuid it and see if the output changes
  chown $QS_USER:$QS_GROUP .perl-test.pl
  chmod 6755 .perl-test.pl
  #This will be run as a different account than $QS_USER - we'll use qmailq
  #as that must exist on every Qmail system
  DD=`$SETUIDGID_QQ ./.perl-test.pl 2>&1`
  QS_SUID=`echo "$DD"|grep ^uid=|sed 's/^uid=//g'|egrep '^[0-9]+$'`
  if [ "$QS_SUID" = "" -o "$QS_SUID" != "$QS_UID" ]; then
    echo "Whoa - broken perl install found."
    echo "Cannot even run a simple script setuid"
    echo ""
    echo "You will either have to correct this"
    echo "or use the C-wrapper within the ./contrib dir"
    echo ""
    echo "Error was:"
    echo "$DD"
    echo ""
    if [ -f /etc/redhat-release ]; then
     echo "Redhat hosts need to have perl-suidperl installed to get setuid support"
    fi
    echo "See FAQ for further details"
    echo ""
    printf "Hit RETURN to continue, Ctr-C to exit and fix: "
    read ans
  else
    echo "Looks OK..."
    #rm -f .perl-test.pl
  fi
 fi
fi

#Unconfigure a few options if ripmime being used

if [ "`echo $UNMIME_BINARY|grep ripmime`" != "" ]; then
 unset UUDECODE_BINARY 
 unset TNEF_BINARY
fi

. ./.locale_vars

#Set maxsize in spamassassin subroutine
#sed -e "s/SA_MAXSIZE/$SA_MAXSIZE/g" sub-spamassassin.template > sub-spamassassin.pl
cat sub-spamassassin.template > sub-spamassassin.pl

perl -p -e "s?UNMIME_BINARY?$UNMIME_BINARY?g;
s?PERLRELEASE_DETAILS?$PERLRELEASE_DETAILS?g;
s?HOST_OS?$HOST_OS?g;
s?HOST_RELEASE?$HOST_RELEASE?g;
s?HOST_HARDWARE?$HOST_HARDWARE?g;
s?DEBUG_LEVEL?$DEBUG_LEVEL?g;
s?DESCRIPTIVE_HEADERS?$DESCRIPTIVE_HEADERS?g;
s?CMDLINE?$CMDLINE?g;
s?PERL5?$PERL5?g;
s?SUIDPERL?$SUIDPERL?g;
s?QS_USER?$QS_USER?g;
s?QMAILINJECT_BIN?$QMAILINJECT_BIN?g;
s?QMAILQUEUE_BIN?$QMAILQUEUE_BIN?g;
s?RM_BINARY?$RM_BINARY?g;
s?GREP_BINARY?$GREP_BINARY?g;
s?UNZIP_BINARY?$UNZIP_BINARY?g;
s?MAX_ZIP_SIZE?$MAX_ZIP_SIZE?g;
s?MAX_UNPACKED_FILES?$MAX_UNPACKED_FILES?g;
s?MAX_MSG_SIZE?$MAX_SCAN_SIZE?g;
s?UNZIP_OPTIONS?$UNZIP_OPTIONS?g;
s?FORCE_UNZIP?$FORCE_UNZIP?g;
s?TNEF_BINARY?$TNEF_BINARY?g;
s?MIMEUNPACKER?$MIMEUNPACKER?g;
s?SILENT_VIRUSES_ARRAY?$FIND_SILENT_VIRUSES_ARRAY?g;
s?AVGD?$AVGD?g;
s?AVGD_PORT?$AVGD_PORT?g;
s?UVSCAN?$UVSCAN?g;
s?CSAV?$CSAV?g;
s?SWEEP?$SWEEP?g;
s?SAVSCAN?$SAVSCAN?g;
s?SOPHIE?$SOPHIE?g;
s?SSOCKET?$SSOCKET?g;
s?TROPHIE?$TROPHIE?g;
s?TSOCKET?$TSOCKET?g;
s?ISCAN?$ISCAN?g;
s?HBEDV_OPTIONS?$HBEDV_OPTIONS?g;
s?HBEDV?$HBEDV?g;
s?AVPSCAN?$AVPSCAN?g;
s?AVPDAEMON?$AVPDAEMON?g;
s?FPSCAND?$FPSCAND?g;
s?FPSCAN?$FPSCAN?g;
s?FSECURE?$FSECURE?g;
s?INOCUCMD?$INOCUCMD?g;
s?RAVLIN?$RAVLIN?g;
s?VEXIRA?$VEXIRA?g;
s?AVASTLITE?$AVASTLITE?g;
s?AVASTCMD?$AVASTCMD?g;
s?NOD32?$NOD32?g;
s?UPDNOD?$UPDNOD?g;
s?ESETS?$ESETS?g;
s?BITDEFENDER?$BITDEFENDER?g;
s?CLAMSCAN?$CLAMSCAN?g;
s?CLAMDSCAN?$CLAMDSCAN?g;
s?FRESHCLAM?$FRESHCLAM?g;
s?Q_REJECT_EXITCODE?$Q_REJECT_EXITCODE?g;
s?Q_REJECT_FD?$Q_REJECT_FD?g;
s?SA_TEMPFAIL?$SA_TEMPFAIL?g;
s?SA_MAXSIZE?$SA_MAXSIZE?g;
s?SA_TIMEOUT?$SA_TIMEOUT?g;
s?SA_FAULT_TOLERANT?$SA_FT?g;
s?SPAMASSASSIN_BINARY?$SPAMASSASSIN_BINARY?g;
s?SPAMC_BINARY?$SPAMC_BINARY?g;
s?SA_HN?$SA_HN?g;
s?SPAMC_SUBJECT?$SPAMC_SUBJECT?g;
s?ALTERMIME_BINARY?$ALTERMIME_BINARY?g;
s?ALTERMIME_DISC?$ALTERMIME_DISC?g;
s?ALTERMIME_DISC_HTML?$ALTERMIME_DSC_HTML?g;
s?ALTERMIME_REGEX?$ALTERMIME_REGEX?g;
s?USERNAME?$USERNAME?g;
s?SKIP_TEXT_MSGS?$SKIP_TEXT_MSGS?g;
s?FQDN?$FQDN?g;
s?MAILDOMAIN?$MAILDOMAIN?g;
s?LOCAL_DOMAINS_ARRAY?$LOCAL_DOMAINS_ARRAY?g;
s?ADMIN_DESCRIPTION?$ADMIN_DESCRIPTION?g;
s?NOTIFY_ADDRESSES?$NOTIFY_ADDRESSES?g;
s?FIND?$FIND?g;
s?GREP?$GREP?g;
s?UUDECODE_BINARY?$UUDECODE_BINARY?g;
s?UUDECODE_PIPE?$UUDECODE_PIPE?g;
s?QS_SPOOLDIR?$SPOOLDIR?g;
s?QS_LOGDIR?$LOGDIR?g;
s?QS_ETCDIR?$ETCDIR?g;
s?VIRUS_MAILDIR?$VIRUS_MAILDIR?g;
s?SPAM_MAILDIR?$SPAM_MAILDIR?g;
s?POLICY_MAILDIR?$POLICY_MAILDIR?g;
s?ARCHIVEIT?$ARCHIVEIT?g;
s?ARCHIVEDIR?$ARCHIVEDIR?g;
s?REDUNDANT?$REDUNDANT?g;
s?LOG_DETAILS?$LOG_DETAILS?g;
s?LOG_CRYPTO?$LOG_CRYPTO?g;
s?FIX_MIME?$FIX_MIME?g;
s?DISABLE_EOL_CHECK?$DISABLE_EOL_CHECK?g;
s?LOCALE_sender_subject?$LOCALE_sender_subject?g;
s?LOCALE_recips_subject?$LOCALE_recips_subject?g;
s?LOCALE_attention?$LOCALE_attention?g;
s?LOCALE_recips_automated_mail_note?$LOCALE_recips_automated_mail_note?g;
s?LOCALE_recips_content?$LOCALE_recips_content?g;
s?LOCALE_recips_explanation?$LOCALE_recips_explanation?g;
s?LOCALE_recips_msg_description?$LOCALE_recips_msg_description?g;
s?LOCALE_recips_quarantine?$LOCALE_recips_quarantine?g;
s?LOCALE_recips_not_automated_mail_note?$LOCALE_recips_not_automated_mail_note?g;
s?LOCALE_sender_virus_content?$LOCALE_sender_virus_content?g;
s?LOCALE_sender_quarantine?$LOCALE_sender_quarantine?g;
s?LOCALE_sender_automated_mail_note?$LOCALE_sender_automated_mail_note?g;
s?LOCALE_sender_explanation?$LOCALE_sender_explanation?g;
s?LOCALE_sender_msg_description?$LOCALE_sender_msg_description?g;
s?LOCALE_sender_other_content?$LOCALE_sender_other_content?g;
s?LOCALE_destring_problem?$LOCALE_destring_problem?g;
s?LOCALE_destring_disallowed_attachment_type?$LOCALE_destring_disallowed_attachment_type?g;
s?LOCALE_destring_virus?$LOCALE_destring_virus?g;
s?LOCALE_destring_policy_violation?$LOCALE_destring_policy_violation?g;
s?SCANNER_ARRAY?$SCANNER_ARRAY?g;
s?JH_VERSION?$JH_VERSION?g;
s?ST_VERSION?$ST_VERSION?g;
s?DESCR_HEADERS_TEXT?$DESCR_HEADERS_TEXT?g;
s?SETTINGS_P_D?$SETTINGS_P_D?g;
s?VIRUS_TO_DELETE?$VIRUS_TO_DELETE?g;
s?SA_FAST?$SA_FAST?g;
s?SA_SQL?$SA_SQL?g;
s?SA_DELTA?$SA_DELTA?g;
s?SA_FORWARD?$SA_FORWARD?g;
s?SA_FWD_VERBOSE?$SA_FWD_VERBOSE?g;
s?SA_QUARANTINE?$SA_QUARANTINE?g;
s?SA_DELETE?$SA_DELETE?g;
s?SA_REJECT?$SA_REJECT?g;
s?SA_ALT?$SA_ALT?g;
s?SA_DEBUG?$SA_DEBUG?g;
s?SA_HDR_REPORT?$SA_HDR_REPORT?g;
s?SPAMD_SOCKET?$SPAMD_SOCKET?g;" qmail-scanner-queue.template > qmail-scanner-queue.pl-1
perl -pe 's/%%/\$/g' qmail-scanner-queue.pl-1 > qmail-scanner-queue.pl
rm -f qmail-scanner-queue.pl-1

cat sub-attachments.pl >> qmail-scanner-queue.pl

if [ "$LOG_MSG_SUB" != "" ]; then
    echo "$LOG_MSG_SUB" >> qmail-scanner-queue.pl
else
    cat sub-log_msg.pl >> qmail-scanner-queue.pl
fi

if [ "$NORMALIZE_MSG" = "no" ]; then
    (cat<<EOF
sub normalize_string {
  my (\$type,\$string)=@_;
  return \$string;
} ;
EOF
) >> qmail-scanner-queue.pl
else
    cat sub-normalize.pl >> qmail-scanner-queue.pl
fi


(cat<<EOF

###############################
##
##  END of standard subroutines
##  Virus-scanner specific subroutines automatically added below by setup.sh
##
###############################

EOF
)  >> qmail-scanner-queue.pl

# st: Add some subroutines
cat sub-patch-st.pl >> qmail-scanner-queue.pl

if [ "`echo $SCANNER_ARRAY| grep -i spamassassin`" = "" ]; then
   echo "
# st: If we do not have spamassassin, at least we need this empty routine
sub check_sa_score {};

" >> qmail-scanner-queue.pl
fi

for scanner in `echo $SCANNER_ARRAY|sed -e 's/\"//g' -e 's/,/ /g' -e's/_scanner//g'` 
do 
    if [ "$scanner" = "avgd" ]; then
	sed "s?AVGD_PORT?$AVGD_PORT?" sub-avgd.template > sub-avgd.pl
    fi

    if [ "$scanner" = "sophie" ]; then
	sed "s?SSOCKET?$SSOCKET?" sub-sophie.template > sub-sophie.pl
    fi
    if [ "$scanner" = "trophie" ]; then
	sed "s?TSOCKET?$TSOCKET?" sub-trophie.template > sub-trophie.pl
    fi
    if [ "$scanner" = "sweep" ]; then
	#Special case for Sweep
	if [ "$SAV_IDE" != "" -o "$SAV_IDE_CONF" = "1" ]; then
	    sed "s?SOPHOS_SAV_IDE?$SAV_IDE?" sub-sweep.template > sub-sweep.pl
	else
	    echo "You have Sophos installed, but  SAV_IDE is not defined!"
	    echo ""
	    echo "Bad install of Sophos, exiting...."
	    exit 1
	fi
    fi
    if test -f "sub-$scanner.pl"
    then
	cat sub-$scanner.pl >> qmail-scanner-queue.pl
    else
	echo ""
	echo "** scanner subroutine for $scanner not found **"
	echo "** disabled as not officially supported. ** "
	echo ""
    fi
done

(cat<<EOF
#########################
## END of scanner definitions
##
#########################
EOF
) >> qmail-scanner-queue.pl

chmod 755 qmail-scanner-queue.pl

if [ "$INSTALLIT" != "0" ]; then
    if [ "$DONOTCONFIRM" != "1" ]; then
     echo  "Hit RETURN to create initial directory structure under $SPOOLDIR,"
     printf "and install qmail-scanner-queue.pl under $BINDIR: "
     read ans 
    fi
    mv -f $BINDIR/qmail-scanner-queue.pl $BINDIR/qmail-scanner-queue.pl.old 2>/dev/null
    cp -f qmail-scanner-queue.pl $BINDIR/qmail-scanner-queue.pl
    chown $QS_USER:$QS_GROUP $BINDIR/qmail-scanner-queue.pl
    chmod 6755 $BINDIR/qmail-scanner-queue.pl
    if [ -f "$BINDIR/antivirus-qmail-queue.pl" -a ! -L "$BINDIR/antivirus-qmail-queue.pl" ]; then
	mv -f $BINDIR/antivirus-qmail-queue.pl $BINDIR/antivirus-qmail-queue.pl.old
	ln -s $BINDIR/qmail-scanner-queue.pl $BINDIR/antivirus-qmail-queue.pl
	cat<<EOF

 ** REMEMBER to alter your Qmail startup scripts to call 
 $BINDIR/qmail-scanner-queue.pl instead of 
 $BINDIR/antivirus-qmail-queue.pl  **

EOF
    fi
    mkdir $SPOOLDIR 2>/dev/null
    # st: some people, maybe because they don't use suidperl have problems with
    # the tmp directory, so better create it now
    mkdir $SPOOLDIR/tmp 2>/dev/null
    mkdir $ETCDIR 2>/dev/null
    mkdir $LOGDIR 2>/dev/null
    #mkdir $DOCDIR 2>/dev/null
    rm -f $SPOOLDIR/viruses $SPOOLDIR/quarantine 2>/dev/null
    mkdir $SPOOLDIR/quarantine 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$VIRUS_MAILDIR 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$VIRUS_MAILDIR/tmp 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$VIRUS_MAILDIR/cur 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$VIRUS_MAILDIR/new 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$SPAM_MAILDIR 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$SPAM_MAILDIR/tmp 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$SPAM_MAILDIR/cur 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$SPAM_MAILDIR/new 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$POLICY_MAILDIR 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$POLICY_MAILDIR/tmp 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$POLICY_MAILDIR/cur 2>/dev/null
    mkdir $SPOOLDIR/quarantine/$POLICY_MAILDIR/new 2>/dev/null
    mkdir $SPOOLDIR/working 2>/dev/null
    mkdir $SPOOLDIR/working/new 2>/dev/null
    mkdir $SPOOLDIR/working/cur 2>/dev/null
    mkdir $SPOOLDIR/working/tmp 2>/dev/null
    touch $LOGDIR/quarantine.log 
    #if [ "$ARCHIVEIT"  != "0" ]; then
	mkdir $SPOOLDIR/$ARCHIVEDIR 2>/dev/null
	mkdir $SPOOLDIR/$ARCHIVEDIR/cur 2>/dev/null
	mkdir $SPOOLDIR/$ARCHIVEDIR/tmp 2>/dev/null
	mkdir $SPOOLDIR/$ARCHIVEDIR/new 2>/dev/null
    #fi

    if [ "$LOG_DETAILS" != "syslog" -a "$LOG_DETAILS" != "0" ]; then
	if [ ! -f "$LOGDIR/$LOG_DETAILS" ]; then
	    echo "#Virus_Found	Process_Time	From	Recipients	Subject	Message-ID	Msg_Size	Date	Attachment_Filenames" > $LOGDIR/$LOG_DETAILS
	    chown $QS_USER:$QS_GROUP $LOGDIR/$LOG_DETAILS
	fi
    fi

    if [ ! -f "$ETCDIR/quarantine-events.txt" ] ; then 
       cp quarantine-events.txt $ETCDIR/
    fi

    if [ ! -f "$ETCDIR/settings_per_domain.txt" ] ; then 
       cp settings_per_domain.txt $ETCDIR/
    fi

    if [ ! -f "$LOGDIR/log-report.sh" ] ; then 
       cp log-report.sh $LOGDIR/
       #chown $QS_USER:$QS_GROUP $LOGDIR/log-report.sh
    else
       if [ "`stat -t log-report.sh | cut -d ' ' -f2`" != "`stat -t $LOGDIR/log-report.sh | cut -d ' ' -f2`" ] ; then
          mv -f $LOGDIR/log-report.sh $LOGDIR/log-report.sh.old 2>/dev/null
          cp log-report.sh $LOGDIR/
          #chown $QS_USER:$QS_GROUP $LOGDIR/log-report.sh
       fi
    fi

    find $SPOOLDIR/ -type d -exec chown -R $QS_USER:$QS_GROUP {} \;
    chmod 750 $SPOOLDIR/tmp
    if [ "$SPOOLDIR" != "$ETCDIR" ]; then
	chown -R $QS_USER:$QS_GROUP $ETCDIR
	chmod 750 $ETCDIR
    fi
    if [ "$SPOOLDIR" != "$LOGDIR" ]; then
	chown -R $QS_USER:$QS_USER $LOGDIR/
	chmod 750 $LOGDIR
    fi
    $BINDIR/qmail-scanner-queue.pl -g
    if [ "$?" != "0" ]; then
	cat<<EOF


	    ******* FATAL ERROR *******


Whoa! Newly installed version of qmail-scanner-queue.pl exits with 
an error when run. 

Replacing with original version (if any) and exiting...

See ./qmail-scanner-queue.pl (current dir) for the errors refered to by 
perl above...

	    ****************************


EOF
        if [ -f "$BINDIR/qmail-scanner-queue.pl.old" ]; then
	   mv -f $BINDIR/qmail-scanner-queue.pl.old $BINDIR/qmail-scanner-queue.pl
	fi
	exit 1
    fi
    if [ -x "$BINDIR/qmail-scanner-queue.pl" ]; then $BINDIR/qmail-scanner-queue.pl -z ; fi
    cat<<EOF

Finished installation of initial directory structure for Qmail-Scanner
under $SPOOLDIR and qmail-scanner-queue.pl under $BINDIR.

Finished. Please read README(.html) and then go over the script
($BINDIR/qmail-scanner-queue.pl) to check paths/etc. 

"$BINDIR/qmail-scanner-queue.pl -r" should return some well-known virus
definitions to show that the internal perlscanner component is working.

If you're upgrading, remember that your previous quarantine-attachments.txt file
has not been changed, maybe it's a good idea to have a look at the file
coming with this distribution.

That's it!

EOF

else

cat<<EOF 


Finished. Please read README(.html) and then go over the script to
check paths/etc, and then install as you see fit.

Remember to copy quarantine-events.txt to $SPOOLDIR and then
run "qmail-scanner-queue.pl -g" to generate DB version.

EOF

fi


if [ "$SCANNER_ARRAY" = "" ]; then
    cat<<EOF

########################################################################
##
#

NOTE: No content/virus scanner was found on your system - so only the 
internal perlscaner will be available for you to use.

Hope that's what you expected :-)

#
##
########################################################################

EOF

fi

if [ -x "$BINDIR/qmail-scanner-queue.pl" -a "$INSTALLIT" != "0" ]; then
    $BINDIR/qmail-scanner-queue.pl -v > SYSDEF
    (cat<<EOF

Configuration information: 

$CMDLINE

EOF
) >> SYSDEF
fi

rm -rf $TMP_DIR

if [ "$SETTINGS_P_D" = "1" ]; then
    cat<<EOF

You have enabled 'settings-per-domain' remember to edit the file
"$SPOOLDIR/settings_per_domain.txt" and build the database with the command
$BINDIR/qmail-scanner-queue.pl -p, other-wise qmail-scanner will fall
to the 'defaults site settings' installed.
EOF

fi

if [ -f "$SPOOLDIR/scanners_per_domain.txt" ] ; then 
    cat<<EOF
###################### WARNING #######################################
There is a previous 'scanners_per_domain.txt' file, you can just rename
it to 'settings_per_domain.txt', rebuild the database and everything
will work, but maybe you want add some sa_settings to the file...

EOF
fi

if [ "$INSTALLIT" != "0" ]; then
   cat<<EOF


              ****** FINAL TEST ******

Please log into an unpriviledged account and run 
$BINDIR/qmail-scanner-queue.pl -g

If you see the error "Can't do setuid", or "Permission denied", then  
refer to the FAQ.

(e.g.  "setuidgid qmaild $BINDIR/qmail-scanner-queue.pl -g")


That's it! To report success:

   % (echo 'First M. Last'; cat SYSDEF)|mail jhaar-s4vstats@crom.trimble.co.nz
Replace First M. Last with your name.

EOF

else

echo "
###

qmail-scanner-queue.pl has been generated in this directory and looks OK.

It is up to you installing it by hand or re-run this script adding the
option  '--install 1'

###
"

fi
