#!/bin/bash
#
#########################################################################################
# Script: 		absmenu.sh
# Description: 		Manage ABSSolute software deployment 
# Author: 		ABS Laundry Business Solutions
# Version: 		9.08.01
#### Changelog of script ################################################################################################
# Date        Author    Version 	Change    
# 15-May-2011 JMI	1.0		Initial version
# 29-May-2011 JMI	1.2		Moved config file to absmenu/config/absmenu_config.sh
# 26-Sep-2015 ROP	1.3		Merged some scripts
# 19-May-2015 ROP	1.6		Added android service
# 14-Aug-2015 ROP	1.7		Added rolling update mechanism
# 30-Jan-2017 MBU	2.2		Uploaded latest used version from VM-ASP-TST to SVN
# 31-Jan-2017 MBU	2.3		Development unattended auto deploy options for VM-ASP-TST EU_LATEST/US_LATEST
# 08-Feb-2017 AFA	2.4		Application Server License deployment / Reports deployment / I-Net License Updated
# 25-Jan-2018 IGH	2.5		Change of webcomponents naming as per 3-letter naming convention
# 12-Sep-2018 MBU	2.6		Extention of UNATTENDED ABSMENU usage
# 28-Sep-2018 MBU	2.7		Extention of UNATTENDED ABSMENU usage
# 05-Nov-2018 MBU	2.8		Extention of UNATTENDED ABSMENU usage
# 06-Nov-2018 MBU	2.9		Added sqlscript log based error detection for UNATTENDED ABSMENU usage
# 27-Dec-2018 MBU	3.0		Added pre patchrun check
#					Added support for ABSSolute releases from GIT
#					Added parallel webserver deployment
#					Remove rolling patching mechanism
#					Added SNMP check during glassfish startup
# 07-Jan-2018 MBU	3.1		Bugfix: exit code is always 1 during unattended deployment actions
# 07-Feb-2019 MBU	3.2		Bugfix: Unpack patch 9.03.00.RELEASE.px deletes future repository
# 26-Mar-2019 IGH/MBU	3.3		Added support to deploy new webapplications: wua=webclient my uniform assistant wrd=webclient residential delivery wrr=webclient route returns
#			  		Bugfix: Install glassfish on non web servers
# 04-Apr-2019 MBU	4.0		Added generation of RMIDIAGNOSTICPORT in absserver.properties
#					Added property generation of rac connection
#					Added exclusion option for CUSTOMER reports with ABSM_EXCLUDECUSTREP setting
#					Added custom heapspace setting for app/rep services
#					Added syncabsshell option to push abs.sh to middle-tier server
#					Added upgraderegistration4 to add missing column in service_registation.cfg
#					Added beautifyregistration to order columns in service_registation.cfg
#					Added execution of conversion scripts after upgrade
# 17-Apr-2019 MBU	4.1		Support for report server only slots
#					Default t flag value (all) on start/stop/restart CLI usage
# 07-May-2019 MBU	4.2		Bugfix: Parallel deploy custom skin for WP2 gives deployment error
# 27-Jun-2019 MBU	4.3		Bugfix: Service retrieval on partial environment name hit
# 15-Jul-2019 MBU	4.4		Bugfix: Custom config settings not working (bug originated from version 4.3)
# 21-Oct-2019 MBU	4.5		Bugfix: Auto deploy feature not working with SNMP selftest value in ABSSolute 9.03.04 (switch to SNMP status value)
#
#
# 4.6   CHECK BITBUCKET LOG FOR HISTORY CHANGES
# 
#    DO NOT ADD HISTORY CHANGES ANYMORE
# 12-Feb-2024 RAY       6.0         	Support for Glassfish4, Payara5, Tomee8, Tomee91 and Tomcat90
# 03-Apr-2024 RAY	9.08.00	    	Renamed version
# 25-Apr-2024 RAY       9.08.00     	Added Support for Tomcat9 - ABS-164468
# 01-Jul-2024 RAY       9.08.01     	Added Support for Tomcat9 and Tomcat10 - ABS-165658
# 21-Aug-2024 RAY       9.08.01     	TI changes for replacing TomEE with Tomcat in 9.08.00 - ABS-167946
# 04-Nov-2024 RAY	9.09.00     	Absmenu update supporting Java21 for ABSSolute 9.09.00 - ABS-170835
# 04-Nov-2024 RAY	9.09.00 	Absmenu update supporting Plugins folder - INSTALLER-176
# 04-Nov-2024 RAY	9.09.00 	Absmenu update supporting Application Server new Classpath location - ABS-170842.
# 16-Dec-2024 RAY	9.09.00 	Fix for ABSGENERICWEBSERVICE loj4j.properties file
# 16-Dec-2024 RAY	9.09.00 	Fix for web version based on ABSSolute version and patch level (unattended_deploy)
# 01-May-2025 RAY	9.09.00 	Fix bugs
# 01-Jun-2025 RAY	9.09.02         ABSSolute Server - Standardization & hot redeploy - TS-839
# 09-Oct-2025 RAY	9.09.02         ABSSolute Server - Fixed issue creating deploy directory on remote server
# 31-Oct-2025 RAY       9.09.02         Add Java zulu_17_60_17_769a1f364544 for JAVA17_60_HOME - TS-1955
# 26-Nov-2025 RAY       9.09.02         Add Java zulu_21_46_19_f28ddd12524c for JAVA21_46_HOME - TS-2142
# 12-Dec-2025 RAY       9.09.02         Add Java zulu_17_62_17_769a1f364544 for JAVA17_62_HOME - TS-1955
########################################################################################################################

