22
33OPENHAB_AUTOMATION=" ${OPENHAB_CONF} /automation"
44OPENHAB_HL_AUTOMATION=" ${OPENHAB_AUTOMATION} /openhab-helper-libraries/Core/automation"
5+ OPENHAB_HL_AUTOMATION_RELATIVE=" ../../openhab-helper-libraries/Core/automation"
56OPENHAB_HL_URL=" https://github.com/openhab-scripters/openhab-helper-libraries/archive/master.zip"
67
78declare -A LANGUAGES=( [" groovy" ]=" groovy" [" javascript" ]=" js" [" python" ]=" py" )
89
910function verify_directory_structure() {
10-
1111 # before making any changes let's first verify that we can make the required changes
1212 verify_directory " ${OPENHAB_AUTOMATION} "
1313 for SUBDIR in jsr223 lib; do
@@ -16,7 +16,7 @@ function verify_directory_structure() {
1616 verify_directory " ${OPENHAB_AUTOMATION} /${SUBDIR} /$LANGUAGE /community"
1717 verify_directory " ${OPENHAB_AUTOMATION} /${SUBDIR} /$LANGUAGE /personal"
1818
19- verify_symlink " ${OPENHAB_AUTOMATION} /${SUBDIR} /${LANGUAGE} / core" " ${OPENHAB_HL_AUTOMATION } /${SUBDIR} /${LANGUAGE} /core"
19+ verify_symlink " ${OPENHAB_AUTOMATION} /${SUBDIR} /${LANGUAGE} " " core" " ${OPENHAB_HL_AUTOMATION_RELATIVE } /${SUBDIR} /${LANGUAGE} /core"
2020 done
2121 done
2222}
@@ -31,7 +31,7 @@ function create_directory_structure() {
3131 create_directory " ${OPENHAB_AUTOMATION} /${SUBDIR} /$LANGUAGE /personal"
3232 chmod g+w " ${OPENHAB_AUTOMATION} /${SUBDIR} /$LANGUAGE /personal"
3333
34- create_symlink " ${OPENHAB_AUTOMATION} /${SUBDIR} /${LANGUAGE} / core" " ${OPENHAB_HL_AUTOMATION } /${SUBDIR} /${LANGUAGE} /core"
34+ create_symlink " ${OPENHAB_AUTOMATION} /${SUBDIR} /${LANGUAGE} " " core" " ${OPENHAB_HL_AUTOMATION_RELATIVE } /${SUBDIR} /${LANGUAGE} /core"
3535 done
3636 done
3737}
@@ -61,25 +61,31 @@ function create_directory() {
6161}
6262
6363function verify_symlink() {
64- local LINK_NAME=$1
65- local TARGET=$2
66- if [ -L " ${LINK_NAME} " ]; then
67- local LINK_TARGET=" $( readlink ${LINK_NAME} ) "
68- if [ " ${LINK_TARGET} " != " ${TARGET} " ]; then
69- echo " ERROR: A symlink with ${LINK_NAME} already exists pointing to a different target."
64+ local LINK_DIR=$1
65+ local LINK_NAME=$2
66+ local TARGET=$3
67+ if [ -d ${LINK_DIR} ]; then
68+ cd " ${LINK_DIR} "
69+ if [ -L " ${LINK_NAME} " ]; then
70+ local LINK_TARGET=" $( readlink ${LINK_NAME} ) "
71+ if [ " ${LINK_TARGET} " != " ${TARGET} " ]; then
72+ echo " ERROR: A symlink with ${LINK_NAME} already exists pointing to a different target."
73+ exit 1
74+ fi
75+ elif [ -e " ${LINK_NAME} " ]; then
76+ echo " ERROR: File or directory with name ${LINK_NAME} already exists."
7077 exit 1
7178 fi
72- elif [ -e " ${LINK_NAME} " ]; then
73- echo " ERROR: File or directory with name ${LINK_NAME} already exists."
74- exit 1
7579 fi
7680}
7781
7882function create_symlink() {
79- local LINK_NAME=$1
80- local TARGET=$2
83+ local LINK_DIR=$1
84+ local LINK_NAME=$2
85+ local TARGET=$3
86+ cd " ${LINK_DIR} "
8187 if [ ! -L " ${LINK_NAME} " ]; then
82- ln -s " ${TARGET} " " ${LINK_NAME} "
88+ ln -rs " ${TARGET} " " ${LINK_NAME} "
8389 if [ $? -ne 0 ]; then
8490 echo " ERROR: Could not create symlink ${LINK_NAME} to ${TARGET} ."
8591 exit 1
@@ -95,6 +101,12 @@ function create_initial_configuration() {
95101 cp " ${OPENHAB_HL_AUTOMATION} /lib/${LANGUAGE} /configuration.${LANGUAGES[$LANGUAGE]} .example" " ${OPENHAB_AUTOMATION} /lib/${LANGUAGE} /configuration.${LANGUAGES[$LANGUAGE]} "
96102 fi
97103 done
104+
105+ for DIRECTORY in community personal; do
106+ if [ ! -f " ${OPENHAB_AUTOMATION} /lib/python/${DIRECTORY} /__init__.py" ]; then
107+ touch " ${OPENHAB_AUTOMATION} /lib/python/${DIRECTORY} /__init__.py"
108+ fi
109+ done
98110}
99111
100112function download_helper_libraries() {
@@ -126,26 +138,35 @@ function install_helper_libraries() {
126138 chown -R openhab:openhab " ${OPENHAB_AUTOMATION} "
127139}
128140
129- function enable_next_generation_rule_engine() {
130- # Enable the Next Generation Rule Engine
131- set +e
132- MISC_LINE=$( grep ' ^[[:space:]]\?misc' ${OPENHAB_CONF} /services/addons.cfg)
141+ function check_addons_config() {
142+ # Check if the Next Generation Rule Engine is enabled
143+ MISC_LINE=$( grep ' ^[[:space:]]\?misc' $1 )
133144 if [ $? -eq 0 ]; then
134145 # ensure we have ruleengine enabled
135146 if [[ ${MISC_LINE} == * " ruleengine" * ]]; then
136- echo " New rule engine is already included in the addons.cfg."
137- else
138- sed -i ' s/misc\s\?=\s\?/misc = ruleengine,/' ${OPENHAB_CONF} /services/addons.cfg
147+ return 0
139148 fi
149+ fi
150+
151+ return 1
152+ }
153+
154+ function check_next_generation_rule_engine() {
155+
156+ if check_addons_config " ${OPENHAB_CONF} /services/addons.cfg" ; then
157+ echo " New rule engine is already enabled in the addons.cfg."
158+ elif check_addons_config " $OPENHAB_USERDATA /config/org/openhab/addons.config" ; then
159+ echo " New rule engine is already enabled in the addons.config."
140160 else
141- # Just append last line
142- echo " Append 'misc = ruleengine' to ${OPENHAB_CONF} /services/addons.cfg."
143- echo " misc = ruleengine" >> ${OPENHAB_CONF} /services/addons.cfg
161+ echo " Please enable the Next Generation Rule Engine."
162+ echo " See https://www.openhab.org/docs/configuration/rules-ng.html"
144163 fi
145164}
146165
147166
148167if [ ! -d " ${OPENHAB_AUTOMATION} /openhab-helper-libraries" ]; then
168+ CURRENT_DIR=$( pwd)
169+
149170 # verify if installation is possible
150171 verify_directory_structure
151172 download_helper_libraries
@@ -157,8 +178,10 @@ if [ ! -d "${OPENHAB_AUTOMATION}/openhab-helper-libraries" ]; then
157178 # create initial configuration if required
158179 create_initial_configuration
159180
160- # enable the next genereation rule engine if required
161- enable_next_generation_rule_engine
181+ # check if the ng-rule engine is enabled
182+ check_next_generation_rule_engine
183+
184+ cd " ${CURRENT_DIR} "
162185else
163186 echo " Helper Libraries for openHAB Scripted Automation already installed."
164187fi
0 commit comments