[EXIM] BETA-Announce: Interactive configuration-script

Top Page
Delete this message
Reply to this message
Author: Hans-Georg v. Zezschwitz
Date:  
To: exim-users
New-Topics: [EXIM] RBL problems
Subject: [EXIM] BETA-Announce: Interactive configuration-script
Hello!

First of all: This is script is NOT intended to build the
main configuration file!
This script is intended to ease the process of building
the Local/Makefile.


The problem:
------------

Pretty often GNU-software just requires these commands for
building the binaries:

     ./configure
     make
     make install


With Exim, you first have to copy the src/EDITME file and
edit it afterwards.

What I wrote, is a script mostly addressed to:

- the novice, who gets the exim sources by download and
tries to install it on his system

- the novice or advanced user, who has installed a binary
version of exim and wants to upgrade by downloading the
sources.

- generally all users, who don't need exotic compile-time
configurations.


What it does
------------

Simple commands like chown or gzip are located and
configured.

You can interactively choose a UID / GID for the Exim
process.

The script tries to find out, where certain files are
located, e.g. it looks for an existing directory /opt/exim,
/var/spool/exim or /var/run to install the binaries,
spool-space and PID-files there, it asks, if no assumptions
can be made, it lists e.g. all path configurations and
gives you a chance to change the assumptions.

It tries to find the libraries and include-headers
eximon needs and asks you, if eximon should be build.


What platform does it run on?
-----------------------------
It is tested by now on Linux, Irix 4, OSF/1.0 and Philip
tested it on Solaris. It does NOT require any GNU tools,
it mostly uses the standard bourne shell (/bin/sh) and
standard awk.

However, as Philip already found some bugs, I'm very interested
in what other people find out and suggest.

If this script should be one or the suggested method how
to compile exim, the script will REALLY need a lot of
testing.

Therefore, I'd really like to ask many folks to give this
script a try on their local machine.

E.g., if you have a configured Exim-src-version, just run
this script and have a look how Local/Makefile is
changed (your old Makefile will be saved as Local/Makefile.old).

I'd be glad to get any success-story or bug-report, suggestions
or comments.

Greetings,


Georg


How to use it
-------------

- Save the attachment, e.g. as ~/Configure-Local

- Change the directory to the Exim source tree, e.g.:

cd /usr/local/src/exim-3.02

- Move the script to this location:

mv ~/Configure-Local scripts/

- Make it executable:

chmod +x scripts/Configure-Local

- Run it.

scripts/Configure-Local

- If you want, start compilation:

make


Affected files:

The script won't touch any file apart from:

- Creating a Local-subdirectory, if not existing

- Generating a Local/Makefile right at the end
(A previous version is saved as Local/Makefile.old)

- Copying eximon/EDITME to Local/eximon.conf, if this
file is not existing

-- 
Georg v. Zezschwitz                      HGVZ1-RIPE

#! /bin/sh
#
# This script tries to make the initial configuration for compiling
# Exim a bit easier. It tries to find out some details about
# your paths and the location of some programs, and asks for
# all the important stuff it can't find.
#
#  written by Georg v. Zezschwitz, gvz@???
#
# 
# GvZ 980502  This script is intended to help some poor starters
#             with Exim. It creates a Local/Makefile for them
#             asks them some questions for the default configure
#             file and tries to make them happy from the scratch
#
# GvZ 990529  I finally risked to send this script to Philip.
#             Some improvement to let it work with Solaris systems,
#             configurable EXIM_UID and some minor stuff added.
#
#
# readln reads a line into $ans.
#
#       readln prompt default oldval
#
readln () {
        if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
                echo "$1"
                ans=$2
        else
                echo $ECHOARG "$1$NONL"
                [ -z "$3" ] && echo $ECHOARG "(NEW) $NONL"
                IFS='@' read ans </dev/tty || exit 1
                [ -z "$ans" ] && ans=$2
        fi
}


#
# bool processes a boolean argument
#
#       bool question define
#
bool () {
    eval 'old=$'$2
        def=${old:-'n'}
        case "$def" in
         "y" | "m") defprompt="Y/n/?"
              def="y"
              ;;
         "n") defprompt="N/y/?"
              ;;
        esac
        while :; do
          readln "$1 ($2) [$defprompt] " "$def" "$old"
          case "$ans" in
            [yY] | [yY]es ) ans="y";
                eval "$2=\"y\"";
                            break;;
            [nN] | [nN]o )  ans="n";
                eval "$2=\"n\"";
                            break;;
            * )             help "$2"
                            ;;
          esac
        done
}