#### settings / parameters / variables / etc ############################################
SCRIPTRELEASE="9.09.02"         # script version
SCRIPTDATE="20251210"           # date of last change to script (yyyymmdd)
SCRIPTUSER=$(whoami)            # user that started the script. 

#### Internal variables /parameters -- DO NOT CHANGE ####################################
LOGDATE=$(date +%Y_%V*)
SCRIPTVERSION="$SCRIPTRELEASE"_"$SCRIPTDATE"

TERM=linux

## Set environment using the absmenu_config script ######################################
if [ -x ./absmenu/config/absmenu_config.sh ]
then
    . ./absmenu/config/absmenu_config.sh
else
    if [ -x /abs/absmenu/config/absmenu_config.sh ]
    then
        . /abs/absmenu/config/absmenu_config.sh
    else
        echo "ABSMENU script - settings not found !  Please check if you have started absmenu.sh with 'abssolute' credentials"
        echo "Aborting..."
        echo 
        exit 1
    fi
fi

# check if the needed local directories and files exist
if [ ! -d "$ABSMENUPATH" ]
then
	echo "Directory $ABSMENUPATH does not exist !"
	echo "Please check..." 
	exit 1
fi
if [ ! -e "$ABSMENUGLOBALCONFIG" ]
then
	echo "Configuration file $ABSMENUGLOBALCONFIG does not exist !"
	echo "Please check..." 
	exit 1
fi

DOABSLOGGING="yes"
if [ ! -d "$ABSMENULOGPATH" ]
then
    mkdir "$ABSMENULOGPATH"
    [ ! -d "$ABSMENULOGPATH" ] && DOABSLOGGING="no"
fi
export DOABSLOGGING

#########################################################################################
# menu options and functions 
# The function names are also used to build the on-screen menu.
#########################################################################################

