#! /bin/csh -f

#################################################
#                                               #
#  Quartus Talkback Network  Install Script    	#
#                                               #
#  Copyright (c) Altera Corportation 2002		#
#  All Rights Reserved                          #
#                                               #
#################################################

# don't let CTRL-C stop this script from continuing
onintr -

if (! $?QUARTUS_ROOTDIR) then
	setenv SCRIPT_PATH `dirname $0`

	if ("${SCRIPT_PATH}" == "") then
        # in case the dirname doesn't work, use "which" (slower)
		setenv SCRIPT_PATH `which $0 |& tail -1`
	endif

	if ("${SCRIPT_PATH}" == "." || "${SCRIPT_PATH}" == "") then
		setenv QUARTUS_ROOTDIR `dirname $cwd`
	else 
		setenv QUARTUS_ROOTDIR `dirname ${SCRIPT_PATH}`
	endif

	if ("${QUARTUS_ROOTDIR}" == "..") then
		setenv QUARTUS_ROOTDIR `dirname $cwd`
	endif
endif

if ( "${QUARTUS_ROOTDIR}" !~ /* ) then
	setenv QUARTUS_ROOTDIR `(cd ${QUARTUS_ROOTDIR} ; pwd)`
endif

source ${QUARTUS_ROOTDIR}/adm/qenv.csh

if ($QENV_STATUS != 0) exit $QENV_STATUS

set os_type=`uname -s`
set os_version=`uname -r`

if ($os_type == "SunOS") then
	if ($os_version =~ 5.*) then
		# This is solaris 2.x
		set host_platform="solaris"
	else if ($os_version =~ 4.1.*) then
		echo "SunOS 4.x is not supported by this script"
		exit 1
	else
		# Unknown SunOS
        echo "Cannot determine whether operating system is compatibile"
        echo "with this installation script"
		exit 1
	endif

else if ($os_type == "HP-UX") then
	# This is an HP
	if ($os_version == B.11.00) then
		set host_platform="hp11"
	else if ($os_version == B.10.20) then
		set host_platform="hp"
	else
        echo "Cannot determine whether operating system is compatibile"
        echo "with this installation script"
		exit 1
	endif

else if ($os_type == "Linux") then
   	# This is a Linux box
   	set host_platform="linux"
	bindkey "^[[3~" delete-char
	set KBS=`tput kbs`
	if (${%KBS} == 1) then 
		stty erase $KBS
	endif

else
	# Unknown
        echo "Cannot determine whether operating system is compatibile"
        echo "with this installation script"
	exit 1

endif

start:

clear 
echo    ""
echo    "Quartus II Talkback Installation Script for UNIX Workstations"
echo    "Copyright (c) Altera Corporation 2002"
echo    ""
echo    "Type Ctrl+C <Return> to quit this installation script at any time." 
echo    ""
echo    "This installation script enables Talkback for all users accessing this installation"
echo    "of the Quartus II software.  You must agree to the Quartus Talkback license and"
echo    "legal disclosure to proceed."
echo    ""

echo "Press <Return> to continue..."
set foo=$<

if (! -w ${QUARTUS_ROOTDIR}/adm ) then
	echo "You must run this script as the administrator with write priviledges to the"
	echo "${QUARTUS_ROOTDIR} directory tree."
	echo ""
	exit 1
endif

cd ${QUARTUS_ROOTDIR}/adm
more qtb_license.txt

get_answer:

echo    ""
echo -n "Do you agree to these terms?  Type 'yes' if you agree, 'no' if you do not: "
set answer=$<

if ($answer =~ [Yy]*) then
	goto gather_info
endif

if ($answer =~ [Nn]*) then
	echo ""
	echo "Quartus Talkback Network Installation was not completed."
	exit 0
endif

echo ""
echo "You must either agree or disagree with the legal terms to continue."

goto get_answer

gather_info:

echo ""
echo "------------------------------------------------------------"
echo ""
echo "To enable Talkback for all users of this installation of"
echo "Quartus II, you will need to provide some information that can"
echo "be used to identify this installation."

echo ""
echo -n "Please specify an Altera ID if you have one: "

set altera_id=$<

echo ""
echo -n "Please specify the FAE name if available: "

set altera_fae=$<

set proxy=""

get_proxy:

echo    ""
echo    "Is a proxy server required to communicate with the Internet for users accessing"
echo -n "this installation of Quartus? (Y/n): "


set answer=$<

if ($answer =~ [Nn]*) then
	goto finish
endif

echo    ""
echo -n "Please specify the proxy host and port. (e.g http://proxy.mycompany.com:80): "
set proxy=$<

if ($proxy == "") then
	goto get_proxy
endif

finish:

echo "setenv QUARTUS_TALKBACK_ON 1" > ${QUARTUS_ROOTDIR}/adm/qtb.csh
if ($proxy != "") then
	echo "setenv QUARTUS_TALKBACK_PROXY $proxy" >> ${QUARTUS_ROOTDIR}/adm/qtb.csh
endif
if ($altera_fae != "") then
	echo "setenv QUARTUS_TALKBACK_FAE $altera_fae" >> ${QUARTUS_ROOTDIR}/adm/qtb.csh
endif
if ($altera_id != "") then
	echo "setenv QUARTUS_TALKBACK_ID $altera_id" >> ${QUARTUS_ROOTDIR}/adm/qtb.csh
endif

echo ""
echo "Quartus Talkback Network Installation complete."

exit
