#!/bin/sh
#
# push-data
# John Simpson 2004-08-25
#
# pushes new validrcptto.cdb file to mailhub servers using SSH
# expects slaves to have a forced command attached to this key, and that
# the command will know what to do with the data we're sending.
#
# 2006-02-15 jms1 - expanding to also push rcpthosts, morercpthosts.cdb,
# and a customized version of smtproutes. see this web page for more
# information: http://qmail.jms1.net/mailhub.shtml
#
# 2006-07-16 jms1 - fixed a typo (a missing "done" in the loops which
# actually push the files.) thanks to Lawrence Sheed for spotting the
# typo.
#
# 2007-01-26 jms1 - adding auth.cdb to the mix
#
###############################################################################
#
# Copyright (C) 2004-2007 John Simpson.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or visit http://www.gnu.org/licenses/gpl.txt
#
###############################################################################
# list of mailhub IP's, separated by spaces.
SERVERS=""
# ssh port on mailhub machines. should be the same for all servers.
PORT="22"
# remote userid on mailhub machines. should be the same for all servers.
USERID=""
# SSH private key file. should be the same for all servers.
IDFILE=""
# the name and port number that the mailhubs' smtproutes file need to
# point to for domains listed in "locals" and "virtualdomains" on this
# server.
MYNAME=`cat /var/qmail/control/me`
MYPORT=""
# if you try to run this while you are ssh'd into the server using a key
# stored in an agent, the key stored in your agent will override the key
# specified on the ssh command line. clearing this variable makes the
# script become not aware of the agent and therefore work normally.
unset SSH_AGENT_SOCK
###############################################################################
###############################################################################
###############################################################################
#
# first build the files for the mailhubs
# the "smtproutes" file needs special handling
WORK=`mktemp -d mailhub.XXXXXXXXXX`
for file in validrcptto.cdb rcpthosts morercpthosts.cdb auth.cdb
do
if [ -f /var/qmail/control/$file ]
then
cp /var/qmail/control/$file $WORK/$file
else
touch $WORK/$file
fi
done
########################################
# build custom smtproutes for mailhub use.
# needs to be the smtproutes from the mailbox server,
# plus the domains from "locals" and "virtualdomains"
# pointing back to this server.
if [ -n "$MYPORT" ]
then
ME="$MYNAME:$MYPORT"
else
ME=$MYNAME
fi
if [ -f /var/qmail/control/smtproutes ]
then
cp /var/qmail/control/smtproutes $WORK/smtproutes
else
touch $WORK/smtproutes
fi
if [ -f /var/qmail/control/locals ]
then
sed "s/$/:$ME/" /var/qmail/control/locals \
>> $WORK/smtproutes
fi
if [ -f /var/qmail/control/virtualdomains ]
then
sed "s/:.*/:$ME/" /var/qmail/control/virtualdomains \
>> $WORK/smtproutes
fi
###############################################################################
#
# do the deeds
for server in $SERVERS
do
for file in validrcptto.cdb rcpthosts morercpthosts.cdb auth.cdb \
smtproutes
do
echo "/---- Start of messages from $server for $file"
cat $WORK/$file | \
ssh -i "$IDFILE" -p $PORT "${USERID}@$server" $file \
| sed 's/^/| /'
echo "\\---- End of messages from $server for $file"
done
done
###############################################################################
#
# clean up
rm -rf $WORK