# Check SNMP status code. Return SNMP status
snmpcheck_app_server()
{
	# $1 = SNMP_SERVER
	# $2 = SNMP_SLOT

	SNMP_SERVER=$1
	SNMP_SLOT=$2
	
	[ ${#SNMP_SLOT} == 1 ] && SNMPVALUE=$(snmpwalk -c public -v 1 udp:$SNMP_SERVER:50${SNMP_SLOT}14 1.3.6.1.4.1.227.1.1 | rev | head -c2 | rev | xargs)
	[ ${#SNMP_SLOT} == 2 ] && SNMPVALUE=$(snmpwalk -c public -v 1 udp:$SNMP_SERVER:5${SNMP_SLOT}14 1.3.6.1.4.1.227.1.1 | rev | head -c2 | rev | xargs)
	
	[ "$SNMPVALUE" == "1" ] && return 0
	return 1
}

absmenu_log()
{
    # first set variable ABSMESSAGE to a text you want to log
    # then call absmenu_log to timestamp it and write it to the logfile
    if [ "$DOABSLOGGING" == "yes" ]
    then
        echo -n $(date +%T) >> $ABSMSCRIPTLOGNAME
        echo "  $ABSMESSAGE" >> $ABSMSCRIPTLOGNAME
    fi
}

absmenu_logline()
{
    if [ "$DOABSLOGGING" == "yes" ]
    then
        echo -n $(date +%T) >> $ABSMSCRIPTLOGNAME
        echo "  $1" >> $ABSMSCRIPTLOGNAME
    fi
}

deploy_future_to_environment()
{
    # $1 - all / srv / webapps / webapps_parallel / webserver_only / delete_web_server
    [ "$1" != "webapps" ] && [ "$1" != "webapps_parallel" ] && [ "$1" != "webserver_only" ] && [ "$1" != "delete_web_server" ] && . $ABSMENUPATH/bin/service_administration.sh stop gf web
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" "$1"
}

touch $ABSMSCRIPTLOGNAME
echo >> $ABSMSCRIPTLOGNAME
echo "-------------------------------------------------------------------------------" >> $ABSMSCRIPTLOGNAME
echo >> $ABSMSCRIPTLOGNAME

export ABSMESSAGE="User $(whoami) started $0 on $(date +%d-%b-%Y)"
absmenu_log

selectoptions_s() # Software update (actions...)
{
    export ABSMESSAGE="MENUACTION: s - automatic update (backup, stop, distribute, start)"
    absmenu_log
    [ $FIRSTRUNDONE == N -a "$ABSM_DOAUTOBACKUP" == Y ] && . $ABSMENUPATH/bin/backup_current_environment.sh
    case $UPDATEWHAT in
        a|A)    deploy_future_to_environment all
				;;
        d|D)    deploy_future_to_environment delete_web_server
				;;
        n|N)    deploy_future_to_environment webserver_only
				;;
		p|P)    deploy_future_to_environment webapps_parallel
				;;
        s|S)    deploy_future_to_environment srv
				;;
        w|W)    deploy_future_to_environment webapps
				;;
    esac
    export FIRSTRUNDONE=Y
}

selectoptions_r() # Reports update 
{
    export ABSMESSAGE="MENUACTION: r - automatic reports update (backup, copy reports + fonts)"
    absmenu_log
    [ $FIRSTRUNDONE == N -a "$ABSM_DOAUTOBACKUP" == Y ] && . $ABSMENUPATH/bin/backup_current_environment.sh
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" reports
    export FIRSTRUNDONE=Y
}  

selectoptions_l() # License update 
{
    export ABSMESSAGE="MENUACTION: k - license update"
    absmenu_log
    [ $FIRSTRUNDONE == N -a "$ABSM_DOAUTOBACKUP" == Y ] && . $ABSMENUPATH/bin/backup_current_environment.sh
    # Do not restart any service -- . $ABSMENUPATH/bin/service_administration.sh stop gf web
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" license
    # Do not restart any service -- . $ABSMENUPATH/bin/service_administration.sh start gf web
    export FIRSTRUNDONE=Y
}  

selectoptions_p() # Generate property files
{
    export ABSMESSAGE="MENUACTION: 8 - Generate properties and xml files"
    absmenu_log
    if [ $FIRSTRUNDONE == N ]
    then
        export RESTORE_YN=N
        echo
        read -p "Are you SURE you want to re-generate properties and xml files for the $ABSMENU_CURRENT_ENVIRONMENT environment? (Y/N)  " RESTYN
        export ABSMESSAGE="response to \"are you sure\" = $RESTYN"
        absmenu_log
        export RESTYN
    fi
    [ "$RESTYN" == Y -o "$RESTYN" == y ] && . $ABSMENUPATH/bin/generate_properties.sh all normal "$ABSMENU_CURRENT_ENVIRONMENT" x x x x x x x x x x x x x x x x x x x x x x x x x
    export FIRSTRUNDONE=Y
}

