#!/bin/sh # Copyright (c) 2003-2004 Andrew McNabb # Mailpipe Script mailhost="mail.mcnabbs.org" localuser="mailpipe" remoteuser="mailpipe" remoteport="2525" localport="2525" sshkey="/home/mailpipe/mailkey" # This is what the remote server thinks our host is named: it really doesn't # matter as long as the queue names match up. queuename="mobile.mydomain.com" # Kill any existing tunnels /sbin/start-stop-daemon --stop --user $localuser # TEST CONNECTION # I'm turning this off because OIT is stupid #/bin/ping -q -c1 -w5 $mailhost /dev/null #error=$? #echo $error >/tmp/mailt.out #if [ $error -ne 0 ] ; then # echo ${error} "${mailhost} unreachable!" # return 1 #fi # ESTABLISH SSH SMTP PORT TUNNEL #add/remove -C for compression/no compression /sbin/start-stop-daemon --start \ --chuid $localuser --user $localuser --startas /usr/bin/ssh \ -p "aeuaeoueoauoeauao" \ -- -C -f -i $sshkey -l $remoteuser -n -N -R ${remoteport}:localhost:25 $mailhost if [ $? -ne 0 ] ; then echo "Couldn't establish incoming ssh tunnel with ${mailhost}!" exit 1 fi /sbin/start-stop-daemon --start \ --chuid $localuser --user $localuser --startas /usr/bin/ssh \ -p "aeuaeoueoauoeauao" \ -- -C -f -i $sshkey -l $remoteuser -n -N -L ${localport}:localhost:25 $mailhost if [ $? -ne 0 ] ; then echo "Couldn't establish outgoing ssh tunnel with ${mailhost}!" exit 1 fi # NOTIFY REMOTE HOST TO RESEND QUEUED MAIL /usr/bin/sudo -u mailtunnel /usr/bin/ssh -i $sshkey -n -l $remoteuser $mailhost /usr/sbin/sendmail -qR${queuename} error=$? if [ $error -ne 0 ] ; then #let's not actually quit; let's just let them know echo "Couldn't notify ${mailhost}!" >&2 #exit 1 fi sleep 5 /usr/sbin/sendmail -q