#!/bin/csh -f
set files="{/var/spool/mail,/usr/adm/sendmail/sendmail.cf,/usr/adm/sendmail/aliases.local,/var/spool/mqueue/*,/usr/local,/etc/rc.private,/usr/adm/ftp,/usr/spool/cron/crontabs}"

echo killing sendmail
set x = ( `ps ax | egrep 'sendmail' | egrep -v egrep | awk '{ print $1 }'` )
if ( $x != "") then
	echo Killing $x
	kill -9 $x
else
	echo No daemon to kill.
endif

echo "Did you unmount all NFS filesystems (particularly any mounted below"
echo "/usr/home?)  If not, suspend now and do that before continuing."
echo -n "<return> to continue"

set CONTINUE=$<

echo "Move to new machine in progress.... " > /etc/nologin
echo "Move to new machine in progress.... DO NOT USE THIS MACHINE" > /etc/motd

set srchost=`hostname`
getname:
echo -n "Sparcstation hostname(ie. sparcinstall2)? "
	set sparcstation=$<

echo Transporting special files.
foreach file ( fstab passwd group exports)
	echo $file
	rdist -c /etc/$file $sparcstation\:/etc/$file\.$srchost
end
echo Merging password and group files.
rsh $sparcstation "grep root /etc/passwd.$srchost > /usr/tmp/newpasswd ;\
        grep -v root /etc/passwd >> /usr/tmp/newpasswd;\
        awk -f /common/usr/lab/lib/sparcinstall.passwd /etc/passwd.$srchost >>/usr/tmp/newpasswd;\
        cp /usr/tmp/newpasswd /etc/passwd"

rsh $sparcstation "grep system /etc/group.$srchost > /usr/tmp/newgroup ;\
        grep -v wheel /etc/group >> /usr/tmp/newgroup ;\
        awk -f /common/usr/lab/lib/sparcinstall.group /etc/group.$srchost >>/usr/tmp/newgroup;\
        cp /usr/tmp/newgroup /etc/group"


echo "Turning off condor"
/usr/psup/condor/bin/condor_off
echo Transporting files from $srchost to $sparcstation
cd /var/home
rm -rf /var/home/condor/*
/usr/psup/bin/tar cf - ./* | rsh $sparcstation "(cd /usr/home; /usr/psup/bin/tar xpf -)"
echo $files
rdist -c $files $sparcstation

echo "Configuring condor on remote sparcstation $sparcstation"
rsh $sparcstation "/usr/psup/condor/bin/condor_init"

rsh $sparcstation "mv /usr/spool/mqueue/syslog* /var/log"
rsh $sparcstation "ln -s /var/log/syslog /usr/spool/mqueue/syslog"

if ( -f /etc/localrc ) then
	rcp /etc/localrc $sparcstation\:/etc/rc.private
	echo "Copied /etc/localrc to /etc/rc.private on $sparcstation"
endif

if ( -f /usr/lib/crontab.local ) then
	rcp /usr/lib/crontab.local $sparcstation\:/usr/spool/cron/crontabs
	echo "crontab.local copied to /usr/spool/cron/crontabs/crontab.local"
	echo "MUST be edited and submitted with crontab command as proper user"
endif

if ( -f /etc/exports ) then
   echo "/etc/{exports,fstab} copied to /etc/{exports,fstab}.$srchost"
   echo "You must edit these manually into proper format."
endif

echo Changing /etc/hostname.le0
rsh $sparcstation "echo $srchost >! /etc/hostname.le0"

echo 'doing aliases'
rsh $sparcstation /usr/lab/bin/mkaliases

echo SparcInstall done.
