#!/bin/csh
#  Quartus Workstation Install Script
#
#  Copyright (c) Altera Corportation 2006
#  All Rights Reserved
#
# Your use of Altera Corporation's design tools, logic functions and other 
# software and tools, and its AMPP partner logic functions, and any output files 
# any of the foregoing (including device programming or simulation files), and 
# any associated documentation or information are expressly subject to the terms 
# and conditions of the Altera Program License Subscription Agreement, Altera 
# MegaCore Function License Agreement, or other applicable license agreement, 
# including, without limitation, that your use is for the sole purpose of 
# programming logic devices manufactured by Altera and sold by Altera or its 
# authorized distributors.  Please refer to the applicable agreement for 
# further details.

unalias *

if ( $?QINST_VERBOSE ) then
	set expert_mode = 1
else
	set expert_mode = 0
endif

if ( $?QINST_DEBUG ) then
	set debug = 1
else
	set debug = 0
endif

if ( $?QINST_AUTO ) then
	set auto_install = 1
else
	set auto_install = 0
endif

if (! $?TMP) then
	setenv TMP /tmp
endif

set display_help=0
set custom_install=0
set families_flag=0
set all_families_flag=0
set device_archives=""
set product_version="6.0"
set product_name="Quartus II"
set copyright="Copyright (c) Altera Corporation 2006"
set install_log="install_${product_version}_log.txt"

start_install:

check_arguments:

set arg_counter=0

