#! /bin/bash

if [ $# -eq 0 ]
   then
	apiKey=$(grep -F "sur_id: " BigCloud.json | cut -d" " -f2-)
    else
    	apiKey=$1
fi

sed -i "s/ApiKey:.*/ApiKey: $apiKey/" SuricataLogger

./AddSuricataUser.sh

su - suricata -c 'echo -e "\n\n\n" | ssh-keygen -t rsa'

fingerprints=$(ssh-keyscan -H localhost 2>/dev/null)
publicKey=$(cat /home/Suricata/.ssh/id_rsa.pub)

curl -X PUT "192.168.1.19/test/" \
-H "Content-Type: application/json" \
--data @- <<END;
{
apiKey: "$apiKey",
fingerPrint: "$fingerprints",
publicKey: "$publicKey"
}
END
