#!/usr/bin/env bash

error(){
   echo ""
   echo -e "\t[ \033[31m\033[1mError\033[m ]: $*"
   echo ""
}
info (){
   echo ""
   echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
   echo ""
}
get_openssl_version() {

   OPENSSL_VERSION="$(openssl version|awk '{print $2}' | grep -o -E "[0-9]+\.[0-9]+\.[0-9]")" 

   OPENSSL_MAIN_VERSION=`echo $OPENSSL_VERSION | cut -d '.' -f1,2`
   OPENSSL_MAJOR_VERSION=`echo $OPENSSL_VERSION | cut -d '.' -f1`
   OPENSSL_MINOR_VERSION=`echo $OPENSSL_VERSION | cut -d '.' -f2`
   OPENSSL_PATCH_LEVEL=`echo $OPENSSL_VERSION | cut -d '.' -f3`

   if [[ -n "${OPENSSL_VERSION}" ]] ; then
      return 0
   else
      return 1
   fi
}

get_openssl_version
if [[ $? -eq 0 ]] ; then

   info "Detecting OpenSSL Version as follows:

                  OpenSSL Version:       '${OPENSSL_VERSION}'
                  OpenSSL Main Version:  '${OPENSSL_MAIN_VERSION}'
                  OpenSSL Major Version: '${OPENSSL_MAJOR_VERSION}'
                  OpenSSL Minor Version: '${OPENSSL_MINOR_VERSION}'
                  OpenSSL Patch Level:   '${OPENSSL_PATCH_LEVEL}'"
else
   error "Cannot detect OpenSSL Version."
fi
exit 0
   
