#!/bin/bash
source ./update_functions.sh 2>&1
source ./config.properties 2>&1
# Detials got from config.properties
# Get mongo detials
# Validaate revert agent version name and update to config.properties file

#mongoDetailsRevert_keyword #localhost #port
read -p "Is Mongo in local server? - yes Or No: " mongodbLocal

if [[ $mongodbLocal == "yes" || $mongodbLocal == "YES" || $mongodbLocal == "y"  ]]; then
	mongoDetailsRevert localhost 27017 

elif [[ $mongodbLocal == "no" || $mongodbLocal == "NO" || $mongodbLocal == "n" ]]; then
	read -p "Enter Mongo Hostname: "  mongoHost
	mongoDetailsRevert $mongoHost 443
else 
	exit
fi

revert_value=$(<$LOCAL_PATH/old_agent_version)
echo "$revert_value"

if [ -z "$revert_value" ]
then
	echo "Your started with revert - Please run the update once for revert."
else
	read -p "Is old version as $revert_value value correct? - yes Or No: " oldversion_yesno

	if [[ $oldversion_yesno == "yes" || $oldversion_yesno == "YES" || $oldversion_yesno == "y"  ]]; then
		sed -i "s|EPA_OLD_VERSION.*|EPA_OLD_VERSION='"$revert_value"' |" ./config.properties
    	sleep 5
    	fileValidation

	elif [[ $oldversion_yesno == "no" || $oldversion_yesno == "NO" || $oldversion_yesno == "n" ]]; then
		read -p "Please enter the old version do you want to revert"  old_vs_old
		sed -i "s|EPA_OLD_VERSION.*|EPA_OLD_VERSION='"$old_vs_old"' |" ./config.properties
    	sleep 5  
    	fileValidation
	else 
		exit
	fi
if
