Skip to content

Commit a42c8bc

Browse files
author
marcel
committed
A cont-init.d script for the official openHAB Docker container.
* Install Jython using the jython-installer.jar if not installed already. * Enable the Next Generation Rule Engine if not enabled already. * Remove *$py.class files upon container startup. * Export EXTRA_JAVA_OPTS environment variable updated for Jython.
1 parent 1e9acbc commit a42c8bc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash -x
2+
3+
JYTHON_VERSION="2.7.0"
4+
JYTHON_HOME="${OPENHAB_CONF}/automation/jython"
5+
6+
export EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Xbootclasspath/a:${JYTHON_HOME}/jython.jar -Dpython.home=${JYTHON_HOME} -Dpython.path=${JYTHON_HOME}/Lib:${OPENHAB_CONF}/automation/lib/python"
7+
8+
9+
function cleanup_compiled_classes() {
10+
# Clears Jython's compiled classes
11+
if [ -d "${OPENHAB_CONF}/automation/lib/python" ]; then
12+
find ${OPENHAB_CONF}/automation/lib/python -name '*\$py.class' -delete
13+
fi
14+
if [ -d "${JYTHON_HOME}/Lib" ]; then
15+
find ${JYTHON_HOME}/Lib -name '*\$py.class' -delete
16+
fi
17+
}
18+
19+
function download_jython_libraries() {
20+
# Download and install Jython
21+
if [ ! -d "${JYTHON_HOME}" ]; then
22+
mkdir -p "${JYTHON_HOME}"
23+
wget -nv -O /tmp/jython-installer.jar http://central.maven.org/maven2/org/python/jython-installer/${JYTHON_VERSION}/jython-installer-${JYTHON_VERSION}.jar
24+
java -jar /tmp/jython-installer.jar -s -d ${JYTHON_HOME}/ -t standard -e demo doc src
25+
rm /tmp/jython-installer.jar
26+
# chmod -R o+w ${JYTHON_HOME}
27+
chown -R openhab:openhab ${JYTHON_HOME}
28+
fi
29+
}
30+
31+
function enable_next_generation_rule_engine() {
32+
# Enable the Next Generation Rule Engine
33+
set +e
34+
MISC_LINE=$(grep '^[[:space:]]\?misc' ${OPENHAB_CONF}/services/addons.cfg)
35+
if [ $? -eq 0 ]; then
36+
# ensure we have ruleengine enabled
37+
if [[ ${MISC_LINE} == *"ruleengine"* ]]; then
38+
echo "New rule engine is already included in the addons.cfg"
39+
else
40+
sed -i 's/misc\s\?=\s\?/misc = ruleengine,/' ${OPENHAB_CONF}/services/addons.cfg
41+
fi
42+
else
43+
# Just append last line
44+
echo "Append 'misc = ruleengine' to ${OPENHAB_CONF}/services/addons.cfg"
45+
echo "misc = ruleengine" >> ${OPENHAB_CONF}/services/addons.cfg
46+
fi
47+
}
48+
49+
50+
download_jython_libraries
51+
cleanup_compiled_classes
52+
enable_next_generation_rule_engine

0 commit comments

Comments
 (0)