selectoptions_h() # Maximal heapspace sync
{
    export ABSMESSAGE="MENUACTION: h - heapspace max sync"
    absmenu_log
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" heapspace
	echo 
	echo "The heapspace max configuration values are synchronised to all services."
	echo "A restart of the services is required to enable the change."
	export FIRSTRUNDONE=Y
} 

selectoptions_f() # Deploy Standard Fonts to Repository
{
    export ABSMESSAGE="MENUACTION: f - deploy fonts"
    absmenu_log
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" fonts
	export FIRSTRUNDONE=Y
} 

selectoptions_t() # Toggle Application and Report Servers HTTP/HTTPS
{
    export ABSMESSAGE="MENUACTION: t - make application and report servers http/https"
    absmenu_log
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" http_https
	export FIRSTRUNDONE=Y
}

selectoptions_k() # Install ABS Encryption Key
{
    export ABSMESSAGE="MENUACTION: k - Install ABS Encryption Key"
    absmenu_log
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" abs_encryption_key
	export FIRSTRUNDONE=Y
}

selectoptions_c() # Deploy Server Certificates Online
{
    export ABSMESSAGE="MENUACTION: c - Deploy Server Certificates Online"
    absmenu_log
    . $ABSMENUPATH/bin/service_binrep_update.sh "$ABSMENU_CURRENT_ENVIRONMENT" abs_deploy_certificates
	export FIRSTRUNDONE=Y
}

selectoptions_() #
{
    echo
}

selectoptions_1() # Start environment
{
    export ABSMESSAGE="MENUACTION: 1 - Start environment"
    absmenu_log
    . $ABSMENUPATH/bin/service_administration.sh start gf web
}

selectoptions_2() # Stop environment
{
    export ABSMESSAGE="MENUACTION: 2 - Stop environment"
    absmenu_log
    . $ABSMENUPATH/bin/service_administration.sh stop gf $DOALSOWEB
}

selectoptions_3() # Restart environment
{
    export ABSMESSAGE="MENUACTION: 3 - Restart environment"
    absmenu_log
    . $ABSMENUPATH/bin/service_administration.sh restart gf web
}

selectoptions_4() # List registered server components
{
    export ABSMESSAGE="MENUACTION: 4 - List registered server components"
    absmenu_log
    . $ABSMENUPATH/bin/service_administration.sh list web
}

selectoptions_5() # Restart Report Server(s)
{
    export ABSMESSAGE="MENUACTION: 5 - Restart Report Server(s)"
    absmenu_log
    . $ABSMENUPATH/bin/service_administration.sh represtart
}

selectoptions_6() # Backup software (current environment)
{
    export ABSMESSAGE="MENUACTION: 6 - Backup environment"
    absmenu_log
    . $ABSMENUPATH/bin/backup_current_environment.sh
}

selectoptions_7() # Restore last backup
{
    export ABSMESSAGE="MENUACTION: 7 - Restore last environment backup"
    absmenu_log
    if [ $FIRSTRUNDONE == N ]
    then
        RESTORE_YN=N
        echo
        read -p "Are you SURE you want to restore environment $ABSMENU_CURRENT_ENVIRONMENT to the last backed up situation? (Y/N)  " RESTORE_YN
        export ABSMESSAGE="response to \"are you sure\" = $RESTORE_YN"
        absmenu_log
        export RESTORE_YN=N
    fi
    
    if [ "$RESTORE_YN" == "Y" -o "$RESTORE_YN" == "y" ] 
    then 
        . $ABSMENUPATH/bin/restore_current_environment.sh
        deploy_future_to_environment all
        export ABSMESSAGE="Backup restored to future repository and distributed to server(s)"
        absmenu_log
    fi
    export FIRSTRUNDONE=Y
}

