|
@@ -2,6 +2,18 @@
|
|
|
|
|
|
export ZWAVE_JS_CONF="${SNAP}/lib/zwavejs2mqtt/node_modules/@zwave-js/config"
|
|
|
|
|
|
+if [ -z "${DAEMONIZED}" ]; then
|
|
|
+ DAEMONIZED=0
|
|
|
+fi
|
|
|
+
|
|
|
+function lprint {
|
|
|
+ if [ ${DAEMONIZED} -eq 0 ]; then
|
|
|
+ echo ${1}
|
|
|
+ else
|
|
|
+ logger "${SNAP_NAME}: ${1}"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
function ensure_zwavejs_config {
|
|
|
# Not needed anymore as of ZWAVEJS_EXTERNAL_CONFIG
|
|
|
# if [ "$(find ${ZWAVE_JS_CONF} -maxdepth 0 -empty -exec echo empty \;)" == "empty" ]; then
|
|
@@ -17,7 +29,7 @@ function get_network_key {
|
|
|
if [ -f "${SNAP_DATA}/settings.json" ]; then
|
|
|
SETTINGS_KEY=$(jq '.zwave.networkKey' -r "${SNAP_DATA}/settings.json")
|
|
|
if [ "${SETTINGS_KEY}" != "" ] && [ "${1}" != "${SETTINGS_KEY}" ]; then
|
|
|
- echo "${SETTINGS_KEY}"
|
|
|
+ lprint "${SETTINGS_KEY}"
|
|
|
return 1
|
|
|
fi
|
|
|
return 0
|
|
@@ -42,12 +54,12 @@ function same_network_key {
|
|
|
function cpy_2_zui {
|
|
|
if snapctl is-connected zui-store; then
|
|
|
if [ "$(ls "${SNAP_COMMON}/zui-store" | wc -l)" -ne 0 ]; then
|
|
|
- echo "The zui-store (${SNAP_COMMON}/zui-store) is not empty, exiting..." >&2
|
|
|
+ lprint "The zui-store (${SNAP_COMMON}/zui-store) is not empty, exiting..." >&2
|
|
|
exit 1
|
|
|
elif [ -d "${SNAP_COMMON}/zui-store" ]; then
|
|
|
cp -rf "${SNAP_DATA}/"* "${SNAP_COMMON}/zui-store"
|
|
|
if [ $? -ne 0 ]; then
|
|
|
- echo "Failed copying data from ${SNAP_COMMON}/zui-store" >&2
|
|
|
+ lprint "Failed copying data from ${SNAP_COMMON}/zui-store" >&2
|
|
|
return 1
|
|
|
fi
|
|
|
mkdir -p "${SNAP_COMMON}/zui-store/logs/zwave-js"
|
|
@@ -56,13 +68,13 @@ function cpy_2_zui {
|
|
|
rm -rf "${SNAP_COMMON}/zui-store/.ext-config"
|
|
|
touch "${SNAP_DATA}/.z2m-cpy"
|
|
|
else
|
|
|
- echo "Missing directory ${SNAP_COMMON}/zui-store, cannot write to it. Exiting..." >&2
|
|
|
+ lprint "Missing directory ${SNAP_COMMON}/zui-store, cannot write to it. Exiting..." >&2
|
|
|
exit 1
|
|
|
fi
|
|
|
else
|
|
|
- echo "Can not copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: 'snap install zwave-js-ui')." >&2
|
|
|
- echo "Please install and connect with:" 1>&2
|
|
|
- echo "$ snap connect ${SNAP_NAME}:zui-store zwave-js-ui:store-dir" >&2
|
|
|
+ lprint "Can not copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: 'snap install zwave-js-ui')." >&2
|
|
|
+ lprint "Please install and connect with:" 1>&2
|
|
|
+ lprint "$ snap connect ${SNAP_NAME}:zui-store zwave-js-ui:store-dir" >&2
|
|
|
return 1
|
|
|
fi
|
|
|
return 0
|
|
@@ -70,12 +82,12 @@ function cpy_2_zui {
|
|
|
|
|
|
function plug_connected {
|
|
|
if ! snapctl is-connected "${1}"; then
|
|
|
- echo "Missing plug: «${1}»" >&2
|
|
|
- echo "Connect with:"
|
|
|
+ lprint "Missing plug: «${1}»" >&2
|
|
|
+ lprint "Connect with:"
|
|
|
if [ "${1}" == "serial-port" ]; then
|
|
|
- echo "$ sudo snap connect ${SNAP_NAME}:${1} <slot name>"
|
|
|
+ lprint "$ sudo snap connect ${SNAP_NAME}:${1} <slot name>"
|
|
|
else
|
|
|
- echo "$ sudo snap connect ${SNAP_NAME}:${1}"
|
|
|
+ lprint "$ sudo snap connect ${SNAP_NAME}:${1}"
|
|
|
fi
|
|
|
return 1
|
|
|
fi
|
|
@@ -92,10 +104,10 @@ function plugs_connected {
|
|
|
SERIAL_RES=$?
|
|
|
|
|
|
if [ $RAW_RES -ne 0 -a $SERIAL_RES -ne 0 ]; then
|
|
|
- echo $RAW_OUT
|
|
|
- echo "----- OR -----"
|
|
|
- echo $SERIAL_OUT
|
|
|
- echo "See ${SNAP_NAME}.help for more info on the serial-port plug"
|
|
|
+ lprint $RAW_OUT
|
|
|
+ lprint "----- OR -----"
|
|
|
+ lprint $SERIAL_OUT
|
|
|
+ lprint "See ${SNAP_NAME}.help for more info on the serial-port plug"
|
|
|
MISSING=1
|
|
|
fi
|
|
|
|
|
@@ -128,13 +140,13 @@ function require_root {
|
|
|
}
|
|
|
|
|
|
function testnset_config {
|
|
|
- logger "${SNAP_NAME}: Testing ${1}, or setting ${2}"
|
|
|
+ lprint "Testing ${1}, or setting ${2}"
|
|
|
RES=$(snapctl get ${1})
|
|
|
if [ $? -ne 0 ] || [ -z "${RES}" ]; then
|
|
|
- logger "${SNAP_NAME}: Setting ${1}=${2}"
|
|
|
+ lprint "Setting ${1}=${2}"
|
|
|
RES=$(snapctl set ${1}=${2})
|
|
|
if [ $? -ne 0 ]; then
|
|
|
- logger "${RES}"
|
|
|
+ lprint "${RES}"
|
|
|
exit 1
|
|
|
fi
|
|
|
return 0
|