#! /bin/sh

PATH=/usr/local/bin:/usr/local/sbin:$PATH

## Generate an alias file of passwd aliases for propogation to delysid.
# It turns out that the exim config completely ignores the right hand side
# of this alias, but putting the IP address here makes a vaguely right thing
# happen if exim were misconfigured to actually use the right hand side.
awk -F: </etc/passwd >/com/mailer/delysid.passwd.aliases \
  ' { printf "%s: %s@[199.232.76.164]\n", $1, $1 } '

## Generate a file of aliases to make real-lusername@gnu.org work
awk -F: </etc/passwd >/com/mailer/delysid.real.aliases \
  ' { printf "real-%s: real-%s@[199.232.76.164]\n", $1, $1 } '

## Generate a file of aliases so that procmail deliveries are handled
## properly.
awk -F: </etc/passwd ' { printf "if test -e ~%s/.procmailrc; then echo %s: %s@[199.232.76.164]; fi\n", $1, $1, $1 } '|sh >/com/mailer/delysid.procmail.aliases

## Propogate the aliases file and the various include files to delysid.
# Since GNU tar insists on relative paths anyway, cd into /com/mailer
cd /com/mailer
# Start with an empty archive
rm /com/mailer/propogate-to-delysid.tar
# Start with the aliases file
tar cf /com/mailer/propogate-to-delysid.tar aliases
tar rf /com/mailer/propogate-to-delysid.tar local_mail_domains
tar rf /com/mailer/propogate-to-delysid.tar delysid.passwd.aliases
tar rf /com/mailer/propogate-to-delysid.tar delysid.real.aliases
tar rf /com/mailer/propogate-to-delysid.tar delysid.procmail.aliases
tar rf /com/mailer/propogate-to-delysid.tar aliases-savannah.gnu.org
tar rf /com/mailer/propogate-to-delysid.tar aliases-freesoftware
# Then add any :include: files that live in /com/mailer/
sed '/^#/d' </com/mailer/aliases |
sed -n 's,^.*:include:/com/mailer/,,gp' |
sed 's/[ ,].*$//' |
sed -e "s,^,tar rf /com/mailer/propogate-to-delysid.tar ," |
sh

scp -i /root/.ssh/identity.delysid.push /com/mailer/propogate-to-delysid.tar delysid.gnu.org:/com >/dev/null
ssh -i /root/.ssh/identity.delysid.unpack delysid.gnu.org >/dev/null 2>&1


