selectoptions_8() # Delete current environment
{
    export ABSMESSAGE="MENUACTION: 8 - Delete current environment"
	absmenu_log
	read -p "Confim Delete of the Environment: $ABSMENU_CURRENT_ENVIRONMENT y/n ? " YN
	case $YN in
		y|Y)	. $ABSMENUPATH/bin/service_administration.sh stop gf $DOALSOWEB
				. $ABSMENUPATH/bin/service_administration.sh delete
				;;
		n|N)	;;
		*)		echo "Invalid input"
				;;
	esac
}

selectoptions_() #
{ 
    echo
}

selectoptions_m() # Environment selection menu
{
    export ABSMESSAGE="MENUACTION: m - select new environment"
    absmenu_log
    . $ABSMENUPATH/bin/select_current_evironment.sh normal
}

selectoptions_q() # Quit
{
    exit
}

# Function to check the column count in service_registration.cfg. Will exit when it is incorrect
check_service_registration()
{
	if [ $(grep -v '::' $ABSMENUGLOBALCONFIG  | grep -v "^$" | head -1 | awk ' {print NF} ') -ne 35 ] 
	then
		echo "Please check the presents of columns: 15_heapspace and 28_ExclCusReport"
		echo "'/abs/absmenu.sh -c upgraderegistration4' can be used to add the columns. It is recommended to validate after."
		exit 0
	fi 
}

############### main body ##############################
clear			

# Check flags for unattended deployment
while getopts c:e:f:t: OPT 
do
	case "$OPT" in
	c)  export UNATTENDED_COMMAND=$( echo "$OPTARG" | tr '[:upper:]' '[:lower:]');;					#Command for unattended option
	e)  export UNATTENDED_ENVIRONMENT=$OPTARG;;														#Environment for unattended command
    f)  export UNATTENDED_PACKAGEPATH=$OPTARG;;														#Optional patch/update package or directory
	t)  export UNATTENDED_COMMAND_PROCESS=$( echo "$OPTARG" | tr '[:upper:]' '[:lower:]');;			#Mandatory with c flag when start/stop/restart (app/rep/web/all)
    esac
done

# Run abs.sh sync or registration update
if [ "$UNATTENDED_COMMAND" == "syncabsshell" ] || [ "$UNATTENDED_COMMAND" == "upgraderegistration4" ] || [ "$UNATTENDED_COMMAND" == "beautifyregistration" ]
then
	. $ABSMENUPATH/bin/unattended_deploy.sh
	exit $?
fi

# Validate the column count in the config
check_service_registration

# Enable unattended deployment when c and e flags are given
if [ ! -z "$UNATTENDED_COMMAND"  ] && [ ! -z "$UNATTENDED_ENVIRONMENT"  ]
then
	[ -z "$UNATTENDED_COMMAND_PROCESS" ] && export UNATTENDED_COMMAND_PROCESS="all"
	. $ABSMENUPATH/bin/unattended_deploy.sh
	exit $?
fi

# Select environment for further processing
export ABSMESSAGE="Select new environment (initial)"
absmenu_log
. $ABSMENUPATH/bin/select_current_evironment.sh normal

# Set correct web server path component
# Extract ABSSolute Core Number
export ABSSOLUTENUMVERSION=`echo $ABSMENU_FUTURE_ENV_SERVERJAR_VERSION | sed 's/\(.\)\.\(..\)\.\(..\).*/\1\2\3/'`
# Extract ABSSolute Patch Number
export ABSSOLUTEPATCHLEVEL=${ABSMENU_FUTURE_ENV_SERVERJAR_VERSION:(-2)}
# Extract ABSSolute Patch Number and verify for Release Candidate
export ABSSOLUTEPATCHLEVELRC=${ABSMENU_FUTURE_ENV_SERVERJAR_VERSION:(-3)}
if [ ${ABSSOLUTEPATCHLEVELRC:0:2} = "RC" ]
then
	export ABSSOLUTEPATCHLEVEL=${ABSMENU_FUTURE_ENV_SERVERJAR_VERSION:(-1)}
fi

if [ $ABSSOLUTENUMVERSION -ge 90902 ]
then
	# tomcat_10.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME="tomcat10"
	export TOMEE8FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90900 ]
then
	# tomcat_10.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME="tomcat10"
	export TOMEE8FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90801 ]