#
# findbin searches for a binary in some public and wellknown paths.
# 
# findbin prg define ask
#
findbin () {
    eval 'PRESET=$'$2
    if [ ! -z "$PRESET" ] && [ -x "$PRESET" ] ; then
        echo "$2 stays $PRESET";
    else
    CHECKPATHS="$PATH:/usr/local/bin:/usr/bin:/bin:/opt/bin"
    found="";
#    for P in `echo "$CHECKPATHS" | tr ':' ' '` ; do
    eval 'for i in '`echo "$CHECKPATHS" | tr ':' ' '`' ; do
        if [ -d $i ] ; then
            if [ -x $i/$1 ] ; then
                eval "$2=\"$i/$1\"";
                found="$i/$1";
                break;
            fi
        fi
    done'
    if [ $found ] ; then
                echo "$2 set to $found";
    else 
                if [ "$3" = "y" ] ; then
                    echo "The program $1 required by some utilities was not found.";
                    echo "If you'd like to make full use of Exim, please specify the absolute path";
                    readln "to $1 ($2): " "$1" "$1"
                    eval "$2=\"$ans\"";
                    echo "Setting $2 to $ans.";
                else
                    echo "WARNING: Did not find $1"
                fi
    fi
    fi
}



#######################################################################
# Main configuration starts here
#######################################################################

######### How do we get echo to suppress the trailing \n ? ############
RESULT=`echo -n`
if [ -z "$RESULT" ] ; then
ECHOARG="-n"
NONL=""
else
ECHOARG=""
NONL="\c"
fi

echo
echo " Exim Interactive Setup"
echo "------------------------"
echo

######### First let us see if we have a chance to do our work #########

CPWD=`pwd`
if [ ! -d src ] ; then
echo "ERROR: The script should be run from the directory where"
echo "the exim sources are installed (e.g. /usr/local/src/exim )."
echo "However, the src-subdirectory was not found."
echo "This is required: Quitting"
exit 1;
fi
if [ ! -r src/EDITME ] ; then
echo "ERROR: This script will generate the configuration-file based"
echo "on the text and comments in src/EDITME. However, this file"
echo "is not readable or does not exist. Please make sure this "
echo "script has read-access to this file. Quitting"
exit 1;
fi
if [ -d Local ] && [ ! -w Local ] ; then
echo "ERROR: The directory \"Local\" does exist, however, it is not"
echo "writable by this script. Please modify the permissions of Local,"
echo "login the owner of this directory or change the owner of that"
echo "directory. Quitting"
exit 1;
fi
if [ ! -d Local ] && [ ! -w . ] ; then
echo "ERROR: The configuration for building Exim will be created in a"
echo "sub-directory named \"Local\". However, this script is not allowed"
echo "to create this directory. Please modify the permissons of this"
echo "directory, login the owner of this directory or change the owner"
echo "of that directoy. Quitting"
exit 1;
fi

# The defaults we will use are either from src/EDITME or, if
# existing, from the current Local/Makefile
# Decide what to use...
if [ -d ./Local ] && [ -r Local/Makefile ] ; then
  echo "The configuration directory \"$PWD/Local\" exists."
  UPDATE="y";
  Q="Do you want to update the current settings?";
  bool "$Q" "UPDATE";
  case "$UPDATE" in 
    n) echo "Exiting..."; exit;
       ;;
  esac;
  if [ -r Local/Makefile ] ; then
    echo "Using settings from Local/Makefile as default."
    . Local/Makefile
  else 
    if [ -r src/EDITME ] ; then
      echo "Using defaults from src/EDITME."
      . src/EDITME
    fi
  fi
else
  mkdir -p Local
  echo "Creating configuration directory \"$PWD/Local\"."
  if [ -r src/EDITME ] ; then
    echo "Using defaults from src/EDITME."
    . src/EDITME
  fi
fi
echo


######### Most of the utilities need some commands, find them ##########

