#!/bin/bash
#
#########################################################################################
# Script: 		service_administration.sh
# Description: 	Service administration script
# Author: 		ABS Laundry Business Solutions
# Version: 		4.5
#### Changelog of script ################################################################
# Date        Author    Version 	Change    
# 15-May-2011 JMI		1.0			Initial version
# 12-Sep-2018 MBU		2.6			Added autoupdate procedure
# 28-Sep-2018 MBU		2.7			Improvements autoupdate procedure
# 05-Nov-2018 MBU		2.8			Added autoupdate patching procedure
# 27-Dec-2018 MBU		3.0			Improvements autoupdate procedure
#									Add pre glassfish startup SNMP check
# 07-Jan-2019 MBU		3.1			Return code 0 at the end of the service_readloop function
# 04-Apr-2019 MBU		4.0			Added support to deploy new webapplications: wua=webclient my uniform assistant wrd=webclient residential delivery wrr=webclient route returns
#									Added execution of conversion scripts after upgrade
# 27-Jun-2019 MBU		4.3			Bugfix: Service retrieval on partial environment name hit
#########################################################################################

# Takes the first application server and performs all database scripts from there
unattended_scriptrun()
{
	# $1 - environment
    
    grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk '$4=="app" { 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          
		echo "Start application server instance on $ABSM_SERVERNAME slot $ABSM_SLOT with autoupdate"
		if [ "$ABSMENU_CURRENT_ENV_SERVERJAR_VERSION.$ABSMENU_CURRENT_ENV_SERVERJAR_REVISION" != "$ABSMENU_FUTURE_ENV_SERVERJAR_VERSION.$ABSMENU_FUTURE_ENV_SERVERJAR_REVISION" ]
		then		
			if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
			then
				cd $ABS_ROOTDIR; ./abs.sh -A -c start -t app -s $ABSM_SLOT -y 5
			else
				ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c start -t app -s $ABSM_SLOT -y 5 -A"
			fi
			
			echo "Checking SNMP Status code and log files to determine status of the scriptrun."
			for ((i=1;i<=36000;i++)); 
			do 
				sleep 1s

				# Check script log for error
				if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ]
				then
					ERRORMESSAGECOUNT=$(grep 'ERROR at line' $(find /abs/$ABSM_SLOT/Server/sqlscripts -name 'Script*.log' | sort -r | head -1) | wc -l)
					# Process LOG errors
					if [ "$ERRORMESSAGECOUNT" != "0" ]
					then 
						echo "The script run failed during the execution of update related SQL scripts"
						cd $ABS_ROOTDIR; ./abs.sh -c stop -t app -s $ABSM_SLOT -y 5
						ERRORMESSAGE=$(find /abs/$ABSM_SLOT/Server/sqlscripts -name 'Script*.log' | sort -r | head -1)
						echo "Error is SQL script log $ERRORMESSAGE"
						return 1
					fi
				else
					ERRORMESSAGECOUNT=0
					LOGFILENAME=""
					LOGFILENAME=$(ssh -n -q "$ABSM_SERVERNAME" "find /abs/$ABSM_SLOT/Server/sqlscripts -name 'Script*.log' | sort -r | head -1" )
					[ ! -z "$LOGFILENAME" ] && ERRORMESSAGECOUNT=$(ssh -n -q "$ABSM_SERVERNAME" "grep 'ERROR at line' $LOGFILENAME | wc -l" )
					# Process LOG errors
					if [ "$ERRORMESSAGECOUNT" != "0" ]
					then 
						echo "The script run failed during the execution of update related SQL scripts"
						ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c stop -t app -s $ABSM_SLOT -y 5"
						LOGFILENAME=$(ssh -n -q "$ABSM_SERVERNAME" "find /abs/$ABSM_SLOT/Server/sqlscripts -name 'Script*.log' | sort -r | head -1" )
						ERRORMESSAGECOUNT=$(ssh -n -q "$ABSM_SERVERNAME" "grep 'ERROR at line' $LOGFILENAME | wc -l" )
						echo "Error is SQL script log $ERRORMESSAGE"
						return 1
					fi
				fi
												
		        # Check SNMP
				snmpcheck_app_server $ABSM_SERVERNAME $ABSM_SLOT &> /dev/null
				[ $? -eq 0 ] && break
			done
			[ "$ABSMFESV" -ge 90400 ] && return 0
			
			# Run conversion scripts
			echo "Executing the conversion scripts"
			if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ]
			then
				cd $ABS_ROOTDIR; ./abs.sh -c convrun -s $ABSM_SLOT &> /dev/null
			else
				ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c convrun -s $ABSM_SLOT" &> /dev/null
			fi
			
			# Set the current patchlevel to 0
			export currentpatch=0
			
		else
			echo "No SQL scriptrun for a version upgrade required"
			# Retrieve current patchlevel for scriptrun
			export currentpatch=$(echo $ABSMENU_CURRENT_ENV_PATCHSERVERJAR_VERSION | rev | head -c2 | rev)
			[ ${currentpatch:0:1} == "0" ] && export currentpatch=${currentpatch:1:1}
		fi 
		
		# Start patch SQL scriptrun
		if [ "$ABSMENU_CURRENT_ENV_SERVERJAR_VERSION" != "$ABSMENU_FUTURE_ENV_SERVERJAR_VERSION" -o "$ABSMENU_CURRENT_ENV_PATCHSERVERJAR_VERSION" != "$ABSMENU_FUTURE_ENV_PATCHSERVERJAR_VERSION" ] 
		then
			echo "Starting the execution of patch related database scripts if this is required"
			if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ]
			then
				cd $ABS_ROOTDIR; ./abs.sh -c stop -t app -s $ABSM_SLOT -y 5
				cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -P $currentpatch &> /dev/null
				
				if [ $? -ne 0 ]
				then
					echo "The script run failed during the execution of the patch SQL script: $f"
					return 1
				else
					cd $ABS_ROOTDIR; ./abs.sh -c start -t app -s $ABSM_SLOT -y 5
				fi
			else 
				ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c stop -t app -s $ABSM_SLOT -y 5"
				ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -s $ABSM_SLOT -P $currentpatch" &> /dev/null
				
				if [ $? -ne 0 ]
				then
					echo "The script run failed during the execution of the patch SQL script: $f."
					return 1
				else
					ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c start -t app -s $ABSM_SLOT -y 5"
				fi
			fi
		else
			echo "No patchrun required."
		fi
		return 0
	done
}

