head     1.9;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.9
date     86.04.04.12.39.53;  author mark;  state Exp;
branches ;
next     1.8;

1.8
date     86.04.03.15.34.28;  author mark;  state Exp;
branches ;
next     1.7;

1.7
date     86.04.03.14.38.53;  author mark;  state Exp;
branches ;
next     1.6;

1.6
date     86.04.03.09.32.52;  author mark;  state Exp;
branches ;
next     1.5;

1.5
date     86.04.02.15.37.07;  author mark;  state Exp;
branches ;
next     1.4;

1.4
date     86.04.02.15.14.21;  author mark;  state Exp;
branches ;
next     1.3;

1.3
date     86.04.02.15.13.22;  author mark;  state Exp;
branches ;
next     1.2;

1.2
date     86.04.01.16.24.27;  author root;  state Exp;
branches ;
next     1.1;

1.1
date     86.04.01.16.24.09;  author root;  state Exp;
branches ;
next     ;


desc
@@


1.9
log
@deleted useless line of files after "RHOST $NODE $FILES"
@
text
@#! /bin/csh
set noglob
#########################
#
# csh script to install support for a new diskless/cluster 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
#	 /usr/spool/rwho
#
# variables:
#	SRV_NAME	hostname of server.
#	SRV_ADDR	internet address for server
#	SRV_ENTRY	/etc/hosts entry for server (complete line)
#	SRV_HID		hostid of server (as found in /etc/rc.local).
#	SRV_MID		hostid of server (as found MID=nnn in boot string).
#	INTERFACE	ethernet interface (probably ex0).
#
#

# set diskless or cluster
if ($1 == diskless) then
	set diskless = true
else if ($1 == cluster) then
	set diskless = false
else
	echo 'Invalid param, try again'
	exit (0)
endif
#
#
# Determine whether hostname and hostid have been set, and ifconfigs done
#
set SRV_NAME = `awk '/^[ \t]*\/bin\/hostname/ {print $2}' /etc/rc.local`
set SRV_HID = `awk '/^[ \t]*\/bin\/hostid/ {print $2}' /etc/rc.local`