findbin chown CHOWN_COMMAND y
findbin chgrp CHGRP_COMMAND y
findbin mv MV_COMMAND y
findbin rm RM_COMMAND y
findbin perl PERL_COMMAND y
#
######### Decide, if and how gzip/compress should be used #############
#
findbin gzip COMPRESS_COMMAND n
if [ ! -x $COMPRESS_COMMAND ] ; then
  findbin compress COMPRESS_COMMAND n
  if [ ! -x $COMPRESS_COMMAND ] ; then
    echo "Did not find neither gzip nor compress.\n";
    while [ ! -x "$COMPRESS_COMMAND" ] ; do 
      echo "Please enter the absolute path to a program for compressing";
      readln "your logfiles: " "" ""
      if [ ! -x "$ans" ] ; then
        echo "There is no program \"$ans\" on your system.";
      else 
        echo "O.k., setting COMPRESS_COMMAND to $ans";
        COMPRESS_COMMAND=$ans;
      fi
    done
    echo "Please enter the suffix compressed files get (e.g. \"Z\"):";
    readln "" "Z" "Z";
    COMPRESS_SUFFIX=$ans;
    echo "O.k., setting COMPRESS_SUFFIX to $ans";
  else
    echo "Using compress instead of gzip for logfile-compression.";
    COMPRESS_SUFFIX="Z";
  fi
else
  COMPRESS_SUFFIX="gz";
fi
echo
#
######### What UID and GID should Exim use ? ##########################
#
  echo "It is recommended to let Exim do its work using its own user"
  echo "and group ID. Some parts of Exims work (like listening on"
  echo "port 25) have to be done as root, but Exim will give up its"
  echo "priviledge when possible."
  echo "If you leave this setting blank, Exim will run most time"
  echo "as user root."


  if [ -r /etc/passwd ] ; then
    echo "If you specify a username here, make sure it is existing in"
    echo "the /etc/passwd file, otherwise specify a numeric UID or"
    echo "do not specify anything at all."
  else 
    echo "Please specify a *numeric* UID or leave this field blank."
  fi
  Q="EXIM_UID [$EXIM_UID]: ";
  readln "$Q" "$EXIM_UID" "$EXIM_UID"
  EXIM_UID=$ans
  if [ -r /etc/passwd ] && [ ! -z "$EXIM_UID" ] ; then
    NUID=`( echo "<<=:$EXIM_UID" ; cat /etc/passwd ) | awk -F':' '
        /^<<=/ { uid=$2 }
        { if ($3==uid || $1==uid) { print $3 } }'`
    if [ ! -z "$NUID" ] && [ -z "$EXIM_GID" ] ; then
      NGID=`( echo "<<=:$EXIM_UID" ; cat /etc/passwd ) | awk -F':' '
    /^<<=/ { uid=$2 }
    { if ($3==uid || $1==uid) { print $4 } }'` ;
    fi
    if [ ! -z "$NUID" ] ; then
      EXIM_UID=$NUID;
      if [ -z "$EXIM_GID" ] ; then
        EXIM_GID=$NGID ;
      fi 
    else 
      echo "*WARING* The UID you specified does not exist! Setting"
      echo "EXIM_UID to root by leaving it blank!"
      EXIM_UID="";
    fi
  fi
  if [ ! -z "$EXIM_UID" ] ; then
    echo
    echo "Please enter the group ID now!"
    if [ -r /etc/group ] ; then
      echo "If you specify a groupname here, make sure its existing in"
      echo "the /etc/group file, otherwise specify a numeric GID or"
      echo "do not specify anything at all." 
    else 
      echo "Please specify a *numeric* GID or leave this field blank."
    fi
    Q="EXIM_GID [$EXIM_GID]: ";
    readln "$Q" "$EXIM_GID" "$EXIM_GID"
    EXIM_GID=$ans
    if [ -r /etc/group ] && [ ! -z "$EXIM_GID" ] ; then
      NGID=`( echo "<<=:$EXIM_GID" ; cat /etc/group ) | awk -F':' '
          /^<<=/ { gid=$2 }
          { if ($3==gid || $1==gid) { print $3 } }'`
      if [ -z "$NGID" ] ; then
        echo "*WARING* The GID you specified does not exist! Setting"
        echo "EXIM_GID to root by leaving it blank!"
        EXIM_GID=""
      else
        EXIM_GID=$NGID 
      fi
    fi
  fi
  echo
