#!/bin/ksh -p
# $Id$
#

# Explorer Version:
EXP_VERSION=4.0

# Get and set the EXP_HOME and EXP_LIB variables
#
DIR=${0%/*}
if [ "${DIR}" = "/usr/sbin" ]
then
    EXP_HOME="/"
    EXP_LIB="/usr/lib/explorer"
    EXP_DEFAULTS="/etc/default/explorer"
else
    # Make DIR absolute path
    if [ `echo ${DIR} | cut -c1` != "/" ]
    then
        DIR=`pwd`
    fi
    EXP_HOME=${DIR%/*}
    EXP_LIB="${EXP_HOME}/lib"
#    EXP_DEFAULTS="${EXP_HOME}/etc/default/explorer"
    EXP_DEFAULTS="${EXP_ETC}/default/explorer"
fi

# Source tools functions
. ${EXP_LIB}/exp_tools

# Source sunone functions
. ${EXP_LIB}/exp_sunone

# Function definitions first.

# initialize the variables that are used throughout the script
typeset -i i=0
typeset -i CONFIG_CHANGED=0

ANSWER=""
DIR_ENTRY=""
EDIT_CONFIG=""
EDITOR=""
ENTRY=""
INST=""
INSTALLED=""
RESPONSE=""
RESPONSE2=""
SR=""
SR_GOOD=""
TEXT=""
VAR=""

aelvx () {

    while :
    do
	screen_footer

        # Read response
        read RESPONSE

	# convert to lowercase
	typeset -l ${ANSWER}

        # Acceptable responses are a|add|e|edit|l|list|v|validate|x|exit
        case "${RESPONSE}" in
            add | a)
                RESPONSE=add
                break
                ;;
            edit | e)
                RESPONSE=edit
                break
                ;;
            list | l)
                RESPONSE=list
                break
                ;;
            validate | v)
		RESPONSE=val
		break
		;;	
	    exit | x)
		RESPONSE=exit
		break
		;;
            *)
                print "Please answer a, add, e, edit, l, list, v, validate, or x, or exit"
                continue
                ;;
        esac
    done

    # Set variable
    eval $1=${RESPONSE}
}

validate_sr () {

	(( v_pos = 11 ))
	(( h_pos = 0 ))
	position_cursor
	clear_below
	# Validate the server root just entered.
	if [[ -z ${SR} ]]
	then
		TEXT="You did not enter anything, do you want to exit?"
		line_length=`print ${#TEXT}`
#		vert_center
		horiz_center
		(( h_pos = h_pos - 4 ))
		position_cursor
		yorn RESPONSE "${TEXT} \c"
		if [[ "${RESPONSE}" == yes ]]
		then
			exit 1
		else
			(( h_pos = 0 ))
			position_cursor
			clear_line
			continue
		fi
	else
		if [[ ! -d ${SR} ]]
		then
			TEXT="The server root you entered is invalid!"
			line_length=`print ${#TEXT}`
#			vert_center
			horiz_center
			position_cursor
			print "${TEXT}"
			TEXT="Do you wish to try again?"
			line_length=`print ${#TEXT}`
#			vert_center
			horiz_center
			(( h_pos = h_pos - 4 ))
			line_increment 1
			position_cursor
			yorn RESPONSE "${TEXT} \c"
			if [[ "${RESPONSE}" == yes ]]
			then
				TEXT="Enter the server root that you would like to add to the configuration file:"
				line_length=`print ${#TEXT}`
				(( h_pos = 0 ))
				line_decrement 2
				position_cursor
				clear_below
				line_increment 2
				position_cursor
				print "${TEXT}"
				line_increment 1
				(( h_pos = 0 ))
				position_cursor
				read SR
				validate_sr ${SR}	
			else
				exit
			fi
		else
			# Check to see if the server root entered already exists in the config file
			IFS="="
			i=0
			while (( ${i} < ${#i_array[*]} ))
			do
				if [[ ${i_array[${i}]} == ${SR} ]]
				then
					TEXT="That server root already exists in the config file!"
					line_length=`print ${#TEXT}`
					vert_center
					horiz_center
					position_cursor
					print "${TEXT}"
					line_increment 1
					position_cursor
					TEXT="Press \"Return\" to continue: "
					print "${TEXT}\c"
					read JUNK
					return 1
				fi
			(( i = i + 1 ))
			done
		fi
	fi

	if [[ NOT_FOUND == 0 ]]
	then
		TEXT="The server root entered appears to be valid!"
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		position_cursor
		print "${TEXT}"
		CONFIG_CHANGED=1
	fi
}

validate_inst () {

	(( v_pos = 1 ))
	(( h_pos = 0 ))
	position_cursor
	clear_below
	screen_footer
	# Validate the instance just entered.
	if [[ -z ${INST} ]]
	then
		TEXT="You did not enter anything, do you want to exit?"
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		position_cursor
		print ${TEXT}
		yorn RESPONSE "${TEXT} \c"
		if [[ "${RESPONSE}" == yes ]]
		then
			exit 1
		else
			continue
		fi
	else
		if [[ ! -d ${INST} ]]
		then
			TEXT="The instance you entered is invalid!"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			line_decrement 2
			position_cursor
			print "${TEXT}"
			TEXT="Do you wish to try again?"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			line_increment 1
			(( h_pos = h_pos - 4 ))
			position_cursor
			yorn RESPONSE "${TEXT} \c"
			if [[ "${RESPONSE}" == yes ]]
			then
				(( v_pos = 1 ))
				(( h_pos = 0 ))
				position_cursor
				clear_below
				screen_footer
				TEXT="Enter the instance that you would like to add to the configure file:"
				line_length=`print ${#TEXT}`
				vert_center
				horiz_center
				line_increment 2
				position_cursor
				print "${TEXT}"
				line_increment 1
				(( h_pos = 0 ))
				positon_cursor
				read INST
				validate_inst ${INST}	
			else
				exit
			fi
		else
			# Check to see if the instance is already in the config file
			i=0
			while (( ${i} < ${#i_array[*]} ))
			do
				if [[ ${SR} == ${i_array[${i}]} ]]
				then
					(( i = i + 1 ))
					while [[ ${i_array[${i}]} != "" ]]
					do
						if [[ ${INST} == ${i_array[${i}]} ]]
						then
							(( v_pos = 1 ))
							(( h_pos = 0 ))
							position_cursor
							clear_below
							screen_footer
							TEXT="This instance, ${INST} is already in the config file!"
							line_length=`print ${#TEXT}`
							vert_center
							horiz_center
							position_cursor
							print "${TEXT}"
						fi
						(( i = i + 1 ))
					done
				fi
				(( i = i + 1 ))
			done
			(( v_pos = 1 ))
			(( h_pos = 0 ))
			position_cursor
			clear_below
			screen_footer
			TEXT="The instance entered appears to be valid!"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			position_cursor
			print "${TEXT}"
			CONFIG_CHANGED=1
		fi
	fi
}

copy_iconfig () {

	(( v_pos = 1 ))
	(( h_pos = 0 ))
	position_cursor
	clear_below
	if [[ -f ${EXP_ICONFIG} && -r ${EXP_ICONFIG} ]]
	then
		cp ${EXP_ICONFIG} ${EXP_ETC}/sunone.config > /dev/null 2>&1
		if (( $? == 0 ))
		then
			TEXT="Config file copied successfully!"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			position_cursor
			print "${TEXT}"
		else
			TEXT1="I'm sorry, there was a problem copying the config file"
			TEXT2="to the ${EXP_ETC} directory."
			TEXT3="Check permissions, or try and determine why the copy"
			TEXT4="did not work."
			TEXT5="Exiting due to a fatal error."
			line_length=`print ${#TEXT1}`
			vert_center
			horiz_center
			line_decrement 2
			position_cursor
			print "${TEXT1}"
			line_length=`print ${#TEXT2}`
			vert_center
			horiz_center
			line_decrement 1
			position_cursor
			print "${TEXT2}"
			line_length=`print ${#TEXT3}`
			vert_center
			horiz_center
			position_cursor
			print "${TEXT3}"
			line_length=`print ${#TEXT4}`
			vert_center
			horiz_center
			line_increment 1
			position_cursor
			print "${TEXT4}"
			line_length=`print ${#TEXT5}`
			vert_center
			horiz_center
			line_increment 2
			position_cursor
			print "${TEXT5}"
			(( v_pos = $term_lines ))
			(( h_pos = 0 ))
			position_cursor
			exit 1
		fi
		validate_iconfig ${EXP_ICONFIG}
		(( v_pos = 0 ))
		(( h_pos = 0 ))
		position_cursor
		clear_below
		screen_header
		screen_footer
	else
		TEXT="The config file entered is either NOT a file or is NOT readable."
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		line_increment 1
		position_cursor
		print "${TEXT}"
		TEXT="Do you want to try again?"
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		(( h_pos = h_pos - 4 ))
		position_cursor
		yorn RESPONSE "${TEXT} \c"
		if [[ ${RESPONSE} == yes ]]
		then
			read EXP_ICONFIG
			copy_iconfig ${EXP_ICONFIG}
		else
			TEXT="Do you want to exit?"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			(( h_pos = h_pos - 4 ))
			postion_cursor
			yorn RESPONSE "${TEXT} \c"
			if [[ ${RESPONSE} == yes ]]
			then
				exit 1
			else
				continue
			fi
		fi
	fi
}

add_edit_list_validate_exit () {

	SaveIFS=${IFS}
	aelvx RESPONSE
	case ${RESPONSE} in
	edit)
		# Edit the config file
		# re-load the array after the config file has been edited.
		# Write out the config file
		if [[ ${CONFIG_CHANGED} == 1 ]]
		then
			save_config
		fi

		# Clear the array!
		unset i_array
		if [[ -n ${EDITOR} ]]
		then
			${EDITOR} ${EXP_ICONFIG}
		else
			vi ${EXP_ICONFIG}
		fi
		validate_iconfig ${EXP_ICONFIG}
		CONFIG_CHANGED=1
		(( v_pos = 0 ))
		(( h_pos = 0 ))
		position_cursor
		clear_below
		screen_header
		screen_footer
		;;
	add)
		(( v_pos = 0 ))
		(( h_pos = 0 ))
		position_cursor
		clear_below
		screen_header
		# Add entries to the config file, verifying those entries as we go along.
		typeset -i I_TYPE
		I_TYPE=7
		while [[ $I_TYPE > 6 ]]
		do 
			(( v_pos = 0 ))
			(( h_pos = 0 ))
			line_increment 1
			position_cursor
			clear_below
			line_increment 2
			position_cursor
			print "1) Application"
			print "2) Directory"
			print "3) Messaging"
			print "4) Portal"
			print "5) Web"
			print "6) Done..."
			TEXT="Please select the server type that you would like to add:"
			print "${TEXT} \c"
			read I_TYPE
			if [[ $I_TYPE == 0 ]]
			then
				I_TYPE=7
			fi
	
			case $I_TYPE in
			1)
				TYPE="[Application]"
				I_TYPE=7
				;;
			2)
				TYPE="[Directory]"
				I_TYPE=7
				;;
			3)
				TYPE="[Messaging]"
				I_TYPE=7
				;;
			4)
				TYPE="[Portal]"
				I_TYPE=7
				;;
			5)
				TYPE="[Web]"
				I_TYPE=7
				;;
			6)
				I_TYPE=0
				break
				;;
			*)
				;;
			esac
		

			TEXT="Enter the server root that you would like to add to the configuration file:"
			line_length=`print ${#TEXT}`
			vert_center
			(( h_pos = 0 ))
			position_cursor
			print "${TEXT}"
			line_increment 1
			(( h_pos = 0 ))
			position_cursor
			read SR
			validate_sr ${SR}
			if [[ $? == 0 ]]
			then
				if [[ ${TYPE} == "[Portal]" ]]
				then
					SR1="${SR}/netscape/directory4"
					CONFIG_CHANGED=1
					IFS=${SaveIFS}
					i=0
					unset si_array
					for DIR_ENTRY in `ls -1 ${SR1}`
					do
						# Try and find the instances!
						case ${DIR_ENTRY} in
						[Hh][Tt][Tt][Pp]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Hh][Tt][Tt][Pp][Ss]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Aa][Dd][Mm][Ii][Nn]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Ss][Ll][Aa][Pp][Dd]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Mm][Ss][Gg]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						*)
							# invalid entry, throw it out.
							;; 
						esac
					done
					SR1="${SR}/netscape/server4"
					CONFIG_CHANGED=1
					IFS=${SaveIFS}
					for DIR_ENTRY in `ls -1 ${SR1}`
					do
						# Try and find the instances!
						case ${DIR_ENTRY} in
						[Hh][Tt][Tt][Pp]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Hh][Tt][Tt][Pp][Ss]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Aa][Dd][Mm][Ii][Nn]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Ss][Ll][Aa][Pp][Dd]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Mm][Ss][Gg]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						*)
							# invalid entry, throw it out.
							;; 
						esac
					done
				else
					CONFIG_CHANGED=1
					IFS=${SaveIFS}
					i=0
					unset si_array
					for DIR_ENTRY in `ls -1 ${SR}`
					do
						# Try and find the instances!
						case ${DIR_ENTRY} in
						[Hh][Tt][Tt][Pp]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Hh][Tt][Tt][Pp][Ss]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Aa][Dd][Mm][Ii][Nn]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Ss][Ll][Aa][Pp][Dd]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						[Mm][Ss][Gg]-*)
							si_array[${i}]=${DIR_ENTRY}
							(( i = i + 1 ))
							;; 
						*)
							# invalid entry, throw it out.
							;; 
						esac
					done
				fi
				# verify that the instances are correct, prompting to edit if necessary.
				i=0 # i is set to the begining of the array.
				j=1 # j is set to the number 1, this makes it easier for the user to

				if [[ ${#si_array[*]} == 0 ]]
				then
					TEXT="No instances found for this server root!"
					(( v_pos = 1 ))
					(( h_pos = 0 ))
					position_cursor
					clear_below
					(( v_pos = 2 ))
					(( h_pos = 0 ))
					position_cursor
					print "${TEXT}"
					TEXT="Removing the Server Root entry from the config file!"
					(( v_pos = 3 ))
					(( h_pos = 0 ))
					position_cursor
					print "${TEXT}"
				else
	
					TEXT="Here are the potential instances that are found in this server root:"
					line_length=`print ${#TEXT}`
					(( v_pos = 1 ))
					(( h_pos = 0 ))
					position_cursor
					clear_below
					(( v_pos = 2 ))
					(( h_pos = 0 ))
					position_cursor
					print "${TEXT}"
					while (( ${i} < ${#si_array[*]} )) # loop until the end of the array
					do
						(( v_pos = 3 ))
						while (( $v_pos < (( $term_lines - 4 )) ))
						do
							if [[ ${i} = ${#si_array[*]} ]]
							then
								break
							fi
							(( h_pos = 0 ))
							position_cursor
							print "${j}) ${si_array[${i}]}" # print the mumber and the array element
							(( i = i + 1 )) # increment i
							(( j = j + 1 )) # increment j
							line_increment 1
						done
						(( v_pos = 3 ))
						(( h_pos = 40 ))
						while (( $v_pos < (( $term_lines - 4 )) ))
						do
							if [[ ${i} = ${#si_array[*]} ]]
							then
								break
							fi
							position_cursor
							print "${j}) ${si_array[${i}]}" # print the mumber and the array element
							(( i = i + 1 )) # increment i
							(( j = j + 1 )) # increment j
							line_increment 1
						done
						if (( ${i} < ${#si_array[*]} ))
						then
							# Too many lines for this screen
							line_increment 1
							(( h_pos = 0 ))
							position_cursor
							clear_below
							TEXT="Press enter for next page..."
							line_length=`print ${#TEXT}`
							horiz_center
							print "${TEXT}"
							read ENTER
						fi
					done
	
					TEXT="Are these entries valid?"
					(( v_pos = (( $term_lines - 2 )) ))
					(( h_pos = 0 ))
					position_cursor
					yorn RESPONSE "${TEXT} \c"
					if [[ $RESPONSE == no ]]
					then
						TEXT="Do you want to remove entry(ies)?"
						(( h_pos = 0 ))
						position_cursor
						clear_line
						yorn RESPONSE2 "${TEXT} \c"
						if [[ $RESPONSE2 == yes ]]
						then	
							while :
							do
								TEXT="Which entry to remove? 1-${#si_array[*]} or return to continue: "
								(( h_pos = 0 ))
								position_cursor
								clear_line
								print "${TEXT} \c"
								read ENTRY
								if [[ ${ENTRY} != "" ]]
								then
									(( ENTRY = ENTRY - 1 ))
									si_array[${ENTRY}]=""
								else
									break
								fi
							done
						fi
					else
						IFS="="
						k=0
						if [[ ${#i_array[*]} = 0 ]]
						then
							k=0
						else
							if [[ ${#i_array[${#i_array[*]}]} = 0 ]]
							then
								(( k = (( ${#i_array[*]} + 1 )) ))
							else
								(( k = (( ${#i_array[*]} + 2 )) ))
							fi
						fi
						j=0
						i_array[${k}]=${TYPE}
						(( k = k + 1 ))
						i_array[${k}]=${SR}
						(( k = k + 1 ))
						while (( ${j} < ${#si_array[*]} ))
						do
							i_array[${k}]=${si_array[${j}]}
							(( k = k + 1 ))
							(( j = j + 1 ))
						done
						(( k = k + 1 ))
					fi
					CONFIG_CHANGED=1
					i=0
					IFS=${SaveIFS}
					save_config
				fi
			fi
		done
		;;
	list)
		validate_iconfig ${EXP_ICONFIG}
		i=0
		j=0
		screen_header
		(( v_pos = 1 ))
		(( h_pos = 0 ))
		position_cursor
		clear_below
		while (( ${i} < ${#i_array[*]} ))
		do
			(( v_pos = 2 ))
			while (( $v_pos < (( $term_lines - 4 )) ))
			do
				if [[ ${i} = ${#i_array[*]} ]]
				then
					break
				fi
				(( h_pos = 0 ))
				position_cursor
				print "${j}) ${i_array[${i}]}" # print the mumber and the array element
				(( i = i + 1 )) # increment i
				(( j = j + 1 )) # increment j
				line_increment 1
			done
			(( v_pos = 3 ))
			(( h_pos = 40 ))
			while (( $v_pos < (( $term_lines - 4 )) ))
			do
				if [[ ${i} = ${#i_array[*]} ]]
				then
					break
				fi
				position_cursor
				print "${j}) ${i_array[${i}]}" # print the mumber and the array element
				(( i = i + 1 )) # increment i
				(( j = j + 1 )) # increment j
				line_increment 1
			done
			if (( ${i} < ${#i_array[*]} ))
			then
				if [[ ${i} = ${#i_array[*]} ]]
				then
					break
				fi
				# Too many lines for this screen
				(( h_pos = 0 ))
				line_increment 1
				position_cursor
				clear_below
				TEXT="Press enter for next page..."
				line_length=`print ${#TEXT}`
				horiz_center
				print "${TEXT}"
				read ENTER
				(( v_pos = 0 ))
				(( h_pos = 0 ))
				position_cursor
				clear_below
				screen_header
			fi
		done
		screen_footer
		;;
	val)
		validate_iconfig ${EXP_ICONFIG}
		if [[ $? == 0 ]]
		then
			screen_header
			screen_footer
			clear_below
			TEXT="iPlanet Config file verified!"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			position_cursor
			print "${TEXT}"
		else
			screen_header
			screen_footer
			clear_below
			TEXT="ERROR, iPlanet Config file error!"
			line_length=`print ${#TEXT}`
			vert_center
			horiz_center
			position_cursor
			print "${TEXT}"
		fi
		;;
	*)
		# Write out the config file
		if [[ ${CONFIG_CHANGED} == 1 ]]
		then
			save_config
		fi
		exit
		;;
	esac
	add_edit_list_validate_exit
}

save_config () {

	# Write out the config file
	if [[ -f ${EXP_ICONFIG} ]]
	then
		# Write out the changes if any
		mv $EXP_ICONFIG ${EXP_ICONFIG}.`date -u +\%Y\%m\%d\%H\%M\%S`
	fi
		
	i=0
	IFS=${SaveIFS}
	EXP_ICONFIG="${EXP_ETC}/sunone.config"
	while (( ${i} < (( ${#i_array[*]} + 1 )) ))
	do	
		echo "${i_array[${i}]}" >> ${EXP_ICONFIG}
		(( i = i + 1 ))
	done
	IFS=${SaveIFS}
}

# Screen Tools
clear_screen () {

	# Clear the dynamic area of the screen, leaving the top line and bottom 3 lines...
	(( v_pos = 0 ))
	(( h_pos = 0 ))
	position_cursor
	term_counter=1
	(( bottom = (( $term_cols - 4 )) ))
	while (( $term_counter < $bottom ))
	do
		tput cup $term_counter $h_pos
		clear_line
		(( term_counter = term_counter + 1 ))
	done

}

screen_header () {

	# Clear the screen, start fresh!
	clear
	TEXT="Explorer/iPlanet Configuration Editor"
	line_length=`print ${#TEXT}`
	horiz_center
	(( v_pos = 0 ))
	position_cursor
	clear_below
	print ${TEXT}

}

screen_footer () {

	TEXT=`gettext "Do you want to (a)dd entries to the file via command line,\n(e)dit the file in an editor, (l)list the config file,\n(v)alidate the file, or e(x)it? [a,e,l,v,x] "`
        # Display prompt
	(( v_pos = (( $term_lines - 3 )) ))
	(( h_pos = 0 ))
	position_cursor
        print "${TEXT} \c"

}

vert_center () {

	(( v_pos = (( $term_lines / 2 )) ))

}

horiz_center () {

	(( h_pos = (( $term_cols - $line_length )) / 2 ))

}

line_increment () {

	(( v_pos = (( v_pos + $1 )) ))

}

line_decrement () {

	(( v_pos = (( v_pos - $1 )) ))
	
}

clear_below () {
	
	tput ed

}

clear_line () {
	
	tput el

}

position_cursor () {
	
	tput cup $v_pos $h_pos

}

bold () {
	
	tput bold

}

init_scr () {
	
	tput sgr0

}

# Main routine. Checks for config file, then allows for add, edit, list, or exit of the program.

term_lines=`tput lines`
term_cols=`tput cols`

# Clear the screen, start fresh!
clear
screen_header

# Offer to display the README file!
TEXT="Do you wish to view the README file?"
TEXT2="This file will explain what the iPlanet config file is,"
TEXT3="what it is used for, and how this program works."
line_length=`print ${#TEXT}`
vert_center
horiz_center
line_decrement 2
position_cursor
clear_line
print ${TEXT}
line_length=`print ${#TEXT2}`
horiz_center
line_increment 1
position_cursor
clear_line
print ${TEXT2}
line_length=`print ${#TEXT3}`
horiz_center
(( h_pos = h_pos - 4 ))
line_increment 1
position_cursor
clear_line
yorn README "${TEXT3} \c"
(( h_pos = 0 ))
position_cursor
clear_line
line_decrement 1
(( h_pos = 0 ))
position_cursor
clear_line
line_decrement 1
(( h_pos = 0 ))
position_cursor
clear_line
if [[ "${README}" == yes ]]
then
	/usr/bin/more ${EXP_HOME}/doc/README.iPlanet_config
	(( v_pos = 0 ))
	(( h_pos = 0 ))
	position_cursor
	clear_below
	screen_header
fi

EXP_ICONFIG=${EXP_ETC}/sunone.config
# Check for existing iPlanet Config File
if [ -f "${EXP_ICONFIG}" ]
then
	EXP_ICONFIG=${EXP_ETC}/sunone.config

	# Validate the current entries in the config file
	(( v_pos = 0 ))
	(( h_pos = 0 ))
	position_cursor
	clear_below
	screen_header
	screen_footer

	validate_iconfig ${EXP_ICONFIG}
	if [[ $? = 0 ]]
	then
		TEXT=`gettext "The sunone config file was found and appears to to valid!"`
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		position_cursor
		bold
		print ${TEXT}
		init_scr
	fi

	while :
	do
		add_edit_list_validate_exit
	done


else
	# Confirm that iPlanet is installed.
	TEXT="iPlanet config file could not be found!"
	TEXT2="Are you sure you have iPlanet software installed?"
	line_length=`print ${#TEXT}`
	vert_center
	horiz_center
	position_cursor
	bold
	print "${TEXT}"
	line_length=`print ${#TEXT2}`
	horiz_center
	(( h_pos = h_pos - 4 ))
	line_increment 1
	position_cursor
	yorn INSTALLED "${TEXT2} \c"
	init_scr
	(( h_pos = 0 ))
	position_cursor
	clear_line
	line_decrement 1
	(( h_pos = 0 ))
	position_cursor
	clear_line
	if [[ "${INSTALLED}" == yes ]]
	then
		TEXT="I cannot find the config file in the appropriate place."
		line_length=`print ${#TEXT}`
		horiz_center
		position_cursor
		clear_line
		bold
		print "${TEXT}"
		init_scr
		TEXT="Do you want to create a new one?"
		line_length=`print ${#TEXT}`
		horiz_center
		(( h_pos = h_pos - 4 ))
		line_increment 1
		position_cursor
		clear_line
		position_cursor
		bold
		yorn RESPONSE "${TEXT} \c"
		init_scr
		if [[ ${RESPONSE} == no ]]
		then
			TEXT="Do you want to enter a different location for the config file? \c"
			line_length=`print ${#TEXT}`
			horiz_center
			(( h_pos = h_pos - 4 ))
			line_increment 1
			position_cursor
			clear_line
			position_cursor
			yorn RESPONSE "${TEXT} \c"
			init_scr
			if [[ ${RESPONSE} == yes ]]
			then
				(( v_pos = 1 ))
				(( h_pos = 0 ))
				position_cursor
				clear_below
				TEXT="After you enter the config filename, It will be verified, then copied"
				line_length=`print ${#TEXT}`
				vert_center
				horiz_center
				position_cursor
				print "${TEXT}"
				TEXT="to the correct location. Enter the full pathname of the config file: "
				line_length=`print ${#TEXT}`
				horiz_center
				line_increment 1
				position_cursor
				print "${TEXT}"
				line_increment 1
				(( h_pos = 0 ))
				position_cursor
				read EXP_ICONFIG
				copy_iconfig ${EXP_ICONFIG}
				add_edit_list_validate_exit
			else
				(( v_pos = 1 ))
				(( h_pos = 0 ))
				position_cursor
				clear_below
				TEXT="Exiting since there is not an appropriate config file."
				line_length=`print ${#TEXT}`
				vert_center
				horiz_center
				position_cursor
				tput blink
				print "${TEXT}"
				init_scr
				(( v_pos = $term_lines ))
				(( h_pos = 0 ))
				position_cursor
				exit 1
			fi
		else
			add_edit_list_validate_exit
		fi
	else
		(( v_pos = 1 ))
		(( h_pos = 0 ))
		position_cursor
		clear_below
		TEXT="Exiting since iPlanet is not installed."
		line_length=`print ${#TEXT}`
		vert_center
		horiz_center
		position_cursor
		tput smul
		bold
		print "${TEXT}"
		tput rmul
		init_scr
		(( v_pos = $term_lines ))
		(( h_pos = 0 ))
		position_cursor
		exit 1
	fi
fi