if ( $SRV_NAME == UNKNOWN || $#SRV_NAME == 0) then 
	echo "Network machine name not defined in rc.local"
	echo "Use the 'Network initialization' function of admin to define it"
	echo -n "Type RETURN..."
	set dummy = ($<)
	exit(0)
endif
if ( $SRV_HID == 00000000 || $#SRV_HID == 0 ) then 
	echo "Network machine I.D. number not defined in rc.local"
	echo "Use the 'Network initialization' function of admin to define it"
	echo -n "Type RETURN..."
	set dummy = ($<)
	exit(0)
endif
#
# Convert hostid to machine id
#
set SRV_MID=`echo $SRV_HID | sed 's/000000$//' | hex_to_dec`
grep -s '^[ \t]*/etc/ifconfig' /etc/rc.local
if ( $status == 1 ) then
	echo "No ifconfigs done in rc.local.  Run 'Network initialization'"
	echo "function of admin first, then try $1 installation again."
	echo - n "Type RETURN..."
	set dummy = ($<)
	exit(0)
endif

echo The existing hostname in /etc/rc.local is $SRV_NAME
echo The existing hostid in /etc/rc.local is $SRV_HID
echo -n Type 'y' to accept these entries and continue $1 installation...
set ans = ($<)
if ( $ans != 'y' && $ans != 'Y' ) then
	echo "Use the Network Initialization function of admin to change these entries."
	echo -n "Type RETURN ..."
	set dummy = ($<)
	exit(0)
endif

#
# Get network number for the server.
#
# If this is a cluster installation, then just ask for it.  If this is a
# diskless installation, then let the user chose from the list of net. nums.
# this machine already knows about.  This list is built by grabbing all the
# names that are ifconfig'ed in rc.local, and getting their associated net.
# nums. from /etc/hosts.
#
if ($diskless == false) then
again01:
	echo -n "Enter cluster network number: "
	set NET_NUM = ($<)
	if ($#NET_NUM != 1 || $NET_NUM < 1 || $NET_NUM > 255) then
		echo "Please answer with a decimal number"
		echo "in the range 1-255."
		goto again01
	endif
	grep -s "^$NET_NUM\." /etc/hosts
	if ( $status == 0 ) then
again02:
		echo Network number $NET_NUM is already in use with the
		echo following entries:
		grep "^$NET_NUM\." /etc/hosts | sed -e 's/^/	/'
		echo -n "Is this ok (y or n)?..."
		set dummy = ($<)
		switch ($dummy)
			case y:
			case Y:
				breaksw
			case n :
			case N :
				goto again01
				breaksw
			default :
				echo Please answer y or n.
				goto again02
				breaksw
		endsw
	endif
else
	echo "" > /tmp/newline$$
	grep '^[ \t]*/etc/ifconfig' /etc/rc.local \
	| sed -e '/[ \t]vb[0-9][ \t]/d' \
	| sed -e s/\`hostname\`/$SRV_NAME/ \
	| awk '{print $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9}' \
	| tr -s '	 \012' '|' \
	| cat - /tmp/newline$$ \
	| sed -e 's/|$//' \
	> /tmp/admin.egr$$
	set egrepexpr = `cat /tmp/admin.egr$$`
	/bin/rm /tmp/admin.egr$$ /tmp/newline$$
	if ($?debug) then
		echo $egrepexpr
		egrep $egrepexpr /etc/hosts
	endif
	egrep $egrepexpr /etc/hosts > /tmp/servers$$
	set nservers = `wc -l /tmp/servers$$ | awk '{print $1}'`
	switch ($nservers)
	case 0 :
		# no ifconfigs
		echo ""
		echo "Ifconfigs in /etc/rc.local do not match any known"
		echo "hosts in /etc/hosts.  Use 'Network Initialization'"
		echo "function of admin to correct rc.local or edit /etc/hosts"
		echo "by hand."
		echo -n "Type RETURN ..."
		set dummy = ($<)
		/bin/rm -f /tmp/servers$$
		exit (0)
		breaksw
	case 1 :
		# only one entry, use it.
		echo "/etc/hosts entry for server is:"
		echo -n "	"
		cat /tmp/servers$$
		echo -n "If this is acceptable, type 'y'..."
		set dummy = ($<)
		if ( $dummy == 'y' || $dummy == 'Y' ) then
			set SRV_ADDR = `awk '{print $1}' /tmp/servers$$`
			set SRV_ENTRY = `fgrep $SRV_ADDR /tmp/servers$$`
			/bin/rm -f /tmp/servers$$
		else
			echo You will have to manually edit \
			   /etc/rc.local and /etc/hosts to support
			echo your desired server interface.
			/bin/rm -f /tmp/servers$$
			exit(0)
		endif
		breaksw
	default :
		# offer choice to user, ask him which one.
		echo "This machine has network entries for more than"
		echo "one network interface.  Please select the"
		echo "interface that the diskless node will boot from"
		echo "by typing the appropriate network address from"
		echo "the following list..."
again03:
		sed -e 's/^/	/' /tmp/servers$$
		echo -n "Network address for server?..."
		set SRV_ADDR = ($<)
		set SRV_ADDR = `echo $SRV_ADDR | awk '{print $1}'`
		set SRV_ENTRY = `fgrep $SRV_ADDR /tmp/servers$$`
		if (`echo $SRV_ENTRY | wc | awk '{print $1}'` != 1) then
			echo "Invalid entry, please re-enter..."
			goto again03
		endif
		breaksw
	endsw

	set NET_NUM = `echo $SRV_ADDR | awk '{FS="."} {print $1}'`
endif
if ($?debug) then
	echo SRV_NAME = $SRV_NAME
	echo SRV_MID = $SRV_MID
	if ($?SRV_ENTRY) echo SRV_ENTRY = $SRV_ENTRY
	if ($?SRV_ADDR) echo SRV_ADDR = $SRV_ADDR
	echo NET_NUM = $NET_NUM
endif


#
# now set up diskless/cluster swap area if it does not exist
# also devices for enet and pty's
#
if ( ! -e /usr/spool/diskless ) then
    echo -n "creating cluster swap directory   "
    mkdir /usr/spool/diskless
    chmod 700 /usr/spool/diskless
    echo " done."
endif
if ( ! -e /dev/enet0a ) then
    echo -n "creating /dev/enet*  "
    ( chdir /dev ; ./MAKEDEV enet0 )
    echo " done."
endif
if ( ! -e /dev/ptyp0 ) then
    echo -n "creating /dev/pty*  "
    ( chdir /dev ; ./MAKEDEV pty0 )
    echo " done."
endif
#
# save current hosts file in case disaster (buggy script) strikes.
#
cp /etc/hosts /etc/hosts.orig
echo "Current /etc/hosts saved in /etc/hosts.orig"
#
# get hostname for new cluster node and
# assign next available address
#
##
##  SET UP NODE NAME
set NODE = 0
set j = 1
set i = 0

cp /dev/null /tmp/hold

if ($diskless == false) then

#
# add cluster net entry *.vb 
#

	set VB=$SRV_NAME".vb"
	set tmp = `grep $VB /etc/hosts`
	if ($#tmp == 0) then
		echo $NET_NUM".0.0."$SRV_MID"	"$SRV_NAME $VB > /tmp/hold
	endif
#
# put 'ifconfig vb0' in /etc/rc.local
#
	grep -s \`hostname\`.vb /etc/rc.local
	if ($status == 1) then
ex /etc/rc.local << EOF > /dev/null
/^[ \t]*\/etc\/ifconfig/i
/etc/ifconfig	vb0 \`hostname\`.vb trailers
.
w
q
EOF
	endif
endif
#
# put bootd invocation in /etc/rc.local
#
set NBOOTDS=`grep '^[ 	]*/etc/bootd' /etc/rc.local | wc | awk '{print $1}'`
if ($NBOOTDS < 1) then
	ex /etc/rc.local << EOF > /dev/null
	/talkd/
	.-1
	r /usr/lib/admin.scripts/proto/bootd_entry
	w
	q
EOF
endif
if ($NBOOTDS < 2) then
again04:
	echo -n "Is this server serving both diskless and clustered nodes?..."
	set dummy = ($<)
	switch ($dummy)
	case 'n':
	case 'N':
		breaksw
	case 'y':
	case 'Y':
		ex /etc/rc.local << EOF > /dev/null
		/talkd/
		.-1
		r /usr/lib/admin.scripts/proto/bootd_entry
		w
		q
EOF
		breaksw
	default:
		echo "Please answer 'y' or 'n'."
		goto again04
		breaksw
	endsw
endif

#
# start of loop for adding new nodes
#
new_node:

if ($diskless == true) then
	echo -n "Enter the hostname of the new diskless node (null entry to quit): "
else
	echo -n "Enter the hostname of the new cluster node (null entry to quit): "
endif
set NODE_NAME = ($<)
if ($#NODE_NAME == 0) then
	goto exit_point
endif

g_loop:
echo -n "Is "$NODE_NAME" a graphics station? (y or n) "
set GRAPHICS = ($<)
if ( ($GRAPHICS != y) && ($GRAPHICS != n)  ) then
	echo "  Please respond 'y' or 'n'"
	goto g_loop
endif


# set cluster/diskless node number

set NODE = `expr $NODE + 1`
#
# display delay message while composing single node entry
echo "Generating unique Internet address, please wait ..."
#
# set up local net entry for new node, assign next available address
#
## GENERATE UNIQUE NETWORK ADDRESS 
#
# read server network definition from /etc/hosts 
#
# 
# Make list in /tmp/admin of network entries to search for next avilable entry
#
awk '{print $1}' /etc/hosts | awk '{FS="."} {print $3"."$4}' >  /tmp/admin.$$

low_loop:
#
# Find unique case of $i.$j in the network entry list
#
fgrep -s $i"."$j /tmp/admin.$$
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 machine ID 
#
set MID = $j
/bin/rm -f /tmp/admin.$$

echo $NET_NUM".0."$i"."$MID"	"$NODE_NAME >> /tmp/hold
if ($?debug ) then
	echo contents of /tmp/hold:
	sed -e "s/^/	/" /tmp/hold
endif


if ($diskless == true) then
	set TYPE = dl
else
	set TYPE = vb
endif
#
# do file installations, with special cases for /etc/rc.local,
# /etc/ttytype, and /etc/ttys  if diskless node is graphics.
#
set FILES = `cat /usr/lib/admin.scripts/PRIVATE_FILES`
RHOST $NODE_NAME $FILES
#
    cp /usr/lib/admin.scripts/proto/rc.dl    /etc/.rc.$NODE_NAME
if ( $GRAPHICS == y ) then
    cp /usr/lib/admin.scripts/proto/rc.local.$TYPE.g /etc/.rc.local.$NODE_NAME
    cp /usr/lib/admin.scripts/proto/ttys.dl.g     /etc/.ttys.$NODE_NAME
    cp /usr/lib/admin.scripts/proto/ttytype.dl.g  /etc/.ttytype.$NODE_NAME
else
    cp /usr/lib/admin.scripts/proto/rc.local.$TYPE  /etc/.rc.local.$NODE_NAME
    cp /usr/lib/admin.scripts/proto/ttys.dl       /etc/.ttys.$NODE_NAME
    cp /usr/lib/admin.scripts/proto/ttytype.dl    /etc/.ttytype.$NODE_NAME
endif



#
#insert new entries into /etc/hosts
#

if ($diskless == true) then
	sed -e "/$SRV_ADDR/r /tmp/hold" /etc/hosts > /tmp/admin.$$
else
	grep -s $VB /etc/hosts
	if ($status == 0) then
		sed -e "/$VB/r /tmp/hold" /etc/hosts > /tmp/admin.$$
	else
		grep -s $SRV_NAME /etc/hosts
		if ($status == 0) then
			sed -e "/$SRV_NAME/r /tmp/hold" \
				/etc/hosts > /tmp/admin.$$
		else
			cat /etc/hosts /tmp/hold > /tmp/admin.$$
		endif
	endif
endif
if ( $?debug ) then
	echo replacing /etc/hosts
	echo type return when ready
	set dummy = ($<)
endif
mv /tmp/admin.$$ /etc/hosts
# remove temp files
chmod 664 /etc/hosts

if ($diskless == true) then
	set DEV = ex
else
	set DEV = vb
endif
#
#
echo "The boot  sequence for node $NODE_NAME is:"
echo "	$DEV(0,0)${SRV_NAME}:/vmunix HOST=$NODE_NAME MID=$MID SID=$SRV_MID"
#
#
# done with this guy, do it again
if ($NODE < 4 || $diskless == true) then
	cp /dev/null /tmp/hold
	goto new_node
endif

exit_point:

/bin/rm -f /tmp/hold
echo ""
echo ""
echo " Record this information and Press <return> when ready to continue."
set FOO = ($<)
@


1.8
log
@added crude error checks for selection of cluster net number
@
text
@a383 1
    /etc/ttytype /etc/utmp /usr/adm /usr/lib/crontab /usr/spool/rwho
@


1.7
log
@now gets list of private files from /usr/lib/admin.scripts/PRIVATE_FILES
@
text
@d94 1
a94 1
again00:
d100 1
a100 1
		goto again00
d102 22
d181 1
a181 1
again0:
d189 1
a189 1
			goto again0
d281 1
a281 1
again1:
d300 1
a300 1
		goto again1
@


1.6
log
@*** empty log message ***
@
text
@d360 2
a361 1
RHOST $NODE_NAME /tmp /usr/tmp /etc/rc /etc/rc.local /etc/ttys \
@


1.5
log
@in cluster mode, if server's name was not in host file, then /tmp/hold
never got in either.
@
text
@d49 1
a49 1
	echo - n "Type RETURN..."
d56 1
a56 1
	echo - n "Type RETURN..."
d80 1
@


1.4
log
@changed hosts.local to hosts in some test somewhere
@
text
@d373 2
d383 2
a384 2
	if ($status == 1) then
		sed -e "/$SRV_NAME/r /tmp/hold" /etc/hosts > /tmp/admin.$$
d386 7
a392 1
		sed -e "/$VB/r /tmp/hold" /etc/hosts > /tmp/admin.$$
@


1.3
log
@removed useless /tmp/ifconfigs$$ file
@
text
@d380 1
a380 1
	grep -s $VB /etc/hosts.local
@


1.2
log
@*** empty log message ***
@
text
@d64 1
a64 1
grep '^[ \t]*/etc/ifconfig' /etc/rc.local > /tmp/ifconfigs$$
d128 1
d249 1
a249 1
	ex /etc/rc.local << EOF
d267 1
a267 1
		ex /etc/rc.local << EOF
@


1.1
log
@Initial revision
@
text
@d22 4
a25 2
#	SRV_HID		hostid of server.
#	SRV_HID		hostid of diskless/cluster node
d40 3
d44 1
d49 1
a49 1
	echo "Type RETURN..."
a52 6
#
# Determine if host id has been set.
#
set SRV_HID = `awk '/^[ \t]*\/bin\/hostid/ {print $2}' /etc/rc.local`
if ( $?debug ) \
	echo SRV_HID = $SRV_HID
d56 1
a56 1
	echo "Type RETURN..."
d60 12
d73 8
a80 13
get_newhost:

echo " "
echo "Enter network address of server in the form: <Internet address> <hostname>"
set HOST = ($<)

# see if the entry is in /etc/hosts
set NET_ADDR = `echo $HOST | awk '{ print $1 }'`
set NET_HOST = `echo $HOST | awk '{ print $2 }'`
set HOSTS_ENTRY = "`grep $NET_ADDR /etc/hosts | grep $NET_HOST`"
if ($#HOSTS_ENTRY == 0) then
	echo "entry not in /etc/hosts, please put it there or try again"
	goto get_newhost
d83 11
a93 3
if ($diskless == true) then
	set NET_NUM = `echo $HOSTS_ENTRY | awk '{FS="."} {print $1}'`
else
d96 75
d172 7
a178 4
#
# Set machine id of server
#
set SRV_MID = `echo $NET_ADDR | awk '{FS="."} {print $4}'`
d180 1
d246 8
a253 8
grep -s bootd /etc/rc.local
if ($status == 1) then
ex /etc/rc.local << EOF > /dev/null
/talkd/
.-1
r /usr/lib/admin.scripts/proto/bootd_entry
w
q
d256 24
d343 4
d377 1
a377 1
	sed -e "/$HOSTS_ENTRY/r /tmp/hold" /etc/hosts > /tmp/admin.$$
d381 1
a381 1
		sed -e "/$HOSTS_ENTRY/r /tmp/hold" /etc/hosts > /tmp/admin.$$
d385 5
@