then
	# tomcat_9.zip and tomcat_10.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMCAT9FOLDERNAME="tomcat9"
	export TOMCAT10FOLDERNAME="tomcat10"
	export TOMEE8FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90800 ] && [ $ABSSOLUTEPATCHLEVEL -ge 10 ]
then
	# tomcat_9.zip and tomcat_10.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMCAT9FOLDERNAME="tomcat9"
	export TOMCAT10FOLDERNAME="tomcat10"
	export TOMEE8FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90800 ] && [ $ABSSOLUTEPATCHLEVEL -ge 01 ]
then
	# tomee_91.zip and tomcat_90.zip
	export TOMEEFOLDERNAME="tomee91"
	export TOMCATFOLDERNAME="tomcat90"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMEE8FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90704 ]
then
	# tomee_8.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEE8FOLDERNAME="tomee8"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90703 ]
then
	# tomee_8.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEE8FOLDERNAME="tomee8"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90702 ]
then
	# tomee_8.zip
	export TOMEEFOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEE8FOLDERNAME="tomee8"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
elif [ $ABSSOLUTENUMVERSION -ge 90701 ]
then
	# tomee_8.zip
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME="tomee8"
elif [ $ABSSOLUTENUMVERSION -ge 90700 ] && [ $ABSSOLUTEPATCHLEVEL -ge 23 ]
then
	# tomcat_9.zip
	export TOMCAT9FOLDERNAME="tomcat9"
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90700 ] && [ $ABSSOLUTEPATCHLEVEL -ge 01 ]
then
	# tomee_8.zip
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export GLASSFISHPATH=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME="tomee8"
elif [ $ABSSOLUTENUMVERSION -ge 90602 ]
then
	# payara_55.zip
	export GLASSFISHPATH="payara5"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90601 ]
then
	# payara_56.zip
	export GLASSFISHPATH="payara5"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90600 ] && [ $ABSSOLUTEPATCHLEVEL -ge 33 ]
then
	# payara_56.zip
	export GLASSFISHPATH="payara5"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90600 ] && [ $ABSSOLUTEPATCHLEVEL -ge 01 ]
then
	# payara_55.zip
	export GLASSFISHPATH="payara5"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90400 ]
then
	# payara_5.zip
	export GLASSFISHPATH="payara5"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90103 ]
then
	# glassgfish_411.zip
	export GLASSFISHPATH="glassfish4"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
elif [ $ABSSOLUTENUMVERSION -ge 90000 ]
then
	# glassgfish_411.zip
	export GLASSFISHPATH="glassfish4"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
else
	# glassgfish_312.zip
	export GLASSFISHPATH="glassfishv3"
	export TOMCAT9FOLDERNAME=""
	export TOMCAT10FOLDERNAME=""
	export TOMCATFOLDERNAME=""
	export TOMEEFOLDERNAME=""
	export TOMEE8FOLDERNAME=""
fi
								