#
######### Where should the binaries be installed ? ####################
#
if [ ! -x "$BIN_DIRECTORY/exim" ] ; then
# First look for a file named "configure" in some famous directories...
  CPATHS="/usr/exim/bin /usr/local/lib/exim/bin /usr/lib/exim/bin"
  CPATHS="$CPATHS /usr/local/bin /usr/bin /opt/bin /bin /opt/exim"
  FOUND="";
  eval 'for i in '$CPATHS' ; do
    if [ -x "$i/exim" ] ; then
      FOUND="$i";
      BIN_DIRECTORY=$FOUND;
      echo "Found exim in $i.";
      break;
    fi
  done'
else
  FOUND=$BIN_DIRECTORY
fi
if [ -z "$FOUND" ] ; then
  echo "Where should the binaries reside? (BIN_DIRECTORY)";
  Q="[$BIN_DIRECTORY]: ";
  readln "$Q" "$BIN_DIRECTORY" "$BIN_DIRECTORY"
  BIN_DIRECTORY=$ans
fi
echo "Binaries will be installed in \"$BIN_DIRECTORY\"."
echo
#
######### Decide, where to place the configuration file ###############
#
FOUND="";
if [ ! -r "$CONFIGURE_FILE" ] ; then
# First look for a file named "configure" in some famous directories...
  CPATHS="/usr/exim /usr/local/lib/exim /etc/mail /etc/exim /usr/lib/exim"
  CPATHS="$CPATHS /var/lib/exim /var/lib/mail /usr/lib/mail"
  eval 'for i in '$CPATHS' ; do
    if [ -z "$FOUND" ] && [ -r "$i/configure" ] ; then
      FOUND="$i/configure";
      CONFIGURE_FILE=$FOUND;
      echo "Found configure in $i.";
    fi
  done'
# If nothing found, look for some famous directories...
  if [ -z "$FOUND" ] ; then
    for i in $CPATHS ; do
      if [ -z "$FOUND" ] && [ -d $i ] ; then
        FOUND="$i/configure";
        CONFIGURE_FILE=$FOUND;
        echo "Found directory named \"$i\".";
      fi
    done
  fi
fi
# Ask, if nothing found
if [ -z "$FOUND" ] ; then
  echo "Where should the configuration file be placed? Exim takes its main";
  echo "configuration from here.";
  readln "(CONFIGURE_FILE) [$CONFIGURE_FILE]:" "$CONFIGURE_FILE"  \
    "$CONFIGURE_FILE"
  CONFIGURE_FILE=$ans;
  echo "Setting CONFIGURE_FILE to $ans.";
fi
echo
#
######### Decide, where to place the log files ######################
#
FOUND="";
if [ ! -r "$LOG_FILE_PATH" ] ; then
# First look for a logfile named "exim_mainlog" in some famous directories...
  CPATHS="/usr/exim/log /var/exim/log /usr/local/exim/log";
  CPATHS="$CPATHS /usr/local/lib/exim/log /var/spool/exim/log";
  CPATHS="$CPATHS /var/log /usr/log /var/adm /usr/adm";
  eval 'for i in '$CPATHS' ; do
    if [ -r "$i/exim_mainlog" ] ; then
      FOUND=$i;
      LOG_FILE_PATH="$i/exim_%slog";
      echo "Found logfiles in $i.";
      break;
    fi
  done'
# If nothing found, look for some famous directories...
  if [ -z "$FOUND" ] ; then
    eval 'for i in '$CPATHS' ; do
      if [ -d $i ] ; then
        FOUND=$i;
        LOG_FILE_PATH="$i/exim_%slog";
        echo "Found directory named \"$i\".";
        break;
      fi
    done'
  fi
fi
# Ask if nothing found
if [ -z "$FOUND" ] ; then
  echo "Where should the logfiles be placed? ";
  readln "(LOG_FILE_PATH) [$LOG_FILE_PATH]:" "$LOG_FILE_PATH" "$LOG_FILE_PATH"
  LOG_FILE_PATH=$ans;
  echo "Setting LOG_FILE_PATH to $ans.";
fi
echo
#
######### Decide, where to place the spool directory ##################
#
FOUND="";
if [ ! -d "$SPOOL_DIRECTORY" ] ; then
# Look for an existing spool directory...
  CPATHS="/usr/exim/spool /var/spool/exim /usr/spool/exim";
  CPATHS="$CPATHS /spool/exim /var/exim/spool"
  eval 'for i in '$CPATHS' ; do
    if [ -d $i ] ; then
      FOUND=$i;
      SPOOL_DIRECTORY=$i;
      echo "Found directory named \"$i\".";
      break;
    fi
  done'
