#!/bin/sh

# This script assumes checksums of this local (slave) collection is
# maintained in /netlib/crc/nac.  Pick your own name.
# Installation Note.  For easiest anonymous ftp, you may wish to add
# to the file  .netrc  in your home directory the line
#   machine netlib.bell-labs.com login anonymous password your@email.address

umask 2  # can't be umask 113 else directories get wrong permissions!

# retrieve the master's checksums
cd /netlib/crc/net
ftp netlib.bell-labs.com <<!
binary
prompt
verbose
cd netlib/crc/net
mget *.gz
quit
!
gunzip -f *.gz || exit 11
lsr compressed nac ornl res | crc > custodiens
(masterslave quis_custodiet custodiens | grep -s '^get') && exit 12
rm quis_custodiet custodiens || exit 13

# now see what's needed
cd /netlib
m=/tmp/mirror
f=/tmp/ftp
sort -u crc/net/net crc/net/ornl > /tmp/ctm$$
sort -u crc/nac/net crc/nac/ornl > /tmp/cts$$
masterslave /tmp/ctm$$ /tmp/cts$$ | grep -v '\.\.|^/' > $m
rm /tmp/ct[ms]$$
cat $m
plausible < $m || (echo 'implausible'; exit 1)

# do it
mirror ftp netlib.bell-labs.com netlib /netlib/crc/net/compressed < $m > $f
sh $f
sed -n 's/get \([^ ]*\) .*/\1/p' < $m | while read i; do
	/bin/test -s $i.gz && (rm -f $i; gunzip $i.gz)
	ls -l $i
	done
chktime < $m
rm $f