#!/bin/sh
#***************************************************************************
#         Description:
#
# permanently allow MICS java runtime for SE linux.
#
# execute this script as root ('su -') if you experience the following error
# during MICS startup:
#   'Error: failed [MICS_HOME]/jre/lib/i386/server/libjvm.so,'
#   'because [MICS_HOME]/jre/lib/i386/server/libjvm.so:'
#   'cannot restore segment prot after reloc: Permission denied'
#***************************************************************************

# if MICS_HOME not set, expect it as commandline parameter
MHPATH=${MICS_HOME:-$1} 

if [ -z ${MHPATH} ] ; then
  echo "MICS_HOME not set, no commandline param given. exiting..."
  exit
fi

if [ ! -d "$MHPATH/jre" ] ; then
  echo "'$MHPATH':invalid path to MICS home given. exiting..."
  exit
fi

echo "configuring SELinux for '$MHPATH/jre'"

# 2019-02-07 change to 64bit java runtime
/usr/bin/chcon -t textrel_shlib_t "$MHPATH/jre/lib/amd64/server/libjvm.so"
/usr/sbin/semanage fcontext -a -t textrel_shlib_t "$MHPATH/jre/lib/amd64/server/libjvm.so"
