#!/bin/bash zip_file_path=$1 if [[ -z $1 ]]; then echo "Specify SAP NetWeaver RFC SDK zip file path. SAP NetWeaver RFC SDK file is available at https://support.sap.com/en/product/connectors/nwrfcsdk.html" exit 1 fi # returns 0 if same, # returns 1 if version 1 is greater than version 2 # returns 2 is version 1 is less than version 2 version_compare() { local s_ver1=$1 local s_ver2=$2 local a_ver1=($(echo $s_ver1 | tr '.' "\n")) local a_ver2=($(echo $s_ver2 | tr '.' "\n")) local i_no_of_ele_ver1=${#a_ver1[@]} local i_no_of_ele_ver2=${#a_ver2[@]} local i_result=0 if [ "X$i_no_of_ele_ver1" != "X$i_no_of_ele_ver2" ]; then echo -e "version_compare sub-routine needs identical number of elements" exit 1 fi for ((i = 0; i < $i_no_of_ele_ver1; i++)); do if [ ${a_ver1[$i]} -eq ${a_ver2[$i]} ]; then continue fi if [ ${a_ver1[$i]} -gt ${a_ver2[$i]} ]; then #version 1 is greater i_result=1 else #version 2 is greater i_result=2 fi break done echo $i_result } version_check() { version_str=$(cat /opt/cyops-ui/version.json) version_split=($(echo $version_str | tr ':' "\n"| tr '-' "\n" )) new_version=$(awk -F'\"' '{print $2}' <<< "${version_split[1]}") compare_result=$(version_compare '7.2.0' $new_version) if [ $? -ne 0 ]; then echo "Failed to compare the version" exit 1 fi if [ $compare_result -eq 1 ]; then user='nginx' else user='fsr-integrations' fi echo $user } user=$(version_check) env_file="/etc/environment" nwrfcsdk_path="/usr/local/sap/" sec_path="/opt/sec" sap_crypto_lib="/opt/SAPCRYPTOLIB" pip_path="/opt/cyops-integrations/.env/bin/pip3" python_path="/opt/cyops-integrations/.env/bin/python3" sudo -u $user $python_path $pip_path install Cython==0.29.30 printf '=%.0s' {1..80}; printf '\n# Install SAP NWRFC Libraries\n' sudo mkdir -p $nwrfcsdk_path echo "${nwrfcsdk_path} created successfully" printf '~%.0s' {1..80}; printf '\n' sudo mkdir -p $sec_path echo "${sec_path} created successfully" printf '~%.0s' {1..80}; printf '\n' sudo chown -R $user:$user $sec_path file_name="${zip_file_path##*/}" curl "$zip_file_path" -o /tmp/$file_name && unzip /tmp/$file_name -d $nwrfcsdk_path printf '~%.0s' {1..80}; printf '\n' echo "${file_name} downloaded at ${nwrfcsdk_path} successfully" sudo chown -R $user:$user $nwrfcsdk_path printf "SAPNWRFC_HOME=${nwrfcsdk_path}nwrfcsdk\nSNC_LIB=$sap_crypto_lib/libsapcrypto.so\nSECUDIR=$sec_path" >>$env_file echo "SAPNWRFC_HOME, SNC_LIB, and SECUDIR environment variables setup successfully" printf '~%.0s' {1..80}; printf '\n' echo "${nwrfcsdk_path}nwrfcsdk/lib" >>/etc/ld.so.conf.d/nwrfcsdk.conf ldconfig && ldconfig -p | grep sap printf '~%.0s' {1..80}; printf '\n' sudo -u $user $python_path $pip_path install pyrfc==2.5.0 printf '~%.0s' {1..80}; printf '\n'