#!/bin/sh
#
# $Id: masqmail_route,v 1.3 2002/11/01 22:05:29 andrew Exp $
#
# Integration (well sort of :-) of whereami with masqmail.
#
# This script looks at the masqmail configuration of the online
# file (usually "/tmp/connect_route") and removes it. If one of
# our current locations matches a location for which masqmail
# is configured then we create a new file with that location.
#

# whereami sets the list of locations to be comma-separated - possibly a mistake!
LOCATIONS="`echo ${LOCATION} | tr ',' ' '`"

# Work out what masqmail has specified for the notification file
ONLINE_FILE="`grep "^online_file *=" /etc/masqmail/masqmail.conf | cut -f2 -d= | tr -d \\"\\  `"

# Remove any existing indications of which location we should use
rm -f ${ONLINE_FILE}

for LOCN in ${LOCATIONS} ; do
  if grep "^connect_route.${LOCN} *=" /etc/masqmail/masqmail.conf >/dev/null ; then
    logger -t whereami -i "Setting masqmail route in ${ONLINE_FILE} to \"${LOCN}\""
    echo "${LOCN}" > ${ONLINE_FILE}

    # We exit on the first success
    exit 0;
  fi
done

