#!/bin/sh
set -u  # force better programming and ability to use check for not set
if [ "${1:-}" = "-x" ] ; then set -xv; shift; fi

node=`uname -n| sed -e 's/\([^\.]\)\..*/\1/'`

if [ "${1:-}" = "-node" ]; then
   shift
   match=$1
   shift
else
  case $node in
    stkensrv*)
      match=d0ensrv`echo $node |sed -e 's/stkensrv//'`
      ;;
    doensrv*)
      match=stkensrv`echo $node |sed -e 's/d0ensrv//'`
      if [ "$match" = "stkensrv5" ]; then match=stkensrv3; fi
      ;;
    stkenmvr*)
      match=d0enmvr18a
      ;;
    d0enmvr*)
      match=d0enmvr18a
      ;;
  *)
    echo "Don't know how to match `uname -n` - fix me"
    exit 1
    ;;
  esac
fi

if [ "${1:-dog}" = "doit" ]; then shift; X=""; else X="--dry-run";fi

OUTPUT=SYNC.$node.$match
rm -f $OUTPUT

echo "Matching $X $node to $match" | tee $OUTPUT

# NOTE: the -e option does not appear to exist on sgi machines
/usr/bin/rsync -e /home/enstore/enstore/sbin/enrsh -c -r -R -l -p -o -g -D -t -x $X \
               --exclude="*~" \
               --exclude="/tmp/*" \
               --exclude="*.Xauthority" \
               --exclude="*.acrorc" \
               --exclude=".bash_history" \
               --exclude="*.jon*" \
               --exclude="*.pyc" \
               --exclude="*.saves-*" \
               --exclude="*random_seed" \
               --exclude="*en*.startup" \
               --exclude="*monitor_server.output" \
               --exclude="*autosave*" \
               --exclude="*CRON" \
               --exclude="*HISTOGRAM" \
               --exclude="**/1" \
               --exclude="/BITERROR" \
               --exclude="/PRODUCTION" \
               --exclude="/SEL" \
               --exclude="/boot/map" \
               --exclude="/dev/*" \
               --exclude="/etc/HOSTNAME" \
               --exclude="/etc/adjtime" \
               --exclude="/etc/ioctl.save" \
               --exclude="/etc/mtab" \
               --exclude="/etc/ntp/*" \
               --exclude="/etc/sysconfig/network" \
               --exclude="/etc/sysconfig/network-scripts/ifcfg-eth0" \
               --exclude="/etc/sysconfig/network-scripts/ifcfg-eth1" \
               --exclude="/home/*" \
               --exclude="/local/ups/prd/www_pages/*" \
               --exclude="/lost+found/*" \
               --exclude="/opt/l440/rom_dos/ned.cfg" \
               --exclude="/opt/lmbench-2alpha11/bin/i686-linux/CONFIG*" \
               --exclude="/opt/lmbench-2alpha11/results/PS/*" \
               --exclude="/opt/lmbench-2alpha11/results/i686-linux*.fnal.gov*" \
               --exclude="/opt/lmbench-2alpha11/results/tmp/*" \
	       --exclude="/opt/rtboot/tomsrtbt-1.7.140/tomsrtbt-1.7.140.unpacked/2/dev/initctl" \
               --exclude="/root/.ssh/known_hosts" \
               --exclude="/root/crontab" \
               --exclude="/root/R" \
               --exclude="/root/SYNC*" \
               --exclude="/root/arp.list" \
               --exclude="/tmp/*" \
               --exclude="/usr/local/*xemacs*.elc" \
               --exclude="/usr/local/lib/xemacs-21.1.7/i686-pc-linux/config.values" \
               --exclude="/usr/src/linux*/*.a" \
               --exclude="/usr/src/linux*/*.o" \
               --exclude="/var/adm/www/*" \
               --exclude="/var/catman/*" \
               --exclude="/var/lib/locatedb" \
               --exclude="/var/lib/logrotate.status" \
               --exclude="/var/lib/rpm/*" \
               --exclude="/var/lock/*" \
               --exclude="/var/log/*" \
               --exclude="/var/run/*" \
               --exclude="/var/spool/*" \
               --exclude="/var/tmp/*" \
               --exclude="/var/spool/*" \
/ $match:/ | tee $OUTPUT

exit 0
               --exclude="*modules.dep" \
               --exclude="*whatis" \
               --exclude="/etc/rc.d/rc.local" \
               --exclude="/etc/rc.d/rc.sysinit" \
               --exclude="/etc/fstab" \
               --exclude="/etc/issue*" \
               --exclude="/usr/local/etc/farmlets*" \
