-- CII Integrated Alarm System

-- Known Issues:
-- The "JAVA_HOME/bin" part gets not removed from the $PATH when you do "module unload"

whatis ("Name: cii-ias")


-- using the "or"-operator to catch undefined (nil) values

local java_home = os.getenv("JAVA_HOME") or "/usr/lib/jvm/java"
setenv ("JAVA_HOME", java_home)

local jre_home = os.getenv("JRE_HOME") or pathJoin(java_home, "jre")
setenv ("JRE_HOME", jre_home)

local kafka_home = os.getenv("KAFKA_HOME") or "/opt/kafka"
setenv ("KAFKA_HOME", kafka_home)

local scala_home = os.getenv("SCALA_HOME") or "/opt/scala"
setenv ("SCALA_HOME", scala_home)

local ias_root = os.getenv("IAS_ROOT") or "/opt/IasRoot"
setenv ("IAS_ROOT", ias_root)

local ias_extjars = os.getenv("IAS_EXTERNAL_JARS") or "/opt/IasExtJars/lib"
setenv ("IAS_EXTERNAL_JARS", ias_extjars)

local alarm_cdb = os.getenv("ALARM_CDB_ROOT") or "/etc/cii_ias"
setenv ("ALARM_CDB_ROOT", alarm_cdb)


-- Further variables are defined in "$IAS_ROOT/config/ias-bash-profile.sh",
-- which could be sourced here with "source-sh". But that function acts a bit
-- obscure, therefore we do here in-line what the shell script would do:

local ias_logs = os.getenv("IAS_LOGS_FOLDER") or pathJoin (ias_root, "logs")
setenv ("IAS_LOGS_FOLDER", ias_logs)

local ias_tmp = os.getenv("IAS_TMP_FOLDER") or pathJoin (ias_root, "tmp")
setenv ("IAS_TMP_FOLDER", ias_tmp)

local ias_config = os.getenv("IAS_CONFIG_FOLDER") or pathJoin (ias_root, "config")
setenv ("IAS_CONFIG_FOLDER", ias_config)

prepend_path ( "PYTHONPATH", pathJoin (ias_root, "lib/python") )
prepend_path ( "PATH", pathJoin (scala_home, "bin") )
prepend_path ( "PATH", pathJoin (jre_home, "bin") )
prepend_path ( "PATH", pathJoin (java_home, "bin") )
prepend_path ( "PATH", pathJoin (ias_root, "bin") )