fi
# Just ask, if nothing was found
if [ ! -d "$SPOOL_DIRECTORY" ] ; then
  echo "Where should Exim place its queue and database? ";
  readln "(SPOOL_DIRECTORY) [$SPOOL_DIRECTORY]:" "$SPOOL_DIRECTORY" \
     "$SPOOL_DIRECTORY"
  SPOOL_DIRECTORY=$ans;
  if [ -z "$SPOOL_DIRECTORY" ] ; then
      SPOOL_DIRECTORY="/var/spool/exim";
  fi
  echo "Setting SPOOL_DIRECTORY to $SPOOL_DIRECTORY.";
fi
echo
#
######### Decide, where to place the pid directory ####################
#
if [ ! -d "$PID_FILE_PATH" ] ; then
# Look for an existing pid directory...
  CPATHS="/var/pid /var/run /var/lock /var/spool/pid /var/spool/run"
  CPATHS="$CPATHS /var/spool/lock /usr/pid /usr/run /usr/lock"
  FOUND="";
  eval 'for i in '$CPATHS' ; do
    if [ -d $i ] ; then
      X=`ls $i/*.pid`
      if [ ! -z "$X" ] ; then
        FOUND=$i;
        PID_FILE_PATH="$i/exim%s.pid";
        echo "Found pid-file in \"$i\".";
        break;
      fi
    fi
  done'
  eval 'for i in '$CPATHS' ; do
    if [ -d $i ] ; then
      FOUND=$i;
      PID_FILE_PATH="$i/exim%s.pid";
      echo "Found directory \"$i\".";
      break;
    fi
  done'
fi
# Just ask, if nothing was found or Exim is not running as root
if [ -z "$FOUND" ] || [ ! -z "$EXIM_UID" ]; then
  echo
  echo "Where should Exim place its process id? ";
  echo "If you choose a setting here, it has to contain the '%s' string"
  echo "for the port number, e.g. /var/run/exim%s.pid"
  while [ true ] ; do
    readln "(PID_FILE_PATH) [$PID_FILE_PATH]:" "$PID_FILE_PATH" \
       "$PID_FILE_PATH"
    PID_FILE_PATH=$ans;
    if [ -z "$PID_FILE_PATH" ] ; then
      break;
    fi
    case $PID_FILE_PATH in
      *%s*)
         break ;;
      *)
         echo "Your path *has* to contain a '%s'." ;;
    esac
  done
  echo "Setting PID_FILE_PATH to $ans.";
fi
#
#
while [ true ] ; do
  echo
  echo "BIN_DIRECTORY    Exim installed in:   $BIN_DIRECTORY"
  echo "SPOOL_DIRECTORY  Queues etc. in:      $SPOOL_DIRECTORY"
  echo "CONFIGURE_FILE   Configuration file:  $CONFIGURE_FILE"
  echo "LOG_FILE_PATH    Logging files as:    $LOG_FILE_PATH"
  echo "PID_FILE_PATH    PID files as:        $PID_FILE_PATH"
  echo
  UPDATE="n";
  bool "Change any of these?" UPDATE $UPDATE
  case "$UPDATE" in 
    n) break;
       ;;
  esac;
  echo
  echo "Where should Exim place its binaries ? ";
  readln "(BIN_DIRECTORY) [$BIN_DIRECTORY]:" "$BIN_DIRECTORY" \
     "$BIN_DIRECTORY"
  BIN_DIRECTORY=$ans;
  echo
  echo "Where should Exim place its queues ? ";
  readln "(SPOOL_DIRECTORY) [$SPOOL_DIRECTORY]:" "$SPOOL_DIRECTORY" \
     "$SPOOL_DIRECTORY"
  SPOOL_DIRECTORY=$ans;
  echo
  echo "Where is the configuration file for Exim ?";
  readln "(CONFIGURE_FILE) [$CONFIGURE_FILE]:" "$CONFIGURE_FILE" \
     "$CONFIGURE_FILE"
  CONFIGURE_FILE=$ans;
  echo
  echo "Where should Exim place its logfiles? ";
  readln "(LOG_FILE_PATH) [$LOG_FILE_PATH]:" "$LOG_FILE_PATH" \
     "$LOG_FILE_PATH"
  LOG_FILE_PATH=$ans;
  echo
  echo "Where should Exim place its process id? ";
  readln "(PID_FILE_PATH) [$PID_FILE_PATH]:" "$PID_FILE_PATH" \
     "$PID_FILE_PATH"
  PID_FILE_PATH=$ans;
