#!/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 ChangeOutgoing.txt

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

PRIVACYGATEWAY_VAL=$privacy_gateway
OUTGOING_THREAD=$out_thread

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




###########
DEFAULT_JS="outgoing_thread.js"
INPUT_FILE="outgoing_thread_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|BLUKRYPT_VAL|$PRIVACYGATEWAY_VAL|g" $INPUT_FILE
	sed -i "s|OUGOING_VAL|$OUTGOING_THREAD|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
	curl -k -X POST https://$PRIVACYGATEWAY_VAL/BluKryptBuilder/cloud/$CLOUD_NAME/updateProperties/
        sleep 2s
        rm $INPUT_FILE

