#!/bin/bash
#
#########################################################################################
# Script: 		service_binrep_update.sh
# Description: 	Service administration script
# Author: 		ABS Laundry Business Solutions
# Version: 		4.5
#### Changelog of script ################################################################
# Date        Author    Version 	Change   
# 13-jun-2011 JMI		1.2     	Initial setup
# 17-jun-2011 JMI		1.3     	removed rsync compression option
#                               	- merged rsync jobs for example /Lib & /License
#                                 	  included in one job
#                               	- binary replication based on global repository
# 14-aug-2015 ROP  		1.7     	Changed for rolling updates
# 24-mar-2017 MBU	    1.8     	Changes for uhfmonitor application
# 16-aug-2017 MBU		1.9     	Bugfix if structure line 776 command not found
# 27-Dec-2018 MBU		3.0			Added parallel web deployment procedure
# 26-Mar-2019 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 exclusion option for CUSTOMER reports with ABSM_EXCLUDECUSTREP setting
#									Added custom heapsize setting
# 17-Apr-2019 MBU		4.1			Synchronization of application server libraries for report server only slot
# 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
###################################################################################

pushd () {
    command pushd "$@" > /dev/null
}

popd () {
    command popd "$@" > /dev/null
}

# Cleanup method when exiting ABSMENU during parallel web deploy
stop_web_deploy_parallel()
{
	for pidfile in $ABSMENUPATH/tmp/*.pid;
	do
		kill $(cat $pidfile)
	done
	
	rm -f $ABSMENUPATH/tmp/*.pid
	rm -f $ABSMENUPATH/tmp/*.deploylist
}

# Start processing with PID files
start_web_deploy_parallel()
{
	# $1 = environment
	
	# No web applications
	[ $(grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | awk '$4!="app" && $4!="rep" { print $0 } ' | wc -l) -eq 0 ] && return 0
	
	# Remove old pid files and deploy lists
	rm -f $ABSMENUPATH/tmp/*.pid
	rm -f $ABSMENUPATH/tmp/*.deploylist
	
	# Register TRAP function
	trap stop_web_deploy_parallel EXIT
	
	# Creating the WAR files in the repository for deployment
	echo ""
	create_repository_warfiles $1 &> /dev/null
	
	# Launching glassfish install process
	grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk '$4!="app" && $4!="rep" { print $2,$5 } ' | uniq | while read ABSM_SERVERNAME ABSM_SLOT
	do
		absmenu_logline "Start web deployment process for webserver on $ABSM_SERVERNAME on slot $ABSM_SLOT"
		install_web_slot_parallel $1 $ABSM_SERVERNAME $ABSM_SLOT &
		sleep 1
	done
	
	# Check amount of PID files until 0 (check processes instead)
	echo ""
	echo "******************** Web deployment overview *******************"
	while [ $(find $ABSMENUPATH/tmp -name '*.pid' | wc -l ) -ne 0 ]
	do
		sleep 1
	done
	[ $(cat $ABSMENUPATH/tmp/*.deploylist | wc -l) -eq 0 ] && echo "******* The were no errors during the deployment process *******"
	rm -f $ABSMENUPATH/tmp/*.deploylist
	
	# Removing war files from repository
	remove_repository_warfiles $1
	trap '' EXIT
	echo ""
}

# Installes a specific web slot from an environment
install_web_slot_parallel()
{
	# $1 = Environment
	# $2 = Server name
	# $3 = Slot number
	
	ABSM_ENVIRONMENT=$1
	ABSM_SERVERNAME=$2
	ABSM_SLOT=$3
	
	PIDFILE=$ABSMENUPATH/tmp/"$ABSM_SERVERNAME"_"$ABSM_SLOT".pid
	ABSMSCRIPTLOGNAME=`date +"$ABSMENULOGPATH"/absmenu_parallel_"$ABSM_SERVERNAME"_"$ABSM_SLOT"_%Y_%V.log`
	PROCESSID=$BASHPID
	ENDTIMESTAMP=$(date --date="$GFSNMPMAXAPPSTARTTIME min" +"%s")
	
	# Create PID
	echo $PROCESSID  > $PIDFILE
	absmenu_logline "Start installation of the webserver with the PID file: $PIDFILE (logfile = $ABSMSCRIPTLOGNAME)"
	
	# Create deploy list
	grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk -v a="$ABSM_SERVERNAME" -v b="$ABSM_SLOT" '$2==a && $5==b && $4!="app" && $4!="rep" { print "DEPLOY", $1, $2, $4, $5, $19, $20, $21, $22, $23, $24 } ' > $ABSMENUPATH/tmp/"$ABSM_SERVERNAME"_"$ABSM_SLOT".deploylist
	DEPLOYLIST=$ABSMENUPATH/tmp/"$ABSM_SERVERNAME"_"$ABSM_SLOT".deploylist
	
	# Install glassfish on the server and sync files. Return if the domain won't start
	echo "Deploying web applications on $ABSM_SERVERNAME slot $ABSM_SLOT (logfile = $ABSMSCRIPTLOGNAME)"
	install_cleanup_glassfish $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SLOT &> /dev/null
	
	# Check if the domain is running. If not one re-attempt is made
	check_web_domainstatus $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SLOT
	if [ $? != 0 ] 
	then 
		# Install glassfish on the server and sync files. Return if the domain won't start
		echo "Redeploying web applications on $ABSM_SERVERNAME slot $ABSM_SLOT (logfile = $ABSMSCRIPTLOGNAME)"
		install_cleanup_glassfish $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SLOT &> /dev/null
		
		# Check if the domain is running. If not the deployment process is killed
		check_web_domainstatus $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SLOT
		
		if [ $? != 0 ] 
		then
			absmenu_logline "Cancelled installation of the webserver with the PID file: $PIDFILE (logfile = $ABSMSCRIPTLOGNAME)"
			cat $DEPLOYLIST | while read ABSM_DEPLOYSTATUS ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_TYPE ABSM_SLOT ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT
			do
				# Remove line from deploylist
				sed -i "/$ABSM_WEBNAME/d" $DEPLOYLIST
				# Add to deploylist with error
				echo "GFINSTALLERROR $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_TYPE $ABSM_SLOT $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT" >> $DEPLOYLIST
				echo "- $ABSM_SERVERNAME slot $ABSM_SLOT $ABSM_WEBCONTEXT ($ABSM_TYPE): Glassfish did not install successfully."
			done
			rm $PIDFILE
			kill $PROCESSID
		fi
	fi
		
	# Move binaries to server
	create_server_warfiles $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SLOT &> /dev/null
	
	# Deploy based on SNMP until $ENDTIMESTAMP is reached (or deploylist is empty )
	while true 
	do
		# Perform deploy of each webapp and remove line from the deploylist if deployed is performed		
		cat $DEPLOYLIST | awk -v a="DEPLOY" '$1==a  { print $0 } ' | while read ABSM_DEPLOYSTATUS ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_TYPE ABSM_SLOT ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT 
		do
			# Check SNMP
			snmpcheck_app_server $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT &> /dev/null
			
			if [ $? -eq 0 ]
			then
				# Remove line from deploylist
				sed -i "/$ABSM_WEBNAME/d" $DEPLOYLIST
				
				# Deploy web application
				deploy_server_warfiles $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_TYPE $ABSM_SLOT $ABSM_WEBNAME $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBLIB &> /dev/null
				if [ $? -ne 0 ]
				then
					echo "DEPLOYFAILED $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_TYPE $ABSM_SLOT $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT" >> $DEPLOYLIST
					echo "- $ABSM_SERVERNAME slot $ABSM_SLOT $ABSM_WEBCONTEXT ($ABSM_TYPE): Deployment error check the Glassish server logs for more details."
				fi
			elif [ $(date +"%s") -gt $ENDTIMESTAMP ]
			then
				# Remove line from deploylist
				sed -i "/$ABSM_WEBNAME/d" $DEPLOYLIST
				
				# Add with SNMPFAILED status to DEPLOYLIST
				echo "SNMPFAILED $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_TYPE $ABSM_SLOT $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT" >> $DEPLOYLIST
				echo "- $ABSM_SERVERNAME slot $ABSM_SLOT $ABSM_WEBCONTEXT ($ABSM_TYPE): The underlying application server ($ABSM_CONNAPPSRV slot $ABSM_CONNAPPSLOT) did not repond successfully on the SNMP check."
			fi
		done
			
		# Check if the deploylist is empty. If so the while loop will be broken away from
		[ $(cat $DEPLOYLIST | awk -v a="DEPLOY" '$1==a  { print $0 } ' | wc -l) -eq 0 ] && break
	done
			
	# Remove PIDFILE and deploylist
	if [ $(cat $DEPLOYLIST | wc -l) -eq 0 ] 
	then
		absmenu_logline "Successfull web deploy on the server $ABSM_SERVERNAME slot $ABSM_SLOT"
	else
		DEPLOYMESSAGE="Unsuccessfull web deploy on the server $ABSM_SERVERNAME slot $ABSM_SLOT"
		[ $(cat $DEPLOYLIST |  awk -v a="DEPLOYFAILED" '$1==a { print $0 } ' | wc -l) -gt 0 ] && DEPLOYMESSAGE="$DEPLOYMESSAGE. Deployment error on $(cat $DEPLOYLIST |  awk -v a="DEPLOYFAILED" '$1==a { printf "%s ", $4 } ')"
		[ $(cat $DEPLOYLIST |  awk -v a="SNMPFAILED" '$1==a { print $0 } ' | wc -l) -gt 0 ] && DEPLOYMESSAGE="$DEPLOYMESSAGE. SNMP dependency error on $(cat $DEPLOYLIST |  awk -v a="SNMPFAILED" '$1==a { printf "%s ", $4 } ')"
		absmenu_logline "$DEPLOYMESSAGE"
	fi
	absmenu_logline "Finished installation of the webserver with the PID file: $PIDFILE (logfile = $ABSMSCRIPTLOGNAME)"
	rm $PIDFILE
}

# Check if glassfish is present, and if it is the correct version. If not a reinstall will be performed. When it is installed the domain will be clean up
install_cleanup_glassfish()
{
	# $1 Environment
	# $2 Remote server
	# $3 Slot number
	
	ABSM_ENVIRONMENT=$1
	ABSM_SERVERNAME=$2
	ABSM_SLOT=$3
	
	grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk -v a="$ABSM_SERVERNAME" -v b="$ABSM_SLOT" '$2==a && $5==b && $4!="app" && $4!="rep" { print $0 } ' | head -1 | while read ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_DBSERVERNAME ABSM_DBDRIVERTYPE ABSM_DBPORTNUMBER ABSM_HEAPSPACE ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_EXCLUDECUSTREP ABSM_GF_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
    do
		# Sync Server Libs if needed
		# ABSM_GF_VERSION is the version set in service_reg file (5 for payara)
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib
		else
			ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib"
		fi
		if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
		then
			rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server
		else
			ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server"
		fi
		
		if [ "$ABSM_GF_VERSION" == "5" ] 
		then 
			export WEBSRVNAME="payara"
		else 
			export WEBSRVNAME="glassfish"
		fi
		# Check if glassfish is present, and if it is the correct version
		
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			if [ -e $ABSM_LOCAL_HOME/$GLASSFISHPATH/bin/asadmin ]
			then
				# Check version of installed glassfish
				INSTALLED_GF_VERSION=`$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c showversion`
				[ "$INSTALLED_GF_VERSION" == "$ABSM_GF_VERSION" ] && ABSM_REFRESH_GF_INSTALL=no || ABSM_REFRESH_GF_INSTALL=upgrade
			else
				ABSM_REFRESH_GF_INSTALL=install
			fi

			if [ $ABSM_REFRESH_GF_INSTALL != no ]
			then
				# correct glassfish not found, so deploy glassfish and create domain
				[ $ABSM_REFRESH_GF_INSTALL == install ] && absmenu_logline "Installing glassfish $ABSM_GF_VERSION"
				[ $ABSM_REFRESH_GF_INSTALL == upgrade ] && absmenu_logline "Upgrade glassfish $INSTALLED_GF_VERSION to $ABSM_GF_VERSION"
				
				mkdir -p $ABSM_LOCAL_HOME

				if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
				then
					rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME
				else
					ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME";
				fi

				pushd $ABSM_LOCAL_HOME
				
				# if upgrading glassfish to a different version, first stop gf and remove completely
				if [ $ABSM_REFRESH_GF_INSTALL == upgrade ]
				then
					$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c stop
					rm -Rf $ABSM_LOCAL_HOME/$GLASSFISHPATH
				fi

				unzip ${WEBSRVNAME}_$ABSM_GF_VERSION.zip
				cd $ABSM_LOCAL_HOME/$GLASSFISHPATH
				chmod a+x mq/bin/* bin/* glassfish/config/* glassfish/bin/* javadb/bin/* pkg/lib/*
				rm -f $ABSM_LOCAL_HOME/${WEBSRVNAME}_$ABSM_GF_VERSION.zip

				$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c enable
				$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN
				$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN
				
				popd
			else
				absmenu_logline "Recreate domains for webserver (cleanup)"
				
				$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN
				$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN
			fi
			$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c start
		else
			if [ `ssh -q -n $ABSM_SERVERNAME "[ -e $ABSM_LOCAL_HOME/$GLASSFISHPATH/bin/asadmin ] && echo 1"` ]
			then
				# Check version of installed glassfish
				GF_VERSION=`ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c showversion"`
				[ "$GF_VERSION" == "$ABSM_GF_VERSION" ] && ABSM_REFRESH_GF_INSTALL=no || ABSM_REFRESH_GF_INSTALL=upgrade
			else
				ABSM_REFRESH_GF_INSTALL=install
			fi
			if [ "$ABSM_REFRESH_GF_INSTALL" != "no" ]
			then
				# create glassfish + domain
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "mkdir -p $ABSM_LOCAL_HOME"
				echo -n .
				ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME";
				echo -n .
				if [ $ABSM_REFRESH_GF_INSTALL == upgrade ]
				then
					absmenu_logline "Upgrade ${WEBSRVNAME} $INSTALLED_GF_VERSION to $ABSM_GF_VERSION"
					ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c stop; rm -Rf $ABSM_LOCAL_HOME/$GLASSFISHPATH"
					echo -n .
				else
					absmenu_logline "Installing ${WEBSRVNAME} $ABSM_GF_VERSION"
				fi
				ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME; unzip ${WEBSRVNAME}_$ABSM_GF_VERSION.zip"
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/$GLASSFISHPATH; chmod a+x mq/bin/* bin/* glassfish/config/* glassfish/bin/* javadb/bin/* pkg/lib/*"
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/${WEBSRVNAME}_$ABSM_GF_VERSION.zip"
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c enable"
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN"
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN"
				echo .
			else
				absmenu_logline "Recreate domains for ${WEBSRVNAME} webserver (cleanup)"

				ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN"
				ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN"
			fi
			ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c start"
		fi
	done
}

# Check the status of the glassfish domain. Running equals return code 0. Anything but running is return code 1
check_web_domainstatus()
{
	# $1 Environment
	# $2 Remote server
	# $3 Slot number
	
	ABSM_ENVIRONMENT=$1
	ABSM_SERVERNAME=$2
	ABSM_SLOT=$3
	ABSM_GFDOMAIN=$(grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk -v a="$ABSM_SERVERNAME" -v b="$ABSM_SLOT" '$2==a && $5==b && $4!="app" && $4!="rep" { print $19 } ' | sort -u)
	
	if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
		STATUS=$($ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c statusdomain -b $ABSM_GFDOMAIN | tail -1)
	else
		STATUS=$(ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c statusdomain -b $ABSM_GFDOMAIN | tail -1")
	fi
	
	[ "$STATUS" == "running" ] && return 0
	return 1
}

# Function to create WAR files in the repository location $ABSMENU/repository/WEB for uploading to the webservers
create_repository_warfiles()
{
	# $1 = Environment
	ABSM_ENVIRONMENT=$1
	absmenu_logline "Creating WAR files in the repository"
	grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | awk '$4!="app" && $4!="rep" { print $4 } ' | sort -u | while read ABSM_TYPE  
	do
		if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
		then
			[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE
			[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war
			pushd $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE
			zip -r ../$ABSM_TYPE.war *
			popd
		else
			ssh -q -n $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE"
			ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war"
			ssh -q -n $ABSMENUREPOSITORYSERVER "cd $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE; zip -r ../$ABSM_TYPE.war *;"
		fi
		absmenu_logline "     ) WAR file for $ABSM_TYPE created in the repository"
	done
}

# Function to delete WAR files in the repository location $ABSMENU/repository/WEB
remove_repository_warfiles()
{
	# $1 = Environment
	ABSM_ENVIRONMENT=$1
	absmenu_logline "Removing WAR files from the repository"
	grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | awk '$4!="app" && $4!="rep" { print $4 } ' | sort -u | while read ABSM_TYPE  
	do
		if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
		then
			rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war
		else
			ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war"
		fi
		absmenu_logline "     ) WAR file for $ABSM_TYPE removed from the repository"
	done
}

# Move web applications to the server and generate server specific warfile on the server
create_server_warfiles()
{
	# $1 = Environment
	# $2 = ABSM_SERVERNAME
	# $3 = ABSM_SLOT
	
	ABSM_ENVIRONMENT=$1
	ABSM_SERVERNAME=$2
	ABSM_SLOT=$3

	grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk -v a="$ABSM_SERVERNAME" -v b="$ABSM_SLOT" '$2==a && $5==b && $4!="app" && $4!="rep" { print $0 } ' | while read ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_DBSERVERNAME ABSM_DBDRIVERTYPE ABSM_DBPORTNUMBER ABSM_HEAPSPACE ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_EXCLUDECUSTREP ABSM_GF_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
    do
		# 1) copy custom jar
		if [ "$ABSM_TYPE" == wpo ]
		then
			if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
			then
				[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/$GLASSFISHPATH/glassfish/domains/$ABSM_GFDOMAIN/lib/applibs
			else
				ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/$GLASSFISHPATH/glassfish/domains/$ABSM_GFDOMAIN/lib/applibs"
			fi
		fi
		if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ]
		then
			if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
			then
				[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy
				[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy
			else
				ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy"
				ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
			fi
		fi

		# 2) sync files to the glassfish server deploy folder
		absmenu_logline "    1) Syncing files from $ABSMENUREPOSITORYSERVER:$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE to $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
		echo "Syncing files from $ABSMENUREPOSITORYSERVER:$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE to $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy
		else
			ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy"
		fi

		# 2.1 Send created war file (create_warfiles) in repository location to the deploy folder and clean up
		if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
		then
			if [ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ]
			then
				rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy
			fi
		else
			echo -n .
			ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
			echo -n .
		fi
		
		# 2.2 (re)create deploy dirs (wpo/gws/ws2/w4m/wp2/wsr/wum/wcl/wua/wrd/wrr/wsb/wmr/wfb) and unzip war in the new dir. 
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			pushd $ABSM_LOCAL_HOME/deploy
			[ -d $ABSM_TYPE ] && rm -Rf $ABSM_TYPE
			mkdir $ABSM_TYPE
			cd $ABSM_TYPE
			unzip ../$ABSM_TYPE.war
			rm -f ../$ABSM_TYPE.war
			[ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xml-apis*.jar $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xercesImpl*.jar 2> /dev/null
			popd
			
			# process custom wp2 files
			if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ] 
			then
				unzip -o $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB -d $ABSM_LOCAL_HOME/deploy/wp2/resources/abs/1_0/
				rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB
				ABSM_WEBLIB="X"
			fi
			
			if [ "$ABSAPPSERVER" ] # copy patchserver.jar, resourcefiles and log4j and snmp sample config from appserver
			then
				[ ! -d $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs ] && mkdir -p $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
				if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
				then
					rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
					[ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
					rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF
					rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF
				else
					echo -n .
					ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
					echo -n .
					[ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
					echo -n .
					ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
					echo -n .
					ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
					echo .
				fi
			fi
		else
			echo -n .
			ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy; [ -d $ABSM_TYPE ] && rm -Rf $ABSM_TYPE"
			echo -n .
			ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy; mkdir $ABSM_TYPE; cd $ABSM_TYPE; unzip ../$ABSM_TYPE.war; rm -f ../$ABSM_TYPE.war"
			echo .
			[ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xml-apis*.jar $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xercesImpl*.jar 2> /dev/null"

			# process custom wp2 files
			if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ] 
			then
				ssh -q -n $ABSM_SERVERNAME "unzip -o $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB -d $ABSM_LOCAL_HOME/deploy/wp2/resources/abs/1_0/"
				ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB"
				ABSM_WEBLIB="X"
			fi		
			
			if [ "$ABSAPPSERVER" ] # copy patchserver.jar, resourcefiles and log4j and snmp sample config from appserver
			then
				echo -n .
				ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs ] && mkdir -p $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
				echo -n .
				ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
				echo -n .
				[ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
				echo -n .
				ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
				echo -n .
				ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
				echo .
			fi
		fi
		
		# 3) generate properties
		absmenu_logline "    2) Generating properties in $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE"
		echo "Generating properties in $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE"
		. $ABSMENUPATH/bin/generate_properties.sh web normal "$ABSMENU_CURRENT_ENVIRONMENT" "$ABSM_TYPE" "$ABSM_SERVERNAME" "$ABSM_SLOT" "$ABSM_LOCAL_HOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_STATIONNR" "$ABSM_CONNAPPSRV" "$ABSM_CONNAPPSLOT" "$ABSM_CONNREPSRV" "$ABSM_CONNREPSLOT" "$ABSM_WEBNAME" "$ABSM_ORATNS" "$ABSM_ORAHOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_USENATIVE" "$ABSM_INET_KEY" "$ABSM_GFDOMAIN" "$ABSM_USER2" "$ABSM_PWD2" "$ABSM_STATIONNR2" "$ABSM_DBSERVERNAME" "$ABSM_DBDRIVERTYPE" "$ABSM_DBPORTNUMBER"
		
		# 5) create new war-file
		absmenu_logline "    3) Generating war-file $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war"
		echo "Generating war-file $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war"
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			[ -e $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war
			pushd $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE
			zip -r -q $ABSM_WEBNAME.war *
			popd
		else
			echo -n .
			ssh -q -n $ABSM_SERVERNAME "[ -e $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war"
			echo -n .
			ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE; zip -r -q $ABSM_WEBNAME.war *"
			echo .
		fi
	done
}

# Move web application to the server
deploy_server_warfiles()
{
	# $1 = Environment
	# $2 = ABSM_SERVERNAME
	# $3 = ABSM_TYPE
	# $4 = ABSM_SLOT
	# $5 = ABSM_WEBNAME
	# $6 = ABSM_GFDOMAIN
	# $7 = ABSM_WEBCONTEXT
	# $8 = ABSM_WEBLIB
	
	ABSM_ENVIRONMENT=$1
	ABSM_SERVERNAME=$2
	ABSM_TYPE=$3
	ABSM_SLOT=$4
	ABSM_WEBNAME=$5
	ABSM_GFDOMAIN=$6
	ABSM_WEBCONTEXT=$7
	ABSM_WEBLIB=$8
	
	absmenu_logline "Deploying WAR file $ABSM_WEBNAME.war for the $ABSM_TYPE web application on the server $ABSM_SERVERNAME"
	echo "Deploy $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$ABSM_WEBNAME.war"
	
	TMPWEBLIB=$ABSM_WEBLIB
	[ "$ABSM_TYPE" == "wp2" ] && TMPWEBLIB="X"
	
	if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
	then
		$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deploy -b $ABSM_GFDOMAIN -w $ABSM_TYPE:$ABSM_WEBNAME:$ABSM_WEBCONTEXT:$TMPWEBLIB
	else
		ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deploy -b $ABSM_GFDOMAIN -w $ABSM_TYPE:$ABSM_WEBNAME:$ABSM_WEBCONTEXT:$TMPWEBLIB"
	fi
	return $?
}

# update web components
updateweb()
{
# 1) check if glassfish is present. If not, deploy and create domain
# 2) copy custom jar and server LIBs if needed
# 3) sync files to the glassfish server deploy folder
#    3.1) zip repository location, send it to the deploy folder and clean up
#    3.2) (re)create empty deploy dir (wpo/gws/ws2/w4m/wp2/wsr/wum/wmr/wfb) and unzip in the new dir
# 4) generate properties
# 5) create new war-file
# 6) make sure the glassfish domain is running
# 7) deploy new war

	if [ "$ABSM_GF_VERSION" == "5" ] 
	then 
		export WEBSRVNAME="payara"
	else 
		export WEBSRVNAME="glassfish"
	fi
	
    export ABSMESSAGE="Updating ${WEBSRVNAME} web"
    absmenu_log

    GFADMINPORT="5"$ABSM_SLOT"34"
    [ ${#GFADMINPORT} == "4" ] && GFADMINPORT="50"$ABSM_SLOT"34"

    WEBNAME="$ABSM_WEBNAME"
    case "$ABSM_TYPE" in
        wpo)    WEBTYPE="web portal";;
        gws)    WEBTYPE="generic webservice";;
        ws2)    WEBTYPE="webservice2";;
        w4m)    WEBTYPE="mobile app webservice";;
        wp2)    WEBTYPE="new web portal";;
        wsr)    WEBTYPE="REST webservice";;
		wum)    WEBTYPE="uhf monitor";;
		wua)    WEBTYPE="webclient my uniform assistant";;
		wrd)    WEBTYPE="webclient residential delivery";;
		wrr)    WEBTYPE="webclient route returns";;
        wsb)    WEBTYPE="webclient replace smart barcode";;
        wfb)    WEBTYPE="absmobilefirebaseservices";;
        wmr)    WEBTYPE="Mobile RestService";;
		wcl)    WEBTYPE="web client"
    esac
    echo "Deploying binaries for the $WEBTYPE web application on ${WEBSRVNAME} server $ABSM_SERVERNAME, slot $ABSM_SLOT"

    # 1) check if glassfish is present, and if it is the correct version
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        if [ -e $ABSM_LOCAL_HOME/$GLASSFISHPATH/bin/asadmin ]
        then
            # Check version of installed glassfish
            INSTALLED_GF_VERSION=`$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c showversion`
            [ "$INSTALLED_GF_VERSION" == "$ABSM_GF_VERSION" ] && ABSM_REFRESH_GF_INSTALL=no || ABSM_REFRESH_GF_INSTALL=upgrade
        else
            ABSM_REFRESH_GF_INSTALL=install
        fi

        if [ $ABSM_REFRESH_GF_INSTALL != no ]
        then
            # correct glassfish not found, so deploy glassfish and create domain
			export ABSMESSAGE="correct glassfish not found, so deploy glassfish and create domain"
			absmenu_log
            [ $ABSM_REFRESH_GF_INSTALL == install ] && export ABSMESSAGE="Installing ${WEBSRVNAME} $ABSM_GF_VERSION"; absmenu_log
            [ $ABSM_REFRESH_GF_INSTALL == upgrade ] && export ABSMESSAGE="Upgrade ${WEBSRVNAME} $INSTALLED_GF_VERSION to $ABSM_GF_VERSION"; absmenu_log
            
            mkdir -p $ABSM_LOCAL_HOME

            if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
            then
                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME
            else
                ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME";
            fi

            pushd $ABSM_LOCAL_HOME
            
            # if upgrading glassfish to a different version, first stop gf and remove completely
            if [ $ABSM_REFRESH_GF_INSTALL == upgrade ]
            then
                $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c stop
                rm -Rf $ABSM_LOCAL_HOME/$GLASSFISHPATH
            fi

            unzip ${WEBSRVNAME}_$ABSM_GF_VERSION.zip
            cd $ABSM_LOCAL_HOME/$GLASSFISHPATH
            chmod a+x mq/bin/* bin/* glassfish/config/* glassfish/bin/* javadb/bin/* pkg/lib/*
            rm -f $ABSM_LOCAL_HOME/${WEBSRVNAME}_$ABSM_GF_VERSION.zip

            $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c enable
            $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN
            $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN
            
            popd
        fi
    else
        if [ `ssh -q -n $ABSM_SERVERNAME "[ -e $ABSM_LOCAL_HOME/$GLASSFISHPATH/bin/asadmin ] && echo 1"` ]
        then
            # Check version of installed glassfish
            GF_VERSION=`ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c showversion"`
            [ "$GF_VERSION" == "$ABSM_GF_VERSION" ] && ABSM_REFRESH_GF_INSTALL=no || ABSM_REFRESH_GF_INSTALL=upgrade
        else
            ABSM_REFRESH_GF_INSTALL=install
        fi
        if [ "$ABSM_REFRESH_GF_INSTALL" != "no" ]
        then
            # create glassfish + domain
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "mkdir -p $ABSM_LOCAL_HOME"
            echo -n .
            ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/${WEBSRVNAME}_$ABSM_GF_VERSION.zip $ABSM_SERVERNAME:$ABSM_LOCAL_HOME";
            echo -n .
            if [ $ABSM_REFRESH_GF_INSTALL == upgrade ]
            then
                ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c stop; rm -Rf $ABSM_LOCAL_HOME/$GLASSFISHPATH"
                echo -n .
            fi
            ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME; unzip ${WEBSRVNAME}_$ABSM_GF_VERSION.zip"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/$GLASSFISHPATH; chmod a+x mq/bin/* bin/* glassfish/config/* glassfish/bin/* javadb/bin/* pkg/lib/*"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/${WEBSRVNAME}_$ABSM_GF_VERSION.zip"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c enable"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN"
            echo .
        fi
    fi

	# 2) copy custom jar and server LIBs if needed
	if [ "$ABSM_TYPE" == wpo ]
    then
        if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
        then
            [ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/$GLASSFISHPATH/glassfish/domains/$ABSM_GFDOMAIN/lib/applibs
        else
            ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/$GLASSFISHPATH/glassfish/domains/$ABSM_GFDOMAIN/lib/applibs"
        fi
    fi
	if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ]
    then
        if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
        then
			[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy
            [ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy
        else
			ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy"
            ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
        fi
    fi
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        [ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib
    else
        ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib"
    fi
    if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
    then
        rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server
    else
        ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server"
    fi

    # 3) sync files to the glassfish server deploy folder
    export ABSMESSAGE="    1) Syncing files from $ABSMENUREPOSITORYSERVER:$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE to $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
    absmenu_log
    echo "Syncing files from $ABSMENUREPOSITORYSERVER:$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE to $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        [ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy
    else
        ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy ] && mkdir -p $ABSM_LOCAL_HOME/deploy"
    fi

	# 3.1 create war in repository location, send it to the deploy folder and clean up
    if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
    then
        [ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE
        [ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war
        pushd $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE
        zip -r ../$ABSM_TYPE.war *
        if [ -e ../$ABSM_TYPE.war ]
        then
            rsync -tav --delete -e "ssh -q" ../$ABSM_TYPE.war $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy
            rm -f ../$ABSM_TYPE.war
        fi
        popd
    else
        echo -n .
        ssh -q -n $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE"
        echo -n .
        ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war"
        echo -n .
        ssh -q -n $ABSMENUREPOSITORYSERVER "cd $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE; zip -r ../$ABSM_TYPE.war *;"
        echo -n .
        ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy"
        echo -n .
        ssh -q -n $ABSMENUREPOSITORYSERVER "[ -e $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war ] && rm -f $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/$ABSM_TYPE.war"
        echo .
	fi
    
	# 3.2 (re)create deploy dirs (wpo/gws/ws2/w4m/wp2/wsr/wum/wcl/wua/wrd/wrr/wsb/wmr/wfb) and unzip war in the new dir. 
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        pushd $ABSM_LOCAL_HOME/deploy
        [ -d $ABSM_TYPE ] && rm -Rf $ABSM_TYPE
        mkdir $ABSM_TYPE
        cd $ABSM_TYPE
        unzip ../$ABSM_TYPE.war
        rm -f ../$ABSM_TYPE.war
        [ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xml-apis*.jar $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xercesImpl*.jar 2> /dev/null
        popd
		
		# process custom wp2 files
		if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ] 
		then
			unzip -o $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB -d $ABSM_LOCAL_HOME/deploy/wp2/resources/abs/1_0/
			rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB
			ABSM_WEBLIB="X"
		fi
		
        if [ "$ABSAPPSERVER" ] # copy patchserver.jar, resourcefiles and log4j and snmp sample config from appserver
        then
            [ ! -d $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs ] && mkdir -p $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
            if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
            then
                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
                [ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs
                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF
                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF
            else
                echo -n .
                ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
                echo -n .
                [ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
                echo -n .
                ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
                echo -n .
                ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
                echo .
            fi
        fi
    else
        echo -n .
        ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy; [ -d $ABSM_TYPE ] && rm -Rf $ABSM_TYPE"
        echo -n .
        ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy; mkdir $ABSM_TYPE; cd $ABSM_TYPE; unzip ../$ABSM_TYPE.war; rm -f ../$ABSM_TYPE.war"
        echo .
        [ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xml-apis*.jar $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/xercesImpl*.jar 2> /dev/null"

		# process custom wp2 files
		if [ -f $ABSMENUREPOSITORYLOCATION/static_zips/$ABSM_WEBLIB ] && [ "$ABSM_TYPE" == "wp2" ] 
		then
			ssh -q -n $ABSM_SERVERNAME "unzip -o $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB -d $ABSM_LOCAL_HOME/deploy/wp2/resources/abs/1_0/"
			ssh -q -n $ABSM_SERVERNAME "rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_WEBLIB"
			ABSM_WEBLIB="X"
		fi		
		
        if [ "$ABSAPPSERVER" ] # copy patchserver.jar, resourcefiles and log4j and snmp sample config from appserver
        then
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs ] && mkdir -p $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
            echo -n .
            ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/patchserver*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
            echo -n .
            [ "$ABSM_TYPE" == "wpo" -o "$ABSM_TYPE" == "wp2" ] && ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib/resource*.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF/lib/abs"
            echo -n .
            ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_AbsSnmpAgentSettings.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
            echo -n .
            ssh -q -n $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_log4j.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/WEB-INF"
            echo .
        fi
    fi
    
    # 4) generate properties
    export ABSMESSAGE="    2) Generating properties in $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE"
    absmenu_log
    echo "Generating properties in $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE"
    . $ABSMENUPATH/bin/generate_properties.sh web normal "$ABSMENU_CURRENT_ENVIRONMENT" "$ABSM_TYPE" "$ABSM_SERVERNAME" "$ABSM_SLOT" "$ABSM_LOCAL_HOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_STATIONNR" "$ABSM_CONNAPPSRV" "$ABSM_CONNAPPSLOT" "$ABSM_CONNREPSRV" "$ABSM_CONNREPSLOT" "$WEBNAME" "$ABSM_ORATNS" "$ABSM_ORAHOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_USENATIVE" "$ABSM_INET_KEY" "$ABSM_GFDOMAIN" "$ABSM_USER2" "$ABSM_PWD2" "$ABSM_STATIONNR2" "$ABSM_DBSERVERNAME" "$ABSM_DBDRIVERTYPE" "$ABSM_DBPORTNUMBER"
    
    # 5) create new war-file
    export ABSMESSAGE="    3) Generating war-file $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war"
    absmenu_log
    echo "Generating war-file $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war"
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        [ -e $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war
        pushd $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE
        zip -r -q $WEBNAME.war *
        popd
    else
        echo -n .
        ssh -q -n $ABSM_SERVERNAME "[ -e $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war ] && rm -f $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war"
        echo -n .
        ssh -q -n $ABSM_SERVERNAME "cd $ABSM_LOCAL_HOME/deploy/$ABSM_TYPE; zip -r -q $WEBNAME.war *"
        echo .
    fi

    # 6) make sure the glassfish domain is running
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c start -b $ABSM_GFDOMAIN -y 20
    else
        ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c start -b $ABSM_GFDOMAIN -y 20"
    fi

    # 7) deploy new version
    export ABSMESSAGE="    4) Deploy $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war"
    absmenu_log
    echo "Deploy $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/deploy/$ABSM_TYPE/$WEBNAME.war"
    if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
    then
        $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deploy -b $ABSM_GFDOMAIN -w $ABSM_TYPE:$WEBNAME:$ABSM_WEBCONTEXT:$ABSM_WEBLIB
    else
        ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deploy -b $ABSM_GFDOMAIN -w $ABSM_TYPE:$WEBNAME:$ABSM_WEBCONTEXT:$ABSM_WEBLIB"
    fi
}

# recreate domains for webservers so you always start clean
cleanup_webservers()
{
	# $1 = environment
	TMPDIR=$ABS_ROOTDIR/tmp
	TMPFILE=$TMPDIR/weblist.abs

	export ABSMESSAGE="     Recreate domains for webservers (cleanup)"
    absmenu_log
    echo 'Recreate domains for webservers if present (cleanup)'
	
	# empty list
	[ ! -d $TMPDIR ] && mkdir $TMPDIR
	[ -e $TMPFILE ] && rm -f $TMPFILE
	touch $TMPFILE
	
	# make a list of all web server/slot combinations in the chosen environment
    grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | while read ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_DBSERVERNAME ABSM_DBDRIVERTYPE ABSM_DBPORTNUMBER ABSM_HEAPSPACE ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_EXCLUDECUSTREP ABSM_GF_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
    do
        case "$ABSM_TYPE" in 
            wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wmr|wfb)   echo $ABSM_SERVERNAME $ABSM_SLOT $ABSM_GFDOMAIN >> $TMPFILE;;
        esac
	done

	# go through the list and re-create glassfish domains
	sort $TMPFILE | uniq | while read ABSM_SERVERNAME ABSM_SLOT ABSM_GFDOMAIN
    do
        if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
        then
            $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN
            sleep 10
            $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN
        else
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "$ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c deletedomain -b $ABSM_GFDOMAIN"
            echo -n .
            ssh -q -n $ABSM_SERVERNAME "sleep 10; $ABS_ROOTDIR/abs.sh -s $ABSM_SLOT -t glass -c createdomain -b $ABSM_GFDOMAIN"
            echo .
        fi
	done
	rm -f $TMPFILE
}

# Function to synchronise the custom maximal heapspace value to the slot
synchronise_heapspace()
{	
	if [ "$ABSM_HEAPSPACE" == "X" ]
	then
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -t $ABSM_TYPE -c resetheap
		else
			ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -t $ABSM_TYPE -c resetheap"
		fi
	elif [[ ! $ABSM_HEAPSPACE =~ [^[:digit:]] ]]
	then
		if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
		then
			cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -t $ABSM_TYPE -M $ABSM_HEAPSPACE -c maxheap 
		else
			ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -t $ABSM_TYPE -M $ABSM_HEAPSPACE -c maxheap" 
		fi
	fi	
}

binrep_updateloop()
{
# $1 - environment
# $2 - all / reports / license (preselection) / heapsize
# $3 - app / rep / client / web / lic

	# recreate domains for webservers so you always start clean
	# has to be done outside the "while read" loop so it gets done only once
	[ "$3" == "web" ] && cleanup_webservers $1 

    grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | while read ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_DBSERVERNAME ABSM_DBDRIVERTYPE ABSM_DBPORTNUMBER ABSM_HEAPSPACE ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_EXCLUDECUSTREP ABSM_GF_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
    do
        FILTER_OK=no
        if [ "$2" == "license" ]
        then
            FILTER_OK=yes
        else
            case "$ABSM_TYPE" in
                app|rep|client)             		[ "$3" == "$ABSM_TYPE" ] && FILTER_OK=yes;;
                wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wmr|wfb|glass)  [ "$3" == "web" ] && FILTER_OK=yes;;
            esac
        fi
        if [ "$FILTER_OK" == "yes" ]
        then
            export ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_GF_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
            if [ "$2" == "license" ]    # sync licenses for app- and rep-servers
            then
                case "$ABSM_TYPE" in
                	app)    export ABSMESSAGE="     Copying new license to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME"; absmenu_log
                            echo "Copying new license to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME"
                            if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
                            then
								export ABSMESSAGE="     Copying new dialogs to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME from $ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/"; absmenu_log
                                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
								export ABSMESSAGE="     Copying new license to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME from $ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/"; absmenu_log
                                rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
                            else
                                export ABSMESSAGE="     Copying new dialogs to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME from $ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/"; absmenu_log
                                ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
                                export ABSMESSAGE="     Copying new license to $ABSM_LOCAL_HOME/Server/License on server $ABSM_SERVERNAME from $ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/"; absmenu_log
                                ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
                            fi;;
                	rep)    export ABSMESSAGE="     Applying Reportserver license to in $ABSM_LOCAL_HOME on server $ABSM_SERVERNAME"; absmenu_log
                            echo "Applying Reportserver license to in $ABSM_LOCAL_HOME on server $ABSM_SERVERNAME"
                            CRYSTALCLEARFILE="$ABSM_LOCAL_HOME/Reportserver/Config/crystalclear.properties"
							APPSERVERCOUNT=$(grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | awk -v a="$ABSM_SERVERNAME" ' $2!=a && $4=="app" { print $0 } ' | wc -l)
                            if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
                            then
								[ $APPSERVERCOUNT -eq 0 ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
								[ $APPSERVERCOUNT -eq 0 ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
								sed -i "/^licensekey=/ c\licensekey=$ABSM_INET_KEY" $CRYSTALCLEARFILE
                            else
								[ $APPSERVERCOUNT -eq 0 ] && ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
                                [ $APPSERVERCOUNT -eq 0 ] && ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
                                ssh -n -q $ABSM_SERVERNAME "sed -i '/^licensekey=/ c\licensekey=$ABSM_INET_KEY' $CRYSTALCLEARFILE"
                            fi;;
                esac
			elif [ "$2" == "heapspace" ]
			then
				synchronise_heapspace &> /dev/null
            else
                if [ "$2" == "reports" ] # sync reports and fonts only
                then
                    if [ "$ABSM_TYPE" == "rep" ]
                    then
                        export ABSMESSAGE="     Replicating reports and fonts for report server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"; absmenu_log
                        echo "Replicating reports and fonts for report server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
                        if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
                        then
                            [ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts
                            if [ "$ABSM_EXCLUDECUSTREP" == "true" ] 
							then 
								rsync --exclude 'CUSTOMER' -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver
								rsync --exclude 'CUSTOMER' -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports
							else
								rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver
								rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports
							fi
                        else
                            ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts"
                            if [ "$ABSM_EXCLUDECUSTREP" == "true" ] 
							then 
								ssh -n -q $ABSMENUREPOSITORYSERVER "rsync --exclude 'CUSTOMER'  -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver"
								ssh -n -q $ABSMENUREPOSITORYSERVER "rsync --exclude 'CUSTOMER'  -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports"
                        	else
								ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver"
								ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports"
                        	fi
						fi
                    fi
                else 
                    if [ "$ABSM_TYPE" == "client" ]
                    then
                        # update client distribution
                        export ABSMESSAGE="Updating CLIENT distrib"; absmenu_log
                        export ABSMESSAGE="     Replicating binaries for client distribution for $ABSM_SERVERNAME slot $ABSM_SLOT"
                        absmenu_log
                        echo "Replicating binaries for client distribution for $ABSM_SERVERNAME slot $ABSM_SLOT"
                        # 1) check if distrib exists. no --> create
                        #    server   : $ABSM_CLIENTDISTR_SRV 
                        #    directory: $ABSM_CLIENTDISTR_DIR
                        if [ "$ABS_ROOTSERVER" == "$ABSM_CLIENTDISTR_SRV" ] 
                        then
                            [ ! -d "$ABSM_CLIENTDISTR_DIR" ] && mkdir -p "$ABSM_CLIENTDISTR_DIR"
                        else
                            ssh -n -q "$ABSM_CLIENTDISTR_SRV" "[ ! -d \"$ABSM_CLIENTDISTR_DIR\" ] && mkdir -p \"$ABSM_CLIENTDISTR_DIR\""
                        fi
                        # 2) check if distrib exists. no --> message and stop trying
                        CLIENTDISTRIBOK=N
                        if [ "$ABS_ROOTSERVER" == "$ABSM_CLIENTDISTR_SRV" ] 
                        then
                            [ -d $ABSM_CLIENTDISTR_DIR ] && CLIENTDISTRIBOK=Y
                        else
                            CLIENTDISTRIBOK=`ssh -n -q "$ABSM_CLIENTDISTR_SRV" "if [ -d \"$ABSM_CLIENTDISTR_DIR\" ]; then echo Y; else echo N; fi"`
                        fi
                        # 3) rsync client to distrib
                        if [ "$CLIENTDISTRIBOK" == "Y" ]
                        then
                            # 3.1) sync binaries to distrib share
                            if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
                            then
                                rsync -tav --delete -e "ssh -q" "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Client" "$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR"
                                rsync -tav --delete -e "ssh -q" "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Server" "$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR"
                                rsync -tav -e "ssh -q" "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Users" "$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR"
                            else
                                ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Client\" \"$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR\""
                                ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Server\" \"$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR\""
                                ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Client/Users\" \"$ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR\""
                            fi
                            
                            # 3.2) generate clientserver.sh
                            if [ "$ABS_ROOTSERVER" == "$ABSM_CLIENTDISTR_SRV" ] 
                            then
                                echo '#/bin/bash'> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTAPPSRV=$ABSM_CONNAPPSRV" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTAPPSRVSLOT=$ABSM_CONNAPPSLOT" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTREPSRV=$ABSM_CONNREPSRV" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTREPSRVSLOT=$ABSM_CONNREPSLOT" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "USEDISTRIB=Y" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTDISTRIBSRV=$ABSM_CLIENTDISTR_SRV" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                echo "CLIENTDISTRIBDIR=$ABSM_CLIENTDISTR_DIR" >> "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                                chmod a+x "$ABSM_CLIENTDISTR_DIR/clientserver.sh"
                            else
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"#/bin/bash\"> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTAPPSRV=$ABSM_CONNAPPSRV\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTAPPSRVSLOT=$ABSM_CONNAPPSLOT\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTREPSRV=$ABSM_CONNREPSRV\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTREPSRVSLOT=$ABSM_CONNREPSLOT\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"USEDISTRIB=Y\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTDISTRIBSRV=$ABSM_CLIENTDISTR_SRV\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "echo \"CLIENTDISTRIBDIR=$ABSM_CLIENTDISTR_DIR\" >> \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo -n .
                                ssh -n -q $ABSM_CLIENTDISTR_SRV "chmod a+x \"$ABSM_CLIENTDISTR_DIR/clientserver.sh\""
                                echo .
                            fi
                        else
                            export ABSMESSAGE="     Problem creating client distribution location $ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR"
                            absmenu_log
                            echo "Problem creating client distribution $ABSM_CLIENTDISTR_SRV:$ABSM_CLIENTDISTR_DIR"
                        fi
                    else
                        # normal (full) update
                        case "$ABSM_TYPE" in 
							app)       		                export ABSMESSAGE="     Replicating binaries for application server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
															absmenu_log
															echo "Replicating binaries for application server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
															if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
															then
																[ ! -d $ABSM_LOCAL_HOME/Server/Config ] && mkdir -p $ABSM_LOCAL_HOME/Server/Config
																[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib
																[ ! -d $ABSM_LOCAL_HOME/Server/License ] && mkdir -p $ABSM_LOCAL_HOME/Server/License
																[ ! -d $ABSM_LOCAL_HOME/Server/Log ] && mkdir -p $ABSM_LOCAL_HOME/Server/Log
																[ ! -d $ABSM_LOCAL_HOME/Server/sqlscripts ] && mkdir -p $ABSM_LOCAL_HOME/Server/sqlscripts
															else
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Config ] && mkdir -p $ABSM_LOCAL_HOME/Server/Config"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/License ] && mkdir -p $ABSM_LOCAL_HOME/Server/License"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Log ] && mkdir -p $ABSM_LOCAL_HOME/Server/Log"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/sqlscripts ] && mkdir -p $ABSM_LOCAL_HOME/Server/sqlscripts"
																echo .
															fi
															if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
															then
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/sqlscripts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_*.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Config
															else
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/sqlscripts $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server"
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Config/sample_*.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Config"
															fi

															if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
															then
																[ -e $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar ] && rm -f $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar
															else
																ssh -n -q $ABSM_SERVERNAME "[ -e $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar ] && rm -f $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar"
															fi
															if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
															then
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib/ReportServer.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Lib
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib/reportserver.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Lib
															else
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib/ReportServer.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Lib"
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib/reportserver.jar $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/Lib"
															fi
															if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
															then
																[ ! -e $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar ] && cp -f $ABSM_LOCAL_HOME/Server/Lib/ReportServer.jar $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar
															else
																ssh -n -q $ABSM_SERVERNAME "[ ! -e $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar ] && cp -f $ABSM_LOCAL_HOME/Server/Lib/ReportServer.jar $ABSM_LOCAL_HOME/Server/Lib/reportserver.jar"
															fi

															. $ABSMENUPATH/bin/generate_properties.sh app check "$1" "$ABSM_TYPE" "$ABSM_SERVERNAME" "$ABSM_SLOT" "$ABSM_LOCAL_HOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_STATIONNR" "$ABSM_CONNAPPSRV" "$ABSM_CONNAPPSLOT" "$ABSM_CONNREPSRV" "$ABSM_CONNREPSLOT" "$WEBNAME" "$ABSM_ORATNS" "$ABSM_ORAHOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_USENATIVE" "$ABSM_INET_KEY" "$ABSM_GFDOMAIN" "$ABSM_USER2" "$ABSM_PWD2" "$ABSM_STATIONNR2" "$ABSM_DBSERVERNAME" "$ABSM_DBDRIVERTYPE" "$ABSM_DBPORTNUMBER"
															if [ -z "$ABSAPPSERVER" ]
															then
																export ABSAPPSERVER=$ABSM_SERVERNAME
																export ABSAPPSERVERLIB="$ABSM_LOCAL_HOME/Server/Lib/patchserver.jar"
															fi
															synchronise_heapspace  &> /dev/null
															;;
										
							rep)                    		export ABSMESSAGE="     Replicating binaries for report server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
															absmenu_log
															echo "Replicating binaries for report server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
															APPSERVERCOUNT=$(grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | awk -v a="$ABSM_SERVERNAME" ' $2!=a && $4=="app" { print $0 } ' | wc -l)
															if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
															then
																# Sync server libs,license is required
																if [ $APPSERVERCOUNT -eq 0 ]
																then
																	[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib
																	[ ! -d $ABSM_LOCAL_HOME/Server/License ] && mkdir -p $ABSM_LOCAL_HOME/Server/License
																	rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server
																	rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License
																fi
																[ ! -d $ABSM_LOCAL_HOME/Reportserver/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Lib
																[ ! -d $ABSM_LOCAL_HOME/Reportserver/Log ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Log
																[ ! -d $ABSM_LOCAL_HOME/Reportserver/Fonts ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Fonts
																[ ! -d $ABSM_LOCAL_HOME/Reportserver/Config ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Config
																[ ! -d $ABSM_LOCAL_HOME/Reportserver/CrReports ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/CrReports
																[ $ABSSOLUTENUMVERSION -ge 90000 -a ! -d $ABSM_LOCAL_HOME/Reportserver/Lib/plugins ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Lib/plugins
															else
																# Sync server libs,license is required
																if [ $APPSERVERCOUNT -eq 0 ]
																then
																	echo -n .
																	ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Server/Lib"
																	echo -n .
																	ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Server/License ] && mkdir -p $ABSM_LOCAL_HOME/Server/License"
																	echo .
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/License $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server"
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Server/License"
																fi
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Reportserver/Lib ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Lib"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Reportserver/Log ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Log"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Reportserver/Fonts ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Fonts"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Reportserver/Config ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Config"
																echo -n .
																ssh -n -q $ABSM_SERVERNAME "[ ! -d $ABSM_LOCAL_HOME/Reportserver/CrReports ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/CrReports"
																echo .
																ssh -n -q $ABSM_SERVERNAME "[ $ABSSOLUTENUMVERSION -ge 90000 -a ! -d $ABSM_LOCAL_HOME/Reportserver/Lib/plugins ] && mkdir -p $ABSM_LOCAL_HOME/Reportserver/Lib/plugins"
																echo .
															fi
															if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
															then
																if [ "$ABSM_EXCLUDECUSTREP" == "true" ] 
																then 
																	rsync --exclude 'CUSTOMER' -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver
																	rsync --exclude 'CUSTOMER' -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports
																else
																	rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver
																	rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports
																fi
																rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Config/sample_*.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/Config
																[ "$ABSSOLUTENUMVERSION" -ge 90000 ] && rsync -tav --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Config/datasources.xml $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/Config
															else
																if [ "$ABSM_EXCLUDECUSTREP" == "true" ] 
																then 
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync --exclude 'CUSTOMER' -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver"
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync --exclude 'CUSTOMER' -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports"
																else
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Lib $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Fonts $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/CrReports $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver"
																	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/CrReports"
																fi																
																ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Config/sample_*.properties $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/Config"
																ssh -n -q $ABSMENUREPOSITORYSERVER "[ $ABSSOLUTENUMVERSION -ge 90000 ] && rsync -tav --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/Config/datasources.xml $ABSM_SERVERNAME:$ABSM_LOCAL_HOME/Reportserver/Config"
															fi
															. $ABSMENUPATH/bin/generate_properties.sh rep check "$1" "$ABSM_TYPE" "$ABSM_SERVERNAME" "$ABSM_SLOT" "$ABSM_LOCAL_HOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_STATIONNR" "$ABSM_CONNAPPSRV" "$ABSM_CONNAPPSLOT" "$ABSM_CONNREPSRV" "$ABSM_CONNREPSLOT" "$WEBNAME" "$ABSM_ORATNS" "$ABSM_ORAHOME" "$ABSM_USER" "$ABSM_PWD" "$ABSM_USENATIVE" "$ABSM_INET_KEY" "$ABSM_GFDOMAIN"  "$ABSM_USER2" "$ABSM_PWD2" "$ABSM_STATIONNR2" "$ABSM_DBSERVERNAME" "$ABSM_DBDRIVERTYPE" "$ABSM_DBPORTNUMBER"
															synchronise_heapspace  &> /dev/null
															;;
													
                            wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wmr|wfb)   	export ABSMESSAGE="Updating WEB"; absmenu_log
													# if the ../Future/Web exists then we will perform the update. Otherwise, nothing to do
													if [ -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web ]
													then
														updateweb
													else
														export ABSMESSAGE="There is no $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/  therefore nothing to update!"; absmenu_log
													fi
													;;
                        esac
                    fi
                fi
            fi
        fi
    done
}

check_repository_for_old_junk()
{
    if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
    then
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/abskey.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/CC-Viewer.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/CrystalClear.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/CCLib.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/commons-logging-1.0.4.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/jcfield450k.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Server/junit.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/commons-digester3-3.2-with-deps.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/compass.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/adhocLoader.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/CCjetty.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/ehcache-core.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/milton-api-1.4.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/adhocClient.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/slf4j-simple-1.5.6.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/gwt-servlet.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/milton-servlet-1.4.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/TableLayout.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/jhall.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/Designer.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/jsp-api-2.0.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/mime-util.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/swing-layout.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/jortho.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/SBSTutorial.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/gwt-servlet-deps.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/CCLib.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/CCjetty-util.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/webdavclient4j-core-0.92.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/commons-httpclient-3.0.1.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/JnlpDesigner.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/commons-codec-1.3.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/jdom-1.0.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/commons-net-3.0.1.jar
        rm -f "$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT"/Future/Reportserver/lucene-core.jar
    else
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/abskey.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/CC-Viewer.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/CrystalClear.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/CCLib.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/commons-logging-1.0.4.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/jcfield450k.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Server/junit.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/commons-digester3-3.2-with-deps.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/compass.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/adhocLoader.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/CCjetty.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/ehcache-core.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/milton-api-1.4.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/adhocClient.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/slf4j-simple-1.5.6.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/gwt-servlet.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/milton-servlet-1.4.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/TableLayout.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/jhall.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/Designer.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/jsp-api-2.0.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/mime-util.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/swing-layout.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/jortho.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/SBSTutorial.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/gwt-servlet-deps.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/CCLib.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/CCjetty-util.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/webdavclient4j-core-0.92.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/commons-httpclient-3.0.1.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/JnlpDesigner.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/commons-codec-1.3.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/jdom-1.0.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/commons-net-3.0.1.jar"
        ssh -n -q "rm -f \"$ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT\"/Future/Reportserver/lucene-core.jar"
    fi
}

unset ABSAPPSERVER
export GFDEPALREADYSTARTED="no"
if [ "$2" == "reports" ]
then
    export ABSMESSAGE="Updating REP"; absmenu_log
	binrep_updateloop $1 $2 rep
elif [ "$2" == "heapspace" ]
then
	binrep_updateloop $1 $2 app
	binrep_updateloop $1 $2 rep
else
    if [ "$2" == "license" ]
    then
        export ABSMESSAGE="Updating licenses"; absmenu_log
        binrep_updateloop $1 $2 lic
    else
        if [ "$2" == "webapps" ]
        then
            export ABSMESSAGE="Updating WEB applications"; absmenu_log
            export ABSMESSAGE="    make sure applicationserver is running"; absmenu_log
            . $ABSMENUPATH/bin/service_administration.sh appstart
        fi
		if [ "$2" == "srv" -o "$2" == "all" ]
        then
            export ABSMESSAGE="Updating APP"; absmenu_log
            [ $ABSSOLUTENUMVERSION -ge 90000 ] && check_repository_for_old_junk
			
            binrep_updateloop $1 $2 app
			
			if [ "$UNATTENDED_SCRIPTRUN" == "yes" ]
			then
				. $ABSMENUPATH/bin/service_administration.sh startupdate
				[ $? -eq 1 ] && return 1
			elif [ "$SCRIPTQUESTIONDONE" == "N" ]
			then
                    export ABSMESSAGE="Waiting for update scripts to finish (manual confirmation)"; absmenu_log
                    echo
                    echo
                    echo "***********************************************************************"
                    echo "If there are any update scripts to run, then please start a server GUI"
                    echo "(in a new session) and run the scripts now. After you completely"
                    echo "finished running all the scripts that need running, press enter in"
                    echo "this session to start the application servers and continue the"
                    echo "software distribution"
					read -p "*********************************************************************** " ABSM_SCRIPTPAUSE
					
                    echo
                    echo
                    export SCRIPTQUESTIONDONE=Y
            fi
			
            export ABSMESSAGE="Updating REP"; absmenu_log
            binrep_updateloop $1 $2 rep
        
            export ABSMESSAGE="Starting application- and report servers"; absmenu_log				
			
			. $ABSMENUPATH/bin/service_administration.sh appstart
			
			[ $? -ne 0 ] && return 1
			
			. $ABSMENUPATH/bin/service_administration.sh repstart
			
			binrep_updateloop $1 $2 client
        fi
        if [ "$2" == "webapps" -o "$2" == "all" ] 
		then
			[ "$GFPARALLELENABLE" != "Y" ] && binrep_updateloop $1 $2 web
			[ "$GFPARALLELENABLE" == "Y" ] && start_web_deploy_parallel $1
		fi
    fi
fi

export ABSMESSAGE="Replicate future repository to current repository"; absmenu_log
echo "Replicate Future repository to Current repository"
export ABSMESSAGE="First check if there is ../Future/Web in the repository server $ABSMENUREPOSITORYSERVER $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT "; absmenu_log
echo $ABSMESSAGE

export FUTUREWEBEXISTS="TRUE"
if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
then
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web ] && export FUTUREWEBEXISTS="FALSE"
else
	[ ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web ]" ] && export FUTUREWEBEXISTS="FALSE"
fi

export ABSMESSAGE="Future web environment exists: $FUTUREWEBEXISTS"; absmenu_log
echo $ABSMESSAGE

if [ "$ABSM_GF_VERSION" == "5" ] 
then 
	export WEBSRVNAME="payara"
else 
	export WEBSRVNAME="glassfish"
fi

if [ "$ABS_ROOTSERVER" == "$ABSMENUREPOSITORYSERVER" ] 
then
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS
	[ $FUTUREWEBEXISTS == "TRUE" ] && echo "Check ../Current/Web => create folder Current/Web"
	[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web ]  && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web
	rsync -ta --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server
	rsync -ta --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE
	rsync -ta --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver
	rsync -ta --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS
	echo "FUTUREWEBEXISTS = $FUTUREWEBEXISTS rsync"
	[ $FUTUREWEBEXISTS == "TRUE" ] && rsync -ta --delete -e "ssh -q" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web
else
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS"
	echo -n .
	[ $FUTUREWEBEXISTS == "TRUE" ] && ssh -n -q $ABSMENUREPOSITORYSERVER "[ ! -d $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web ] && mkdir -p $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web"
	echo .
	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -ta --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Server/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Server"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -ta --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/LICENSE/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/LICENSE"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -ta --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Reportserver/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Reportserver"
	echo -n .
	ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -ta --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/CUSTOMREPORTS/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/CUSTOMREPORTS"
	[ $FUTUREWEBEXISTS == "TRUE" ] && ssh -n -q $ABSMENUREPOSITORYSERVER "rsync -ta --delete -e \"ssh -q\" $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Future/Web/* $ABSMENUREPOSITORYLOCATION/$ABSMENU_CURRENT_ENVIRONMENT/Current/Web"
fi 
