#! /bin/csh
set noglob
######Message Texts######
set mesg1 = "creating cluster swap directory   "
set done = "done."
set mesg2 = "creating /dev/enet*  "
set mesg3 = "creating /dev/pty*  "
set mesg4 = "Enter name for new cluster node: "
set mesg5 = "That name has already been used, please enter another: "
set mesg6 = "Is "
set mesg6b = " a graphics station? (y or n) "
set mesg7 = "  Please respond 'y' or 'n'"
set mesg10 = "Bootstrap string for cluster node will be:"
set mesg12 = " Type <return> when ready."
set mesg13 = "Node address file has not been set up yet, use admin to do so."
set mesg14 = "One moment please"
#########################
#
# csh script to install support for a new clustered node
#
# for the first attempt, we will only worry about:
#
#        /tmp
#        /usr/tmp
#        /etc/ttys
#        /etc/ttytype
#        /etc/rc
#        /etc/rc.local
#        /etc/utmp
#        /usr/adm
#        /usr/lib/crontab
#

# make sure set_nodes has been run
set HID = `fgrep /bin/hostname /etc/rc.local | awk '{print $2}'`
if ( $HID == UNKNOWN ) then 
	echo $mesg13
	sleep 10
	exit(0)
endif
#
# now set up cluster swap area if it does not exist
# also devices for enet and pty's
#
#
# get hostname for new cluster node and
# assign next available address
#
echo -n $mesg4" "
get_newhost:
set NEWHOST = ($<)
if ( $#NEWHOST == 0 ) then
	goto get_newhost
endif
grep -sw $NEWHOST /etc/hosts
if ( $status != 1 ) then 
	echo -n $mesg5" "
	goto get_newhost
endif

g_loop:
echo -n $mesg6$NEWHOST$mesg6b" "
set GRAPHICS = ($<)
if ( ($GRAPHICS != y) && ($GRAPHICS != n)  ) then
    echo $mesg7
    goto g_loop
endif

echo $mesg14
set NET = `awk '{print $1" " $2}' /etc/hosts | grep -w $HID | awk '{FS="."} {print $1"."$2}'`
fgrep $NET /etc/hosts | awk '{FS="."} {print $3"."$4}' | awk '{print $1}' > temp
set i = 0
set j = 1
low_loop:
fgrep -s $i"."$j temp
if ( $status != 1) then
	set j = `expr $j + 1`
	if ( $j > 255 ) then
		set j = 1
		set i = `expr $i + 1`
	endif
	goto low_loop
endif
set MID = $j
set CLUSNET = `awk '{print $1" " $2}' /etc/hosts | grep -w $HID | awk '{FS="."} {print $4}' | awk '{print $1}'`

/bin/rm -f temp
#
# do file installations, with special cases for /etc/rc.local and
# /etc/ttys if cluster node is graphics.
#
set SID = `awk '{print $1" " $2}' /etc/hosts | grep -w $HID | awk '{FS="."} {print $4}' | awk '{print $1}'`
echo $mesg10
echo ""
echo "	vb(0,0)${HID}:/vmunix HOST=$NEWHOST MID=$MID SID=$SID"
echo ""
echo $mesg12
set FOO = ($<)
