#!/usr/bin/env bash
###############################################################################
#
#          Dell Inc. PROPRIETARY INFORMATION
# This software is supplied under the terms of a license agreement or
# nondisclosure agreement with Dell Inc. and may not
# be copied or disclosed except in accordance with the terms of that
# agreement.
#
# Copyright (c) 2000-2018 Dell Inc. All Rights Reserved.
#
# Module Name:
#
#   dsm_om_connsvc-helper
#
# Abstract/Purpose:
#
#   DSM SA Connection Service Environment Variables
#
# Environment:
#
#   Linux
#
# Notes:
#
#
###############################################################################

PROGRAM_INI_ROOT="/opt/dell/srvadmin/etc/openmanage/oma/ini"

# current jre version
currentjrepath=$(grep omajvmpath ${PROGRAM_INI_ROOT}/omprv.ini)
currentjrepath=${currentjrepath#omajvmpath=}
currentjreversion=$(grep omajvmversion ${PROGRAM_INI_ROOT}/omprv.ini)

# bundled jre version
bundledjrepath=$(grep BundledJREPath ${PROGRAM_INI_ROOT}/omprv.ini)
bundledjrepath=${bundledjrepath#BundledJREPath=}
bundledjreversion=$(grep BundledJREVersion ${PROGRAM_INI_ROOT}/omprv.ini)
bundledjreversion=${bundledjreversion#BundledJREVersion=}
JAVA_FILE="${currentjrepath}/bin/java"

if [ ! -f ${JAVA_FILE} ]; then
	# replace currentjrepath with bundledjre
	sed -i "s%$currentjrepath%$bundledjrepath%g" ${PROGRAM_INI_ROOT}/omprv.ini
	# replace currentjreversion with bundlejre version
	sed -i "s%$currentjreversion%omajvmversion=${bundledjreversion}%g" ${PROGRAM_INI_ROOT}/omprv.ini
fi

sLibPath=$(grep omalibrarypath ${PROGRAM_INI_ROOT}/omprv.ini)
sLibPath=${sLibPath#omalibrarypath=}
sLibPath=${sLibPath//,/:}

echo $sLibPath

