Add connector cert script

#!/bin/bash
#author email: dhuks@quintessence.net

# log file
log_file=/tmp/logs

# upload parametres from applicationCustom-custom.properties
broker_url=$(grep 'broker.url' /home/qcuser/apps/qc/midgard/conf/applicationContext-custom.properties | cut -d'=' -f2 | sed 's|ssl://||' | cut -d':' -f1)

truststore_password=$(grep 'truststore.password' /home/qcuser/apps/qc/midgard/conf/applicationContext-custom.properties | cut -d'=' -f2)
unique_alias="cert_$(date +%d%m%Y)"
truststore_path=$(grep 'truststore.path' /home/qcuser/apps/qc/midgard/conf/applicationContext-custom.properties | cut -d'=' -f2)

echo "$broker_url"
# download the certificate
echo | openssl s_client -servername NAME -verify 5 -connect "${broker_url}:61617" | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/test.crt


# import the certificate
/home/qcuser/apps/opt/java/bin/keytool -import -alias $unique_alias -v -trustcacerts -file /tmp/test.crt -keystore $truststore_path -storepass $truststore_password >> $log_file 2>&1 <<EOF
yes
EOF

cp /home/qcuser/.ssh/amqCert.ts /home/qcuser/qc-install/init/


#Check if the first argument is "restart"

if [ "$1" == "restart" ]; then
/apps/bin/rcqcair stop-force
sleep 1
/apps/bin/rcqcair start
echo "Import finished and the container restarted!"
exit 0

elif [ "$1" == "" ]; then
#Check if the first argument without or is not "restart"

echo "Do you want to restart the container service? (y/n)"
read answer

if [ "$answer" != "${answer#[Yy]}" ] ;then
/apps/bin/rcqcair stop-force
sleep 1
/apps/bin/rcqcair start
echo "Import finished and the container restarted!"
else
echo "Container service not restarted."
fi

else
echo "Container service not restarted."
fi