#!/bin/bash
#Developed By: Vaibhav K

PARABLU_CONFIG_SCRIPT_PATH=/parablu-scripts/Installable/config/parablu_config.sh
PARABLU_COMPONENT_CONFIG_SCRIPT_PATH=/parablu-scripts/Installable/config/parablu_component_config.sh

source $PARABLU_CONFIG_SCRIPT_PATH
source $PARABLU_COMPONENT_CONFIG_SCRIPT_PATH

source ChangeCloudValidity.txt

#### VALUE TO BE MODIFIED ######

LICENCE_RENEWAL_VAL=$cloud_licence

################################




###########
DEFAULT_JS="cloud_vailidity.js"
INPUT_FILE="cloud_vailidity_install.js"
OUTPUT_FILE="scriptutil.log"
######

dbport=$(grep port: /etc/mongod.conf)
MONGODB_PORT=$(echo $dbport | sed -e 's/port://' | sed 's/"//g' | tr -d ' ')


	cp -r $DEFAULT_JS $INPUT_FILE
	sleep 1s
	sed -i "s|CLOUDVALIDITY_PLACEHOLDER|$LICENCE_RENEWAL_VAL|g" $INPUT_FILE
	sleep 1s


	echo "Run These Commands"
	sudo mongo localhost:$MONGODB_PORT -u "neil" -p "parablu" --authenticationDatabase "admin" < $INPUT_FILE >>$OUTPUT_FILE
	echo "RESPONSE CODE IS:$?" >> $OUTPUT_FILE
	service memcached restart
	service tomcat-pcb1 restart
	sleep 2s
	rm $INPUT_FILE



