#!/bin/csh -f
set files="{/etc/exports,/var/local,/var/spool/mail,/var/public,/var/pub,/var/adm/crontab.local,/.login.local,/.cshrc.local,/etc/aliases.local,/etc/ttys,/etc/srvtab,/etc/rc.private,/p,/public,/u,/src,/etc/sendmail.cf,/var/spool/mqueue}"

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 "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 "Decstation hostname(csl5/csl6)? "
	set decstation=$<
	switch ($decstation)
		case csl4:
		case csl5:
		case csl6:
		case limby:
			breaksw
		case "":
			echo You must specify a name.
			goto getname
			breaksw
		default:
			echo Invalid decstation name.
			goto getname
			breaksw
	endsw

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

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

echo Transporting files from $srchost to $decstation
cd /var/home
rm -rf /var/home/condor/*
tar cf - ./* | rsh $decstation "(cd /var/home; tar xpf -)"
echo "Creating condor directory for new architecture."
rsh $decstation "/usr/psup/condor/bin/condor_init"
echo $files
rdist -c $files $decstation

echo Creating /home/$decstation
rsh $decstation "ln -s /var/home /home/$srchost"

echo Changing /etc/rc.hostname
rsh $decstation "echo $srchost >! /etc/rc.hostname"

echo 'doing aliases'
rsh $decstation "(cd /usr/lib ; touch /etc/aliases.local ; make INSTDIR=/etc install)"

echo uVInstall done.