while :
do
	clear
	echo -e "*** \e[1mABS Laundry Business Solutions \e[0m***"
	echo -e "--- ABSMENU Script - Release \033[0;36m$SCRIPTVERSION\033[0m"
	echo "--- System's Date: $(date)"
	echo "==========================================================================="
	
	# Display details on the selected environment
	echo "Customer / Environment : $ABSMENU_CURRENT_ENV_LICCODE / $ABSMENU_SELECTED_ENVIRONMENT"
	echo "Current Server version : $ABSMENU_CURRENT_ENV_SERVERJAR_VERSION $ABSMENU_CURRENT_ENV_SERVERJAR_BUILDTIME $ABSMENU_CURRENT_ENV_SERVERJAR_REVISION"
	echo "Current Patch version  : $ABSMENU_CURRENT_ENV_PATCHSERVERJAR_VERSION $ABSMENU_CURRENT_ENV_PATCHSERVERJAR_BUILDTIME $ABSMENU_CURRENT_ENV_PATCHSERVERJAR_REVISION"
	echo "Future Server version  : $ABSMENU_FUTURE_ENV_SERVERJAR_VERSION $ABSMENU_FUTURE_ENV_SERVERJAR_BUILDTIME $ABSMENU_FUTURE_ENV_SERVERJAR_REVISION"
	echo "Future Patch version   : $ABSMENU_FUTURE_ENV_PATCHSERVERJAR_VERSION $ABSMENU_FUTURE_ENV_PATCHSERVERJAR_BUILDTIME $ABSMENU_FUTURE_ENV_PATCHSERVERJAR_REVISION"
	echo "Repository home        : $ABSMENUREPOSITORYSERVER:$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"
	echo "Backup home            : $ABSMENUBACKUPSERVER:$ABSMENUBACKUPLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"

	# select a menu option
	echo "==========================================================================="
    grep selectoptions_ absmenu.sh | grep -v V_MENU_CHOICE | sed -e "s/\(selectoptions_\)\(.*\)\(() #\)\(.*\)/\2 \4/"
	echo "================================================"
	echo ""
    read -p "Enter option or press ENTER to quit: " V_MENU_CHOICE
	
    if [ "$V_MENU_CHOICE" == "q" -o "$V_MENU_CHOICE" == "Q" -o ! "$V_MENU_CHOICE" ] 
    then 
        export ABSMESSAGE="Exit script"
        absmenu_log
        echo "Thank you for using the script."
        echo ""
        break
    fi
	
	case "$V_MENU_CHOICE" in
        1|2|3|4|5|6|7|8|9|c|f|h|k|l|m|p|q|r|s|t)  MENU_PARAM_OK=Y;;
        *)                          	  	      MENU_PARAM_OK=N;;
    esac
	
    if [ "$MENU_PARAM_OK" == "N" ]
	then
		echo Unknown menu option \""$V_MENU_CHOICE"\". Please select again.
	else
        export FIRSTRUNDONE=N
        export SCRIPTQUESTIONDONE=N
        export DOALSOWEB=web
        if [ "$V_MENU_CHOICE" == "s" ]
        then
            ###read -p "[a] - update all [s] - app/rep [w] - web sequential [p] - web parallel [q] - quit: " UPDATEWHAT
			echo "[a] - Deploy all (app+rep+web)"
			echo "[s] - Deploy servers only (app+rep)"
			echo "[w] - Deploy web apps only (sequential)"
			echo "[p] - Deploy web apps only (parallel)"
			echo "[n] - Deploy web server only (parallel)"
			echo "[d] - Delete web server (parallel)"
			echo "[q] - quit (or any other key)"
			echo ""
			read -p "Enter action [a|s|w|p|n|d|q] : " UPDATEWHAT
			
            export ABSMESSAGE="response to \"app_rep_web\app_rep\web_sequential\web_parallel\web_server_only\delete_web_server\all\" = $UPDATEWHAT"; absmenu_log
            echo ""
            case $UPDATEWHAT in
                a|A)				UPDATEWHAT=a;;
				d|D|p|P|s|S|w|W|n|N)    ;;
				q|Q)    			UPDATEWHAT=q;;
                *)              	UPDATEWHAT=q;;
            esac
            export UPDATEWHAT
            case $UPDATEWHAT in
                a|A)    echo "Update application and report server(s) and web components";;
				d|D)    echo "Delete Web Server and web apps";;
                s|S)    echo "Update application and report server(s) only";;
				p|P)    echo "Update web components only - Parallel Deployment";;
                w|W)    echo "Update web components only - Sequential Deployment";;
				n|N)    echo "Install/Update webserver only - Parallel Deployment (no web apps)";;
				q|Q)	echo "Thank you for using the script."; V_MENU_CHOICE=q;;
            esac
            echo ""
        fi
		export ABSMENU_CURRENT_ENVIRONMENT="$ABSM_ENVIRONMENT_NAME"
		selectoptions_$V_MENU_CHOICE
	fi
    echo
    read -p "Press ENTER to continue... "
    export ABSMENU_CURRENT_ENVIRONMENT="$ABSM_ENVIRONMENT_NAME"
    . $ABSMENUPATH/bin/select_current_evironment.sh get_details
done