# check all arguments
if ($#argv > 0) then
	while ($arg_counter <= $#argv)
		if ("$argv[$arg_counter]" == "--auto") then
			set auto_install=1

			if ($arg_counter != $#argv) then
				set next = `expr $arg_counter + 1`
				if ("$argv[$next]" =~ --*) then
					echo "The '--auto' flag must have a target directory specified."
					exit 1
			    endif
			else if ($arg_counter == $#argv) then
 	   			echo "The '--auto' flag must have a target directory specified."
				exit 1
			endif
		else if ("$argv[$arg_counter]" == "--help") then
			set display_help=1
		else if ("$argv[$arg_counter]" == "--all") then
			set all_families_flag=1
		else if ("$argv[$arg_counter]" == "--families") then
			set custom_install=1
			set families_flag=1

			# all following arguments identify the familes to be installed until 
			# the next argument starting with '--' or the end
			set arg_counter = `expr $arg_counter + 1`

			while ($arg_counter <= $#argv && "$argv[$arg_counter]" !~ --*)
				set device_archives="$argv[$arg_counter] $device_archives"
				set arg_counter = `expr $arg_counter + 1`

				# If last arg processed, break out of loop
				if ($arg_counter > $#argv) then
					set arg_counter = `expr $arg_counter - 1`
					break
				endif
			end

			if ("$argv[$arg_counter]" =~ --*) then
				set arg_counter = `expr $arg_counter - 1`
			endif
		else if ("$argv[$arg_counter]" != "") then
			set default_install=$argv[$arg_counter];
		else
			set default_install=/opt/altera/quartus$product_version
		endif

		set arg_counter = `expr $arg_counter + 1`
	end
else
	set default_install=/opt/altera/quartus$product_version
endif
			
set curr_dir=`pwd`
set banner = "$product_name $product_version Installation Script for UNIX Workstations"

# Determine cd directory

set script_path = `dirname $0`

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

if ("${script_path}" == "." || "${script_path}" == "") then
	set script_path = `pwd`
endif

if ($script_path !~ /*) then
	set script_path = `pwd`/$script_path
endif

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

# Next check to see what system this is
if ($os_type == "SunOS") then
	if ($os_version =~ 5.*) then
		# This is solaris 2.x
		set host_platform="solaris"
		set df_command = /usr/ucb/df
		set whoami_command = /usr/ucb/whoami
		@ df_offset = 2
	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
	set host_platform="hp11"
	set df_command = /usr/bin/bdf
	set whoami_command = /usr/bin/whoami
	@ df_offset = 2
else if ($os_type == "AIX") then
	# This is an RS/6000
	set host_platform="rs6000"
	set df_command = /usr/bin/df
	@ df_offset = 4
else if ($os_type == "Linux") then
   	# This is a Linux box
   	set host_platform="linux"
   	set whoami_command = /usr/bin/whoami
    set df_command = /bin/df
	bindkey "^[[3~" delete-char
	set KBS=`tput kbs`
	if ( (${%KBS} == 1) && ! $auto_install) then 
		stty erase $KBS
	endif
    @ df_offset = 2
else
	# Unknown
	echo "Cannot determine whether operating system is compatibile"
	echo "with this installation script"
	exit 1
endif

set default_mount_dir=$script_path

clear 
if ( $auto_install ) echo "Running automated install"

set mount_dir=$default_mount_dir

goto check_mount_directory

get_mount_directory:

echo    ""
echo    "Type the full pathname of the directory where this Quartus II"
echo -n "CD-ROM is mounted (default: $default_mount_dir): "
set mount_dir=$<

if ($mount_dir == "") then
	set mount_dir=$default_mount_dir
endif

if (! -d $mount_dir) then
	echo ""
	echo "Sorry, '$mount_dir' is not a valid directory name"
	goto get_mount_directory
endif

check_mount_directory:

set disk_type = ""
set ext="gz"
if ( -f $mount_dir/solaris.$ext || -f $mount_dir/solaris64.$ext ) then
	set disk_type = "solaris"
else if ( -f $mount_dir/hp11.$ext ) then
	set disk_type = "hp11"
else if ( -f $mount_dir/linux.$ext || -f $mount_dir/linux64.$ext) then
	set disk_type = "linux"
else if ( -f $mount_dir/devinfo.$ext ) then
	set disk_type = "common"
else
	echo "$mount_dir is not a valid Quartus II cdrom image."
	goto get_mount_directory
endif

# always use gzip & gtar, look for platform specific tools provided on CD
set uncompress_cmd="${mount_dir}/tools/${host_platform}/gzip -c -d"
set untar_cmd="${mount_dir}/tools/${host_platform}/gtar xoUf -"
set default_mount_dir = $mount_dir

# Usage & help
if ( $display_help ) then
	echo    ""
	echo    $banner
	echo    $copyright
	echo    ""
	if (-f "$mount_dir/dev_info.txt" || $disk_type == "common") then
		echo    "Usage: install [--all] [--families <list of families>] [--auto <target directory>]"
	else
		echo    "Usage: install [--auto <target directory>]"
	endif
	echo    ""
	if ( -f "$mount_dir/dev_info.txt" ) then
		echo "You may install any or all of the following Altera device families:"
		echo ""
		echo "Enter this:                            Family Name     Size (kbytes)"
		echo "-----------               ------------------------     -------------"
		cat $mount_dir/dev_info.txt | awk -F":" '{ printf "%10s     %35s     %sk\n", $2, $1, $3 }' 
		echo ""
	endif

	exit
endif

# reset flags
if ( $disk_type != common ) then
	set families_flag=0
	set all_families_flag=0
	set custom_install=0
endif

start:

echo    ""
echo    $banner
echo    $copyright
echo    ""
echo    "Type Ctrl+C <Return> to quit this installation script at any time." 
echo    ""
if ($disk_type != common) then
	echo    "Use this installation script to install the Quartus II software,"
	echo    "including sample/tutorial files and interfaces to other EDA tools."
else
	echo    "Use this installation script to install the Quartus II device information"
	echo    "for all device families."
endif
echo ""
if ( $all_families_flag == 1 || $families_flag == 1 || $disk_type != common ) then
	echo -n "Press <Return> to continue installation: "
	if ( ! $auto_install ) then
		set foo=$<
	endif	

	goto get_install_directory
   	echo ""
else
	echo    "Press <Return> to continue normal installation or type <s>"
	echo -n "to select the components to install: "
	if ( ! $auto_install ) then
		set foo=$<
		if ($foo =~ [Ss]*) then
			set custom_install=1
			echo ""
			echo "Custom install selected ..."
		endif
	else
		echo ""
	endif
endif

get_install_directory:

set install_dir=""
echo    ""
if ($disk_type != "common") then
	echo    "Type the full pathname of the directory where you want to"
	echo	"install the Quartus II $product_version software."
else
	echo    "Type the full pathname of the directory where you have"
	echo	"already installed the Quartus II $product_version software."
endif
echo    ""
echo -n "(default: $default_install): "
if (! $auto_install) then
	set install_dir=$<
endif
if ($install_dir == "") then
	set install_dir=$default_install
endif
if (-d $install_dir) then
	if ((! -w $install_dir) || (! -x $install_dir)) then
		echo ""
		echo "Sorry, you do not have access to the '$install_dir' directory"
		if ($auto_install) then
			exit 1
		else
			goto get_install_directory
		endif
	endif
	if ( -f $install_dir/bin/quartus_sh ) then
		if ( $disk_type != "common") then
			set answer=""
			while ($answer !~ [Yy]* && $answer !~ [Nn]*)
				echo ""
				echo "An installation of Quartus II already exists in '$install_dir'"
				echo -n "Do you want to remove it before installing Quartus II $product_version? (y/n): "
				if ( ! $auto_install ) then
					set answer=$<
				else
					set answer="n"
					echo ""
				endif
			end
			if ($answer =~ [Yy]*) then
				echo ""
				echo "Removing all files in '$install_dir'"
				rm -rf $install_dir/*
			endif
		endif
   else
		if ( $disk_type != "common") then
			set answer=""
			while ($answer !~ [Yy]* && $answer !~ [Nn]*)
				echo    ""
				echo    "The $install_dir directory already exists."
				echo    "OK to delete all existing files in $install_dir before"
				echo -n "installing Quartus II $product_version? (y/n): "
				if ( ! $auto_install ) then
					set answer=$<
				else
					set answer="n"
					echo ""
				endif
			end
			if ($answer =~ [Yy]*) then
				echo ""
				echo "Removing all files in '$install_dir'"
				rm -rf $install_dir/* >&/dev/null
			endif
		else
			echo "You must provide a path to an existing Quartus II $product_version"
			echo "installation"
			if ( $auto_install ) then
				exit 1
 			else
				goto get_install_directory
			endif
		endif
   endif
else
	if ( $disk_type != "common") then
		if (! { mkdir $install_dir } ) then
			echo ""
			echo "Cannot create the '$install_dir' directory"
			if ( $auto_install ) then
				exit 1
			else
				goto get_install_directory
			endif
		endif
	else
		echo "You must provide a path to an existing Quartus II $product_version"
		echo "installation"
		goto get_install_directory
	endif
endif	

set default_install="$install_dir"
set all_device_archives=""

if ( -f "$mount_dir/dev_info.txt" ) then
	cat $mount_dir/dev_info.txt | awk -F":" '{ print $2 }' > ${TMP}/qinst_$$.tmp
	set all_device_archives=`cat ${TMP}/qinst_$$.tmp | sort | uniq`
	rm -f ${TMP}/qinst_$$.tmp
endif

set devices_space=0
if ($all_families_flag) set device_archives="$all_device_archives"

# Display custom install options
if ( $custom_install && -f "$mount_dir/dev_info.txt" ) then
	
	if ( $families_flag == 1 ) then
		goto display_selected_device_families
	endif
	
	display_device_families:
	echo "You may install any or all of the following Altera device families:"
	echo ""
	echo "Enter this:                            Family Name     Size (kbytes)"
	echo "-----------               ------------------------     -------------"
	echo "       sii                              Stratix II     119520k"
	cat $mount_dir/dev_info.txt | awk -F":" '{ printf "%10s     %35s     %sk\n", $2, $1, $3 }' 
	echo ""
	echo "Enter one or more of the families listed above (example: stx cyc)"
   	echo -n "(default: all): "

	if ( ! $auto_install ) then
		set answer="$<"
		if ("$answer" == "") then
			set device_archives="$all_device_archives"
		else if ("$answer" =~ [Aa]ll) then
			set device_archives="$all_device_archives"
	    else
			set device_archives="$answer"
		endif
	else
		if ("$device_archives" == "") then
			set device_archives="$all_device_archives"
		endif
		echo ""
	endif

	display_selected_device_families:
	set entry=""
	set answer=""
	set devices_space=0
	set filtered_archives=""
	while ("$answer" !~ [YyNn]*)
		echo    ""
   		echo    "You have chosen to install the following Altera device families:"
		echo    ""
		echo    "------------------------------------------------------------"
		echo    ""
		echo    "                         Stratix II     119520k"
		foreach entry ($device_archives)
			if ( -f "${mount_dir}/${entry}.$ext" ) then
				cat $mount_dir/dev_info.txt | grep ":${entry}:" | awk -F":" '{ printf "%35s     %sk\n", $1, $3 }'
				set size=`cat $mount_dir/dev_info.txt | grep ":${entry}:" | awk -F":" '{ print $3 }'`
				set devices_space=`expr $devices_space + $size`
				set filtered_archives="$filtered_archives $entry"
			endif
		end
		echo    ""
		echo    "------------------------------------------------------------"		
		echo    ""
		set device_archives="$filtered_archives"
		set devices_space=`expr $devices_space + 119520`
		echo    "Total size: $devices_space kbytes"
		echo    ""
		echo -n "Do you want to proceed with this selection (y/n): "

		set families_flag=0
   		if ( ! $auto_install ) then
   			set answer=$<
   		else
   			set answer="y"
   			echo ""
   		endif
    end

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

else
	# assume all device archives are to be installed.
	set device_archives="$all_device_archives"
endif

# Perform the installation

echo ""
echo "------------------------------------------------------------"
echo ""
echo "Calculating disk space requirements..."

@ common_req_space = `grep common $mount_dir/space.txt | awk '{printf $2}'`
@ required_space = `grep "$disk_type " $mount_dir/space.txt | awk '{printf $2}'`

if ($devices_space == 0) then
	@ required_space = `expr $required_space + $common_req_space`
else
	@ required_space = `expr $required_space + $devices_space`
endif

if (($required_space != "") && ($required_space != 0)) then
	echo ""
	echo "The requested installation requires $required_space kbytes."
	set df_result = `$df_command $install_dir | tail +2`
	set diskspace = `echo $df_result | awk '{n = split($0,a); printf a[n-offset]}' offset=$df_offset`
	if ("$diskspace" == "" || $diskspace =~ *[A-Za-df-z]*) then
		echo ""
		echo "------------------------------------------------------------"
		echo ""
		echo "Unable to determine disk space available in $install_dir."
		echo "Please verify that you have at least $required_space kbytes"
		echo "available in $install_dir, otherwise this installation"
		echo "will fail."
		echo ""
		set answer=""
		while ($answer !~ [YyNn]*)
			echo    "Is there at least $required_space kbytes available in"
			echo -n "$install_dir (type n to stop this installation)? (y/n): "
			set answer=$<
		end
		if ($answer =~ [Nn]*) then
			set answer=""
			while ($answer !~ [YyNn]*)
				echo -n "Would you like to restart the installation? (y/n): "
				set answer=$<
			end
			if ($answer =~ [Yy]*) then
				goto get_mount_directory
			else
				echo ""
				echo "Exiting Quartus II UNIX Workstation Installation...."
				echo ""
				exit 1
			endif
		else
			set diskspace=$required_space
		endif
	endif
	${mount_dir}/tools/${host_platform}/compare $required_space $diskspace
	if ($status != 2) then
		echo ""
		echo "------------------------------------------------------------"
		echo ""
		echo "You do not have enough disk space to install the requested items."
		echo "There are only $diskspace kbytes in $install_dir."
		echo ""
		
		set answer=""
		while ($answer !~ [YyNn]*)
			echo -n "Would you like to restart the installation? (y/n): "
			set answer=$<
		end

		if ($answer =~ [Yy]*) then
			goto get_mount_directory
		else
			echo ""
			echo "Exiting Quartus II UNIX Workstation Installation...."
			echo ""
			exit 1
		endif
	endif
	echo ""
	echo "------------------------------------------------------------"
else
	echo ""
	echo "------------------------------------------------------------"
	echo ""
	echo "Unable to determine the disk space necessary to install Quartus II."
	echo "Please verify that you have sufficient disk space in "
	echo "$install_dir, otherwise this installation will fail."
	echo -n "Press <Return> to continue..."
	if ( ! $auto_install ) then
		set foo=$<
	endif
endif

echo ""
cd $install_dir

# Start installation log
if ( $disk_type != "common") then
	if (-f "${install_dir}/$install_log") then
		rm -f "${install_dir}/$install_log" >& /dev/null
	else
		echo "" > $install_log
	endif
endif
echo "Install Log Quartus II $product_version" >> $install_log
echo "$copyright" >> $install_log
echo `date` >> $install_log
echo "Disk type: $disk_type" >> $install_log
echo "whoami: `$whoami_command`" >> $install_log
echo "uname -s: $os_type" >> $install_log
echo "uname -r: $os_version" >> $install_log
echo "uncompress_cmd: $uncompress_cmd" >> $install_log
echo "untar_cmd: $untar_cmd" >> $install_log
echo "" >> $install_log
echo "Installing from '$mount_dir' to '$install_dir'" >> $install_log

if ( -f $mount_dir/stub.csh ) then
	if ( ! -d ./bin ) then
		mkdir ./bin
	endif

	echo "Creating wrapper shell scripts in the '$install_dir/bin' directory..."
	echo "Creating wrapper shell scripts in the '$install_dir/bin' directory" >> $install_log

	cp -f $mount_dir/stub.csh ./bin/quartus
	cp -f $mount_dir/stub.csh ./bin/quartus_cmd
	cp -f $mount_dir/stub.csh ./bin/qmegawiz
	cp -f $mount_dir/stub.csh ./bin/genmem
	cp -f $mount_dir/stub.csh ./bin/tclsh
	cp -f $mount_dir/stub.csh ./bin/mwcleanup
	cp -f $mount_dir/stub.csh ./bin/mwcontrol
	cp -f $mount_dir/stub.csh ./bin/makeprogfile
	cp -f $mount_dir/stub.csh ./bin/exc_bus_translate
	cp -f $mount_dir/stub.csh ./bin/exc_flash_programmer
	cp -f $mount_dir/stub.csh ./bin/memimagedecoder
	cp -f $mount_dir/stub.csh ./bin/excalibursbdtocode
	cp -f $mount_dir/stub.csh ./bin/jtagd
	cp -f $mount_dir/stub.csh ./bin/jtagconfig
	cp -f $mount_dir/stub.csh ./bin/bin2elf
	cp -f $mount_dir/stub.csh ./bin/hex2rif
	cp -f $mount_dir/stub.csh ./bin/mif2rif
	cp -f $mount_dir/stub.csh ./bin/mif2hex
	cp -f $mount_dir/stub.csh ./bin/hh
	if ($disk_type == "solaris") then
		cp -f $mount_dir/stub.csh ./bin/qtb_install
		cp -f $mount_dir/stub.csh ./bin/ess
	endif
	if ($disk_type == "hp11") then
		cp -f $mount_dir/stub.csh ./bin/ess
	endif
	if ($disk_type == "linux") then
		cp -f $mount_dir/stub.csh ./bin/qtb_install
	endif
	cp -f $mount_dir/stub.csh ./bin/sbi_config
	cp -f $mount_dir/stub.csh ./bin/quartus_map
	cp -f $mount_dir/stub.csh ./bin/quartus_fit
	cp -f $mount_dir/stub.csh ./bin/quartus_tan
	cp -f $mount_dir/stub.csh ./bin/quartus_asm
	cp -f $mount_dir/stub.csh ./bin/quartus_eda
	cp -f $mount_dir/stub.csh ./bin/quartus_cdb
	cp -f $mount_dir/stub.csh ./bin/quartus_sh
	cp -f $mount_dir/stub.csh ./bin/quartus_cpf
	cp -f $mount_dir/stub.csh ./bin/quartus_pgm
	cp -f $mount_dir/stub.csh ./bin/quartus_sim
	cp -f $mount_dir/stub.csh ./bin/quartus_swb
	cp -f $mount_dir/stub.csh ./bin/quartus_stp
	cp -f $mount_dir/stub.csh ./bin/quartus_sta
	cp -f $mount_dir/stub.csh ./bin/quartus_staw
	cp -f $mount_dir/stub.csh ./bin/quartus_drc
	cp -f $mount_dir/stub.csh ./bin/quartus_g2b
	cp -f $mount_dir/stub.csh ./bin/quartus_rpp
	cp -f $mount_dir/stub.csh ./bin/quartus_pow	
	cp -f $mount_dir/stub.csh ./bin/quartus_jli
	cp -f $mount_dir/stub.csh ./bin/qcmd
	cp -f $mount_dir/stub.csh ./bin/clearbox
	cp -f $mount_dir/stub.csh ./bin/dmf_ver
	chmod 555 ./bin/*
endif

if ( -f $mount_dir/adm.$ext ) then
	echo "Installing contents of 'adm.$ext' to the '$install_dir/adm' directory..."
	echo "Installing contents of 'adm.$ext' to the '$install_dir/adm' directory..." >> $install_log
	cat $mount_dir/adm.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/solaris.$ext ) then
	echo "Installing contents of 'solaris.$ext' to the '$install_dir/solaris' directory..."
	echo "Installing contents of 'solaris.$ext' to the '$install_dir/solaris' directory..." >> $install_log
	cat $mount_dir/solaris.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/solaris64.$ext ) then
	echo "Installing contents of 'solaris64.$ext' to the '$install_dir/solaris64' directory..."
	echo "Installing contents of 'solaris64.$ext' to the '$install_dir/solaris64' directory..." >> $install_log
	cat $mount_dir/solaris64.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/hp11.$ext ) then
	echo "Installing contents of 'hp11.$ext' to the '$install_dir/hp11' directory..."
	echo "Installing contents of 'hp11.$ext' to the '$install_dir/hp11' directory..." >> $install_log
	cat $mount_dir/hp11.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/linux.$ext ) then
	echo "Installing contents of 'linux.$ext' to the '$install_dir/linux' directory..."
	echo "Installing contents of 'linux.$ext' to the '$install_dir/linux' directory..." >> $install_log
	cat $mount_dir/linux.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/linux64.$ext ) then
	echo "Installing contents of 'linux64.$ext' to the '$install_dir/linux64' directory..."
	echo "Installing contents of 'linux64.$ext' to the '$install_dir/linux64' directory..." >> $install_log
	cat $mount_dir/linux64.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

foreach archive ($device_archives)
	if ( -f ${mount_dir}/${archive}.${ext} ) then
		echo "Installing contents of '${archive}.${ext}' to the '${install_dir}/common' directory..."
		echo "Installing contents of '${archive}.${ext}' to the '${install_dir}/common' directory..." >> $install_log
		cat ${mount_dir}/${archive}.${ext} | $uncompress_cmd | $untar_cmd >> $install_log
	endif
end

if ( -f $mount_dir/qdesigns.$ext ) then
	echo "Installing contents of 'qdesigns.$ext' to the '$install_dir/qdesigns' directory..."
	echo "Installing contents of 'qdesigns.$ext' to the '$install_dir/qdesigns' directory..." >> $install_log
	rm -rf ./qdesigns/fir_filter ./qdesigns/tutorial >&/dev/null
	cat $mount_dir/qdesigns.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/libs.$ext ) then
	echo "Installing contents of 'libs.$ext' to the '$install_dir/libraries' directory..."
	echo "Installing contents of 'libs.$ext' to the '$install_dir/libraries' directory..." >> $install_log
	cat $mount_dir/libs.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/lmf.$ext ) then
	echo "Installing contents of 'lmf.$ext' to the '$install_dir/lmf' directory..."
	echo "Installing contents of 'lmf.$ext' to the '$install_dir/lmf' directory..." >> $install_log
	cat $mount_dir/lmf.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/eda.$ext ) then
	echo "Installing contents of 'eda.$ext' to the '$install_dir/eda' directory..."
	echo "Installing contents of 'eda.$ext' to the '$install_dir/eda' directory..." >> $install_log
	cat $mount_dir/eda.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/tcl.$ext ) then
	echo "Installing contents of 'tcl.$ext' to the '$install_dir/tcl' directory..."
	echo "Installing contents of 'tcl.$ext' to the '$install_dir/tcl' directory..." >> $install_log
	cat $mount_dir/tcl.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/mw.$ext ) then
	echo "Installing contents of 'mw.$ext' to the '$install_dir/mw' directory..."
	echo "Installing contents of 'mw.$ext' to the '$install_dir/mw' directory..." >> $install_log
	cat $mount_dir/mw.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/hh.$ext ) then
	echo "Installing contents of 'hh.$ext' to the '$install_dir/hh' directory..."
	echo "Installing contents of 'hh.$ext' to the '$install_dir/hh' directory..." >> $install_log
	cat $mount_dir/hh.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/obj_stud.$ext ) then
	echo "Installing contents of 'obj_stud.$ext' to the '$install_dir/objective_studio' directory..."
	echo "Installing contents of 'obj_stud.$ext' to the '$install_dir/objective_studio' directory..." >> $install_log
	cat $mount_dir/obj_stud.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/sopc.$ext ) then
	echo "Installing contents of 'sopc.$ext' to the '$install_dir/sopc_builder' directory..."
	echo "Installing contents of 'sopc.$ext' to the '$install_dir/sopc_builder' directory..." >> $install_log
	cat $mount_dir/sopc.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/cusp.$ext ) then
	echo "Installing contents of 'cusp.$ext' to the '$install_dir/cusp' directory..."
	echo "Installing contents of 'cusp.$ext' to the '$install_dir/cusp' directory..." >> $install_log
	cat $mount_dir/cusp.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/common.$ext ) then
	echo "Installing contents of 'common.$ext' to the '$install_dir' directory..."
	echo "Installing contents of 'common.$ext' to the '$install_dir' directory..." >> $install_log
	cat $mount_dir/common.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/devinfo.$ext ) then
	echo "Installing contents of 'devinfo.$ext' to the '$install_dir' directory..."
	echo "Installing contents of 'devinfo.$ext' to the '$install_dir' directory..." >> $install_log
	cat $mount_dir/devinfo.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

if ( -f $mount_dir/sii.$ext ) then
	echo "Installing contents of 'sii.$ext' to the '$install_dir' directory..."
	echo "Installing contents of 'sii.$ext' to the '$install_dir' directory..." >> $install_log
	cat $mount_dir/sii.$ext | $uncompress_cmd | $untar_cmd >> $install_log
endif

set txt_files="readme.txt license.txt megacore.txt"

foreach file ($txt_files)
	if ( -f $mount_dir/$file ) then
		cp -f $mount_dir/$file .
	endif
end

if ( -d ./devices ) then
	if ( -d ./solaris ) then
		cd solaris
		ln -s ../devices .
		cd ..
	endif
	if ( -d ./solaris64 ) then
		cd solaris64
		ln -s ../devices .
		cd ..
	endif
	if ( -d ./hp11 ) then
		cd hp11
		ln -s ../devices .
		cd ..
	endif
	if ( -d ./linux ) then
		cd linux
		ln -s ../devices .
		cd ..
	endif
	if ( -d ./linux64 ) then
		cd linux64
		ln -s ../devices .
		cd ..
	endif
endif

echo "" >> $install_log
echo "Removing ${install_dir}/bin/quartus_patch_log.txt" >> $install_log
echo "" >> $install_log
rm -f $install_dir/bin/quartus_patch_log.txt >& /dev/null

# sopc_builder_wizard_lst
if ( $disk_type != "common") then
	cd $curr_dir
	if ( -f $install_dir/libraries/megafunctions/sopc_builder_wizard.lst ) then
		rm -f $install_dir/libraries/megafunctions/sopc_builder_wizard.lst
	endif
	echo "[]" > $install_dir/libraries/megafunctions/sopc_builder_wizard.lst
	echo 'Altera SOPC Builder = '${install_dir}'/'${disk_type}'/perl561/bin/perl -x '$install_dir'/sopc_builder/bin/sopc_builder %f -d'${install_dir}'/sopc_builder %o %h<INFO><ALIAS SELECTABLE="YES">Altera SOPC Builder 2.6</ALIAS><ALIAS SELECTABLE="YES">Altera SOPC Builder 2.7</ALIAS><ALIAS SELECTABLE="YES">Altera SOPC Builder 2.8</ALIAS></INFO>' >> $install_dir/libraries/megafunctions/sopc_builder_wizard.lst
	
	# .sopc_builder
	echo "# .sopc_builder configuration file:" > $install_dir/sopc_builder/.sopc_builder
	echo 'sopc_builder = "'$install_dir'/sopc_builder";' >> $install_dir/sopc_builder/.sopc_builder
	echo 'sopc_legacy_dir = "";' >> $install_dir/sopc_builder/.sopc_builder
	echo 'sopc_quartus_dir = "'$install_dir'/";' >> $install_dir/sopc_builder/.sopc_builder
	echo 'sopc_modelsim_dir = "";' >> $install_dir/sopc_builder/.sopc_builder
	echo 'sopc_ui_debug = "0";' >> $install_dir/sopc_builder/.sopc_builder
endif

echo ""
if ( $disk_type != "common") then
	echo "*** You must install the Quartus II Device Information for UNIX & Linux"
   	echo "    Workstations CD-ROM in order to begin using the Quartus II software"
	echo "    for this platform ($disk_type).  Please mount the Quartus II Device"
	echo "    Information for UNIX & Linux Workstations CD-ROM and run 'install'"
	echo "    before continuing."
	echo ""
	echo "Installation of $product_name $disk_type platform completed."
else
	echo "For information about completing the setup of the Quartus II software and"
	echo "configuring licensing, please check the Quartus II Installation and"
	echo "Licensing for UNIX and Linux Workstations Manual on the Altera website at"
	echo "http://www.altera.com/literature/manual/quartus_unix.pdf"
	echo ""
	echo "Installation of Quartus II Device Information for UNIX & Linux "
	echo "Workstations is complete.  You can now run the Quartus II software."
endif

cd $install_dir
echo "Installation of disk type '$disk_type' completed (`date`)." >> $install_log
