#!/bin/sh
# ~jhs/bin/.sh/majordomo_receive.sh
# This script receives at home, from the remote majordomo server master host.
# See Also:
#	~jhs/public_html/bin/.sh/majordomo_send.sh
#	/site/domain/berklix/etc/Distfile.master
recipients=jhs-list
cd /tmp	# Paranoid safety.
lokal=/usr/backup/host/list/usr/local
tarsd=$lokal/majordomo.tars
cd $tarsd || echo "$0 failed to cd $tarsd" | \
	mail -s "$0 cd failed" $recipients
cd $tarsd || exit 1
nice uudecode && ls -l | tail -2 | \
	mail -s "$0 uudecode succeeded `date -u +%Y-%m-%dT%H:%M:%SZ` `pwd`" \
		$recipients
for i in lists archives digests ; do
	rm -rf $lokal/majordomo.$i
	mkdir $lokal/majordomo.$i
        cd $lokal/majordomo.$i || \
		echo "$0 failed to cd $i" | \
                mail -s "$0 failed to cd $i" $recipients
	# Extract last archive
	(cd $tarsd ; cat `/bin/ls -1 majordomo.20*.$i.tgz | tail -1` ) | \
		nice tar zxf -
	done

# As I now only move majordomo.*.lists.tgz by mail, & leave
# majordomo.*.archives.tgz majordomo.*.digests.tgz to be ftp'd manually,
# majordomo.archives/ & majordomo.digests/ will be one .tgz out of
# date compared with majordomo.lists/

echo "$0 finished OK `du -s $lokal/majordomo.[a-z]*`" |\
	mail -s "$0 finished OK `date -u +%Y-%m-%dT%H:%M:%SZ`" $recipients
name=`basename $0`

cd $tarsd
date=`ls -1 *.lists.tgz|tail -1|sed -e s/majordomo.//|sed -e s/.lists.tgz//`
echo "Please fetch ftp://list1.berklix.org/$tarsd/majordomo.$date.*.tgz and also rm older (fire|list1):/$tarsd/majordomo.*.(archives|digests).tgz" \
 | mail -s "$name archives digest bin/.sh/majordomo_transmit.sh" $recipients

exit 0