done
echo
#
######### Decide, if to build eximon or not #########################
#
CPATHS="/vvva /usr/X11/lib /usr/X11R6/lib /usr/X11R5/lib /usr/lib/X11";
CPATHS="$CPATHS /usr/openwin/lib /usr/lib /lib";


for j in "libXaw.*" "libXmu.*" "libXt.*" "libXext.*" "libX11.*" ; do
  FOUND="";
  eval 'for i in '$CPATHS' ; do
    if [ -d $i ] ; then
      ls $i/$j > /dev/null 2>&1 ;
      if [ "$?" -eq "0" ] ; then
        FOUND=$i;
        echo "Found $j in \"$i\".";
        break;
      fi
    fi
  done'
  if [ -z "$FOUND" ] ; then
    echo "Did not find \"$i\" - not (all) X11-libraries installed.";
    break;
  fi
done
# Now we look for one specific X11-include-file (X11/Xaw/Form.h)
if [ ! -z "$FOUND" ] ; then
  FOUND="";
  CPATHS="/usr/X11/include /usr/X11R6/include /usr/X11R5/include /usr/include";
  CPATHS="$CPATHS /usr/openwin/include /usr/include/X11 /usr/include/X11R5";
  FOUND="";
  eval 'for i in '$CPATHS' ; do
    if [ -d $i ] && [ -r $i/X11/Xaw/Form.h ] ; then
      FOUND="$i";
      echo "Found X11-include-headers in \"$i\".";
      break;
    fi
  done'
  if [ -z "$FOUND" ] ; then
    echo "Did not find X11-include-headers.\n";
    break;
  fi
fi
#
if [ -z "$FOUND" ] ; then
  echo "Some files required for eximon are missing, not building eximon.";
  EXIM_MONITOR="";
else
  echo
  echo "You might build the graphical monitor for Exim, eximon."
  echo "Eximon uses X11, which seems to be installed on your system."


  EXIM_MONITOR="y";
  bool "Do you want to build eximon?" EXIM_MONITOR
  if [ "$EXIM_MONITOR" = "y" ] ; then
    EXIM_MONITOR="eximon.bin";
  else
    EXIM_MONITOR="";
  fi
fi
echo
#
######### Decide, how many logfiles should be kept ##################
#
echo "A script called exicyclog rotates the logfiles (e.g. daily)";
echo "and compresses the elder ones. How many old versions do you";
readln "want to keep? [1-nnn, Current: $EXICYCLOG_MAX]: " 10 $EXICYCLOG_MAX;
EXICYCLOG_MAX=$ans;
echo
#
######### Now the real job: We actually build Local/Makefile ########
#
if [ ! -d Local ] ; then
  mkdir Local