# Check the SNMP status of the app server with 
pre_glassfishstart_snmpcheck()
{
	#1 = Environment
	ABSM_ENVIRONMENT=$1
	
	# Check existance of web components
	[ $(grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk '$4!="app" && $4!="rep" { print $0 } ' | wc -l) -eq 0 ] && return 0
	
	# Remove possible old list snmplist files
	rm -r $ABSMENUPATH/tmp/*.snmplist &> /dev/null
	
	# Create snmplist for check
	grep '^ *'$ABSM_ENVIRONMENT"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 | awk '$4!="app" && $4!="rep" { print $23,$24 } ' | sort -u > $ABSMENUPATH/tmp/"$ABSM_ENVIRONMENT".snmplist
	SNMPLIST=$ABSMENUPATH/tmp/"$ABSM_ENVIRONMENT".snmplist
	
	# Set end timestamp
	ENDTIMESTAMP=$(date --date="$GFSNMPMAXAPPSTARTTIME min" +"%s")
	
	# Starting SNMP check
	echo "Checking the SNMP status of all application server required for web components"
	while [ $(cat $SNMPLIST | wc -l) -gt 0 ] && [ $(date +"%s") -lt $ENDTIMESTAMP ]
	do
		cat $SNMPLIST | while read ABSM_CONNAPPSRV ABSM_CONNAPPSLOT 
		do 
			# Check SNMP
			snmpcheck_app_server $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT &> /dev/null
			
			# Successfull SNMP remove from list
			[ $? -eq 0 ] && sed -i "/$ABSM_CONNAPPSRV\s$ABSM_CONNAPPSLOT/d" $SNMPLIST
		done
		sleep 1s
	done
	
	# Remove SNMPLIST
	rm -r $ABSMENUPATH/tmp/"$ABSM_ENVIRONMENT".snmplist &> /dev/null
}

service_readloop()
{
# $1 - environment
# $2 - command (start, stop, restart etc.)
# $3 = type (app, rep, wpo, gws, ws2, w4m, wp2, wsr, wum, wcl, wua, wrd, wrr , wsb , wfb , glass)
#      mws=w4m wpon=wp2 rest=wsr uhfmon=wum wcl=webclient wfb=absmobilefirebaseservices

    unset SORTORDER
    [ "$2" == stop ] && SORTORDER="--reverse"
    export GFSERVERSDONE=""
    
    grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 -k4,4 $SORTORDER | 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
        case "$ABSM_TYPE" in
            app|rep)                    [ "$3" == "$ABSM_TYPE" ] && FILTER_OK=yes;;
            wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wfb|glass) [ "$3" == "web" ] && FILTER_OK=yes;;
        esac
        if [ "$FILTER_OK" == yes ]
        then
            if [ "$DOGFRESTART" == yes ]
            then
                case "$ABSM_TYPE" in
                    wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wfb) export ABSM_TYPE=glass;;
                esac
            fi
            case "$ABSM_TYPE" in
                app)                    echo "$2 application server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
										if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
										then
											cd $ABS_ROOTDIR; ./abs.sh -c $2 -t app -s $ABSM_SLOT -y 5
										else
											ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c $2 -t app -s $ABSM_SLOT -y 5"
										fi
                                        ;;
                rep)                    echo "$2 report server instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
                                        if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
										then
											cd $ABS_ROOTDIR; ./abs.sh -c $2 -t rep -s $ABSM_SLOT -y 5
										else
											ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c $2 -t rep -s $ABSM_SLOT -y 5"
										fi
										
                                        ;;
                glass)                  if [[ $GFSERVERSDONE != *"$ABSM_SERVERNAME$ABSM_SLOT;"* ]]
                                        then
                                            echo "$2 glassfish instance on $ABSM_SERVERNAME slot $ABSM_SLOT"
                                            if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
											then
												cd $ABS_ROOTDIR; ./abs.sh -c $2 -t glass -s $ABSM_SLOT -y 5
											else
												ssh -n -q "$ABSM_SERVERNAME" "$ABS_ROOTDIR/abs.sh -c $2 -t glass -s $ABSM_SLOT -y 5"
											fi
											export GFSERVERSDONE="$GFSERVERSDONE$ABSM_SERVERNAME$ABSM_SLOT;"
                                        fi
										
                                        ;;
                wpo|gws|ws2|w4m|wp2|wsr|wum|wcl|wua|wrd|wrr|wsb|wfb)  	case "$ABSM_TYPE" in
													wpo)    WEBAPPNAME="Web Portal";;
													gws)    WEBAPPNAME="Generic Webservice";;
													ws2)    WEBAPPNAME="WebService2";;
													w4m)    WEBAPPNAME="MobileWebService";;
													wp2)    WEBAPPNAME="New Web Portal";;
													wsr)    WEBAPPNAME="REST WebService";;
													wum)    WEBAPPNAME="Web UHF Monitor";;
													wcl)    WEBAPPNAME="Web Client";;
													wua)    WEBAPPNAME="webclient my uniform assistant";;
													wrd)    WEBAPPNAME="webclient residential delivery";;
													wrr)    WEBAPPNAME="webclient route returns";;
                                                    wsb)    WEBAPPNAME="webclient replace smart barcode";;
                                                    wfb)    WEBAPPNAME="absmobilefirebaseservices";;
												esac
												echo "$2 glassfish application $WEBAPPNAME on $ABSM_SERVERNAME slot $ABSM_SLOT"
												if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
												then
												cd $ABS_ROOTDIR; ./abs.sh -b $ABSM_GFDOMAIN -c $2 -t $ABSM_TYPE -s $ABSM_SLOT
												else
													ssh -n -q "$ABSM_SERVERNAME" "$ABS_ROOTDIR/abs.sh -b $ABSM_GFDOMAIN -c $2 -t $ABSM_TYPE -s $ABSM_SLOT"
												fi
												;;
            esac
        fi
    done
	return 0
}

create_serverslot_list()
{
	TMPDIR=$ABS_ROOTDIR/tmp
	TMPFILE=$TMPDIR/serverslot.abs

	# empty list
	[ ! -d $TMPDIR ] && mkdir $TMPDIR
	[ -e $TMPFILE ] && rm -f $TMPFILE
	touch $TMPFILE
	
	# make a list of all server/slot combinations in the chosen environment
    grep '^ *'$1"[[:blank:]]" $ABSMENUGLOBALCONFIG | sort -k2,2 -k5,5 | 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
        echo $ABSM_SERVERNAME $ABSM_SLOT >> $TMPFILE
	done

	# walk through the list and show server status
	sort $TMPFILE | uniq | while read ABSM_SERVERNAME ABSM_SLOT
    do
        if [ "$ABS_ROOTSERVER" == "$ABSM_SERVERNAME" ] 
        then
            cd $ABS_ROOTDIR; ./abs.sh -c status -s $ABSM_SLOT
        else
            ssh -n -q "$ABSM_SERVERNAME" "cd $ABS_ROOTDIR; ./abs.sh -c status -s $ABSM_SLOT"
        fi
	done
	rm -f $TMPFILE
}

service_administration()
{
# $1 - environment
# $2 - command (start, stop, restart etc.)
    if [ "$2" == stop ]
    then
        [ "$INCLUDEWEB" == "Y" ] && service_readloop $1 $2 web
        service_readloop $1 $2 rep
        service_readloop $1 $2 app
    else
        if [ "$2" == list ]
        then
            create_serverslot_list $1
        else
            service_readloop $1 $2 app
            service_readloop $1 $2 rep
			if [ "$GFSTARTUPSNMPCHECK" == "Y" ]
			then 
				pre_glassfishstart_snmpcheck $ABSMENU_CURRENT_ENVIRONMENT
			elif [ "$GFSTARTUPDELAY" == "Y" ] 
			then
				echo "Waiting "$SERVICEDELAY" seconds for Application Servers startup"
				sleep $SERVICEDELAY
			fi
			service_readloop $1 $2 web
        fi
    fi
}

echo
export LISTALREADYSTARTED=false
export DOGFRESTART=no
export INCLUDEWEB=Y

case "$1" in
    stop)       	[ "$2" == "gf" ] && export DOGFRESTART=yes
					[ "$3" == "noweb" ] && export INCLUDEWEB=N
					echo "Stopping all $ABSMENU_CURRENT_ENVIRONMENT services:"
					service_administration $ABSMENU_CURRENT_ENVIRONMENT stop;;
    start)      	[ "$2" == "gf" ] && export DOGFRESTART=yes
					echo "Starting all $ABSMENU_CURRENT_ENVIRONMENT services:"
					service_administration $ABSMENU_CURRENT_ENVIRONMENT start;;
	startupdate) 	echo "Starting autoupdate procedure: $ABSMENU_CURRENT_ENVIRONMENT"
					export ABSMFESV=`echo $ABSMENU_FUTURE_ENV_SERVERJAR_VERSION | sed 's/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)/\1\2\3/'`
 				  unattended_scriptrun $ABSMENU_CURRENT_ENVIRONMENT;;
    restart)   		echo "Restarting all $ABSMENU_CURRENT_ENVIRONMENT services:"
					export DOGFRESTART=yes
					service_administration $ABSMENU_CURRENT_ENVIRONMENT stop
					service_administration $ABSMENU_CURRENT_ENVIRONMENT start;;
    appstart)   	echo "Starting all $ABSMENU_CURRENT_ENVIRONMENT application servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT start app;;
	appstop)   		echo "Stoping all $ABSMENU_CURRENT_ENVIRONMENT application servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT stop app;;
	apprestart) 	echo "Restarting all $ABSMENU_CURRENT_ENVIRONMENT application servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT restart app;;
    repstart)   	echo "Starting all $ABSMENU_CURRENT_ENVIRONMENT report servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT start rep;;
	repstop)   		echo "Stoping all $ABSMENU_CURRENT_ENVIRONMENT report servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT stop rep;;
    represtart) 	echo "Restarting all $ABSMENU_CURRENT_ENVIRONMENT report servers:"
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT restart rep;;
	webstart)   	echo "Starting all $ABSMENU_CURRENT_ENVIRONMENT web servers:"
					export DOGFRESTART=yes
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT start web;;
	webstop)    	echo "Stopping all $ABSMENU_CURRENT_ENVIRONMENT web servers:"
					export DOGFRESTART=yes
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT stop web;;
	webrestart) 	echo "Restarting all $ABSMENU_CURRENT_ENVIRONMENT web servers:"
					export DOGFRESTART=yes
					service_readloop $ABSMENU_CURRENT_ENVIRONMENT restart web;;
    list)       	echo "List all $ABSMENU_CURRENT_ENVIRONMENT services:"
					service_administration $ABSMENU_CURRENT_ENVIRONMENT list
					echo
					echo "Registered in the service configuration file (server - slot - type) :"
					grep '^ *'$ABSMENU_CURRENT_ENVIRONMENT"[[: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
						echo "$ABSM_SERVERNAME" "$ABSM_SLOT" "$ABSM_TYPE" | awk '{printf "     %20s  %5s  %5s\n",$1,$2,$3}'
					done
					echo
					echo;;
    *)          	echo "**  WRONG CALL TO SCRIPT SERVICE_ADMINISTRATION.  PLEASE CHECK  **"; exit;;
esac    
