#!/bin/sh
#
# Create customization for console server
# 	1) Edit root's bashrc file to contain path to $CONSBIN
#	2) Edit rc.local to start console server software on bootup
# All you should need to do is edit the CONSFILE variable
#

B="[1m"
N="[0m"
# 
# $CONSBIN is the location of the console server binary (conserver).
#
CONSBIN=/usr/farm/bin


update_bashrc() {
	file=/root/.bashrc
	echo "Updating your bashrc file -- adding $CONSBIN in path."
	if [ ! -f $file ]
	then
		touch $file
	fi
	cat <<- EOF >> $file
		#
		# Console server path
		#
		export PATH=\$PATH:/sbin:$CONSBIN
	EOF
}

update_rc.local () {
	file=/etc/rc.d/rc.local
	echo "Updating /etc/rc.d/rc.local file."
	grep "startserver" $file > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
	cat <<- EOF
		
		
		#################################################
		Looks like there's already a startserver entry in
		${B}$file${N}.  Please remove this entry if 
		it is in error and add the following instead:

		${B}
		#
		# Start console server software
		#
		${CONSBIN}/startserver
		${N}

		##################################################
	EOF
	echo ""
	echo -n "Press any key to continue"
	read a
	else
		cat <<- EOF >> $file
			#
			# Start console server software
			#
			${CONSBIN}/startserver
		EOF
	fi
	
}

send_update () {
	cat <<- EOF
	
	******************************************************************
	******************************************************************
	Now that this system is functional, you will need to do the 
	following:

	1) If this system is part of the FERMI CSS console server cluster,
	   you must update the master conserver.cf file and add this machine's
	   name to the list of trusted hosts.

	2) Edit the ${B}/usr/farm/bin/send2linux${N} file on the master console
	   server and add this machine's host name to the list of linux
	   console servers.
	******************************************************************
	******************************************************************


	Be sure to set your /root/.forward unless you plan to read mail
	from this machine directly.

	EOF
}
	   
	
install_sshd () {
	dir=/usr/farm/src/ssh-1.2.25
	cd $dir
	echo "Installing sshd..."
	sleep 2
	make install
	echo ""
	echo "Editting /etc/rc.d/rc.local to start sshd automatically."
	cat <<- EOF >> /etc/rc.d/rc.local	
			#
			# Start ssh server software
			#
			/usr/local/sbin/sshd
	EOF
        cat <<- EOF >> /etc/hosts.deny
	ALL: ALL
	EOF
	cat <<- EOF >> /etc/hosts.allow
	in.telnetd: ALL EXCEPT .fnal.gov  : twist /bin/echo "Noisy line.  Please check connection."
	in.ftpd: ALL EXCEPT .fnal.gov  : twist /bin/echo "Noisy line.  Please check connection."
	in.rshd: ALL EXCEPT .fnal.gov  : twist /bin/echo "Noisy line.  Please check connection."
	in.rlogind: ALL EXCEPT .fnal.gov  : twist /bin/echo "Noisy line.  Please check connection."
	in.rshd: fnop.fnal.gov
	EOF
}

create_motd () {
        cat <<- EOF >> /etc/motd

	###########################################################
	# This machine is to be used by FERMILAB employees only.  #
	# Unauthorized use of this machine is strictly prohibited #
	###########################################################


	EOF
}

update_cron () {
	echo ""
	echo "Editting crontab."
	crontab -l >> /usr/farm/bin/.crontab
	crontab /usr/farm/bin/.crontab
	echo "Crontab entry now looks like: "
	echo ""
	crontab -l
	echo ""
}

update_bashrc
update_rc.local
#install_sshd
echo "Updating /etc/services file"
grep "782/tcp" $file > /dev/null 2>&1
if [ $? -eq 0 ]
then
        echo "There is already a service for port 782.  Please make sure it is the"
        echo "console server port."
else
        echo "console         782/tcp conserver       #console server" >> /etc/services
fi
create_motd
send_update
update_cron
echo "Done."
echo ""