fi
echo "Building Local/Makefile...";
( cat <<ENDOFVARS
<<=BIN_DIRECTORY=$BIN_DIRECTORY=
<<=CHGRP_COMMAND=$CHGRP_COMMAND=
<<=CHOWN_COMMAND=$CHOWN_COMMAND=
<<=COMPRESS_COMMAND=$COMPRESS_COMMAND=
<<=COMPRESS_SUFFIX=$COMPRESS_SUFFIX=
<<=CONFIGURE_FILE=$CONFIGURE_FILE=
<<=CONFIGURE_FILE_USE_EUID=$CONFIGURE_FILE_USE_EUID=
<<=CONFIGURE_FILE_USE_NODE=$CONFIGURE_FILE_USE_NODE=
<<=DB_DIRECTORY_MODE=$DB_DIRECTORY_MODE=
<<=DB_LOCKFILE_MODE=$DB_LOCKFILE_MODE=
<<=DB_MODE=$DB_MODE=
<<=DELIVER_BUFFER_SIZE=$DELIVER_BUFFER_SIZE=
<<=DIRECTOR_ALIASFILE=$DIRECTOR_ALIASFILE=
<<=DIRECTOR_FORWARDFILE=$DIRECTOR_FORWARDFILE=
<<=DIRECTOR_LOCALUSER=$DIRECTOR_LOCALUSER=
<<=DIRECTOR_SMARTUSER=$DIRECTOR_SMARTUSER=
<<=EXICYCLOG_MAX=$EXICYCLOG_MAX=
<<=EXIM_GID=$EXIM_GID=
<<=EXIM_MONITOR=$EXIM_MONITOR=
<<=EXIM_UID=$EXIM_UID=
<<=HEADER_MAXLENGTH=$HEADER_MAXLENGTH=
<<=INPUT_DIRECTORY_MODE=$INPUT_DIRECTORY_MODE=
<<=LOG_DIRECTORY_MODE=$LOG_DIRECTORY_MODE=
<<=LOG_FILE_PATH=$LOG_FILE_PATH=
<<=LOG_MODE=$LOG_MODE=
<<=LOOKUP_DBM=$LOOKUP_DBM=
<<=LOOKUP_DNSDB=$LOOKUP_DNSDB=
<<=LOOKUP_LDAP=$LOOKUP_LDAP=
<<=LOOKUP_LSEARCH=$LOOKUP_LSEARCH=
<<=LOOKUP_NIS=$LOOKUP_NIS=
<<=LOOKUP_NISPLUS=$LOOKUP_NISPLUS=
<<=LOOKUP_TESTDB=$LOOKUP_TESTDB=
<<=MSGLOG_DIRECTORY_MODE=$MSGLOG_DIRECTORY_MODE=
<<=MV_COMMAND=$MV_COMMAND=
<<=PERL_COMMAND=$PERL_COMMAND=
<<=PID_FILE_PATH=$PID_FILE_PATH=
<<=RM_COMMAND=$RM_COMMAND=
<<=ROUTER_DOMAINLIST=$ROUTER_DOMAINLIST=
<<=ROUTER_IPLITERAL=$ROUTER_IPLITERAL=
<<=ROUTER_IPLOOKUP=$ROUTER_IPLOOKUP=
<<=ROUTER_LOOKUPHOST=$ROUTER_LOOKUPHOST=
<<=ROUTER_QUERYPROGRAM=$ROUTER_QUERYPROGRAM=
<<=SPOOL_DIRECTORY=$SPOOL_DIRECTORY=
<<=SPOOL_DIRECTORY_MODE=$SPOOL_DIRECTORY_MODE=
<<=SPOOL_MODE=$SPOOL_MODE=
<<=STDERR_FILE=$STDERR_FILE=
<<=TRANSPORT_APPENDFILE=$TRANSPORT_APPENDFILE=
<<=TRANSPORT_AUTOREPLY=$TRANSPORT_AUTOREPLY=
<<=TRANSPORT_DEBUG=$TRANSPORT_DEBUG=
<<=TRANSPORT_PIPE=$TRANSPORT_PIPE=
<<=TRANSPORT_SMTP=$TRANSPORT_SMTP=
ENDOFVARS


cat src/EDITME
) | \
awk -F'=' ' 
/^<<=/ {
     if ($3!="") {
         ENVIRON[$2] = $3 ;
     }
     next;
}
/^[# ]*[A-Z_-]+[ ]*[=]+/ {
     if (substr($1,1,1)=="#") {
       print $0;
       while (substr($1,1,1)=="#" || substr($1,1,1)==" ") {
         $1 = substr($1,2,512);
       }
       if (ENVIRON[$1]!="" && $1!="EXIM_GID") {
         print $1 "=" ENVIRON[$1];
         ENVIRON[$1] = "";
         if ($1=="EXIM_UID" && ENVIRON["EXIM_GID"]!="") {
           print "EXIM_GID=" ENVIRON["EXIM_GID"]
           ENVIRON["EXIM_GID"]="";
         } 
       } 
     } else { 
       if (ENVIRON[$1]!="") {
         print $1 "=" ENVIRON[$1] ;
       } else {
         print "# " $0;
       }
     }
     next;
}
{
     print $0;
}' > Local/Makefile.new
if [ -f Local/Makefile ] ; then
  rm -f Local/Makefile.old
  mv Local/Makefile Local/Makefile.old
fi
mv Local/Makefile.new Local/Makefile
if [ ! -z "$EXIM_MONITOR" ] && [ ! -f Local/eximon.conf ] ; then
  if [ ! -r exim_monitor/EDITME ] ; then
     echo "WARNING: Can't access exim_monitor/EDITME!"
     echo "Please copy this file manually to Local/eximon.conf!"
  else  
     cp exim_monitor/EDITME Local/eximon.conf
  fi
fi
echo
echo "Done!";
echo 
echo "You might now build Exim by typing \"make\"!";