From 9a360be8e0ecd2a96262e623276f32647e9d17d1 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 16 Dec 2020 12:34:51 +0100 Subject: [PATCH] HomeMatic: s6-overlay & tempio (#1713) * HomeMatic: s6-overlay & tempio * Use tempio * fix line end * Fix dev version * Fix bugs --- .devcontainer/supervisor.sh | 4 +- homematic/CHANGELOG.md | 148 +------------ homematic/Dockerfile | 19 +- homematic/build.json | 4 +- homematic/config.json | 2 +- homematic/data/hm-firmware.sh | 37 ---- homematic/data/hm-interface.sh | 40 ---- homematic/data/run.sh | 195 ------------------ homematic/rootfs/etc/cont-finish.d/hmip.sh | 7 + homematic/rootfs/etc/cont-finish.d/regahss.sh | 6 + homematic/rootfs/etc/cont-init.d/certs.sh | 5 + homematic/rootfs/etc/cont-init.d/env.sh | 19 ++ homematic/rootfs/etc/cont-init.d/hm_ip.sh | 41 ++++ homematic/rootfs/etc/cont-init.d/hm_rfd.sh | 36 ++++ homematic/rootfs/etc/cont-init.d/hm_wired.sh | 23 +++ homematic/rootfs/etc/cont-init.d/interface.sh | 8 + homematic/rootfs/etc/cont-init.d/nginx.sh | 6 + .../{data => rootfs/etc/nginx}/nginx.conf | 0 .../rootfs/etc/services.d/hmserver/finish | 8 + homematic/rootfs/etc/services.d/hmserver/run | 12 ++ homematic/rootfs/etc/services.d/lighttpd/run | 6 + homematic/rootfs/etc/services.d/nginx/finish | 8 + homematic/rootfs/etc/services.d/nginx/run | 9 + homematic/rootfs/etc/services.d/regahss/run | 18 ++ homematic/rootfs/etc/services.d/rfd/finish | 8 + homematic/rootfs/etc/services.d/rfd/run | 10 + homematic/rootfs/etc/services.d/timesync/run | 14 ++ homematic/rootfs/etc/services.d/wired/finish | 8 + homematic/rootfs/etc/services.d/wired/run | 10 + .../opt/hm/etc}/config/HMServer.conf | 0 .../opt/hm/etc}/config/log4j.xml | 0 .../opt/hm/etc}/config/rega.conf | 0 .../usr/share/tempio/InterfacesList.xml | 29 +++ .../usr/share/tempio}/crRFD.conf | 4 + .../usr/share/tempio}/hs485d.conf | 8 + .../usr/share/tempio}/rfd.conf | 8 + 36 files changed, 333 insertions(+), 427 deletions(-) delete mode 100755 homematic/data/hm-firmware.sh delete mode 100755 homematic/data/hm-interface.sh delete mode 100755 homematic/data/run.sh create mode 100755 homematic/rootfs/etc/cont-finish.d/hmip.sh create mode 100755 homematic/rootfs/etc/cont-finish.d/regahss.sh create mode 100644 homematic/rootfs/etc/cont-init.d/certs.sh create mode 100644 homematic/rootfs/etc/cont-init.d/env.sh create mode 100755 homematic/rootfs/etc/cont-init.d/hm_ip.sh create mode 100755 homematic/rootfs/etc/cont-init.d/hm_rfd.sh create mode 100755 homematic/rootfs/etc/cont-init.d/hm_wired.sh create mode 100755 homematic/rootfs/etc/cont-init.d/interface.sh create mode 100644 homematic/rootfs/etc/cont-init.d/nginx.sh rename homematic/{data => rootfs/etc/nginx}/nginx.conf (100%) create mode 100644 homematic/rootfs/etc/services.d/hmserver/finish create mode 100644 homematic/rootfs/etc/services.d/hmserver/run create mode 100644 homematic/rootfs/etc/services.d/lighttpd/run create mode 100644 homematic/rootfs/etc/services.d/nginx/finish create mode 100644 homematic/rootfs/etc/services.d/nginx/run create mode 100644 homematic/rootfs/etc/services.d/regahss/run create mode 100644 homematic/rootfs/etc/services.d/rfd/finish create mode 100644 homematic/rootfs/etc/services.d/rfd/run create mode 100644 homematic/rootfs/etc/services.d/timesync/run create mode 100644 homematic/rootfs/etc/services.d/wired/finish create mode 100644 homematic/rootfs/etc/services.d/wired/run rename homematic/{data => rootfs/opt/hm/etc}/config/HMServer.conf (100%) rename homematic/{data => rootfs/opt/hm/etc}/config/log4j.xml (100%) rename homematic/{data => rootfs/opt/hm/etc}/config/rega.conf (100%) create mode 100644 homematic/rootfs/usr/share/tempio/InterfacesList.xml rename homematic/{data/config => rootfs/usr/share/tempio}/crRFD.conf (91%) rename homematic/{data/config => rootfs/usr/share/tempio}/hs485d.conf (55%) rename homematic/{data/config => rootfs/usr/share/tempio}/rfd.conf (65%) diff --git a/.devcontainer/supervisor.sh b/.devcontainer/supervisor.sh index bcf0e3c..ead5615 100755 --- a/.devcontainer/supervisor.sh +++ b/.devcontainer/supervisor.sh @@ -4,6 +4,8 @@ set -eE DOCKER_TIMEOUT=30 DOCKER_PID=0 +SUPERVISOR_VERSON="$(curl -s https://version.home-assistant.io/dev.json | jq -e -r '.supervisor')" + function start_docker() { local starttime @@ -85,7 +87,7 @@ function run_supervisor() { -e SUPERVISOR_NAME=hassio_supervisor \ -e SUPERVISOR_DEV=1 \ -e SUPERVISOR_MACHINE="qemux86-64" \ - homeassistant/amd64-hassio-supervisor:dev + "homeassistant/amd64-hassio-supervisor:${SUPERVISOR_VERSON}" } function init_dbus() { diff --git a/homematic/CHANGELOG.md b/homematic/CHANGELOG.md index 066cfc7..9078890 100644 --- a/homematic/CHANGELOG.md +++ b/homematic/CHANGELOG.md @@ -1,157 +1,27 @@ # Changelog -## 10.3 +## 11.0.0 + +- Migrate to s6-overlay & tempio +- Update OCCU to 3.55.5-1 + +## 10.3.0 - Flush ReGaHss config on shutdown - Add ReGaHss reset option -## 10.2 +## 10.2.0 - Update Bashio to fix the wait function - Extend the log output -## 10.1 +## 10.1.0 - Fix issue with SSL -## 10.0 +## 10.0.0 - Add Ingress support - Disable external ports per default - Fix wrong version number - Speedup start without sleeps - -## 9.9 - -- Update glibc for armv7 - -## 9.8 - -- Update OCCU to 3.51.6-1 - -## 9.7 - -- Fix glibc error on i386/amd64 - -## 9.6 - -- Update OCCU to 3.49.17-4 -- Use new gcc8 binary for i386 -- Change ReGaHass to normal version - -## 9.5 - -- Fix ReGaHss binary - -## 9.4 - -- Update OCCU to 3.49.17-2 -- Use new gcc8 binary for armhf -- Don't use ReGaHss-beta - -## 9.3 - -- Update from bash to bashio -- Use debian as base image -- Fix config for group settings - -## 9.2 - -- Update OCCU to 3.47.22-3 - -## 9.1 - -- Optimize InterfaceList handling -- Make userprofiles static - -## 9.0 - -- Add Regahss (WebUI) support (experimentel) -- Update OCCU to 3.47.18-1 - -## 8.3 - -- Update OCCU to 3.47.10 -- Add Port descriptions - -## 8.2 - -- Update OCCU to 3.45.7 - -## 8.1 - -- Update OCCU to 3.43.15 -- Migrate to new arch layering -- Better handling for errors with Firmware updates - -## 8.0 - -- Update OCCU to 3.41.11 -- Fix write error when starting OCCU / HmIP -- Redirect HMIPServer log to console - -## 7.0 - -- Update OCCU to 3.41.7 - -## 6.0 - -- Allow customer firmware updates inside `/share` -- Update Hardware on startup -- Limit HmIP server to 64mb memory -- Set `rf_enable` default to `false` - -## 5.0 - -- Save hmip_address.conf persistent - -## 4.0 - -- New ubuntu base images -- Support firmware update of HM-MOD-RPI-PCB, HmIP-RFUSB -- Add HmIP support with HmIP-RFUSB - -## 3.0 - -- Add periodically time sync - -## 2.0 - -- Fix wrong Timezone -- Update OCCU to 3.37.8 - -## 1.0 - -- Change version format to other core add-ons -- Update OCCU to 2.35.16 -- Disable AppArmor to work on system like HassOS - -## 2.31.25-p2 - -- Bugfix with reset value on GPIO - -## 2.31.25-p1 - -- Add `reset` options for RF modules - -## 2.31.25-p0 - -- Update OCCU to 2.31.25 - -## 2.31.23-p0 - -- Update OCCU to 2.31.23 - -## 2.29.22-1-p1 - -- Fix bug in script -- Add wired port into config - -## 2.29.22-1-p1 - -- Change config logic -- Add support for wired - -## 2.29.22-1-p0 - -- Initial diff --git a/homematic/Dockerfile b/homematic/Dockerfile index 73e2432..94703d6 100644 --- a/homematic/Dockerfile +++ b/homematic/Dockerfile @@ -19,7 +19,9 @@ ARG BUILD_ARCH # Install OCCU WORKDIR /usr/src -RUN curl -SL https://github.com/jens-maus/occu/archive/${OCCU_VERSION}.tar.gz | tar xzf - \ +RUN \ + set -x \ + && curl -SL https://github.com/jens-maus/occu/archive/${OCCU_VERSION}.tar.gz | tar xzf - \ && cd occu-${OCCU_VERSION} \ && mkdir -p \ /boot \ @@ -74,15 +76,8 @@ RUN curl -SL https://github.com/jens-maus/occu/archive/${OCCU_VERSION}.tar.gz | \ && rm -rf /usr/src/occu-${OCCU_VERSION} -ENV HM_HOME=/opt/hm LD_LIBRARY_PATH=/opt/hm/lib:${LD_LIBRARY_PATH} +ENV \ + HM_HOME=/opt/hm \ + LD_LIBRARY_PATH=/opt/hm/lib:${LD_LIBRARY_PATH} -# Update config files -COPY data/config/* /opt/hm/etc/config/ -COPY data/nginx.conf /etc/nginx/nginx.conf - -# Setup start script -COPY data/run.sh / -COPY data/hm-firmware.sh data/hm-interface.sh /usr/lib/ - -WORKDIR /data -CMD [ "/run.sh" ] +COPY rootfs / diff --git a/homematic/build.json b/homematic/build.json index 6a0d93a..1ba9ea2 100644 --- a/homematic/build.json +++ b/homematic/build.json @@ -4,7 +4,7 @@ "i386": "homeassistant/i386-base-debian:bullseye" }, "args": { - "OCCU_VERSION": "3.51.6-1", - "CCU_VERSION": "3.51.6" + "OCCU_VERSION": "3.55.5-1", + "CCU_VERSION": "3.55.5" } } diff --git a/homematic/config.json b/homematic/config.json index eb88e47..db3d30b 100644 --- a/homematic/config.json +++ b/homematic/config.json @@ -1,6 +1,6 @@ { "name": "HomeMatic CCU", - "version": "10.3", + "version": "11.0.0", "slug": "homematic", "description": "HomeMatic central based on OCCU", "url": "https://github.com/home-assistant/hassio-addons/tree/master/homematic", diff --git a/homematic/data/hm-firmware.sh b/homematic/data/hm-firmware.sh deleted file mode 100755 index 353cdb2..0000000 --- a/homematic/data/hm-firmware.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bashio -# shellcheck disable=SC2012 - - -function firmware_update_hmip() { - local DEVICE="$1" - local FROM_VERSION= - local TO_VERSION= - - FROM_VERSION="$(java -Xmx64m -jar /opt/HmIP/hmip-copro-update.jar -p "${DEVICE}" -v | grep "Application version =" | cut -d' ' -f5)" - TO_VERSION="$(ls /firmware/HmIP-RFUSB/hmip_coprocessor_update-*.eq3 | sed 's/.*hmip_coprocessor_update-\(.*\)\.eq3/\1/' | tail -n1)" - if [ "${FROM_VERSION}" != "${TO_VERSION}" ]; then - if java -Xmx64m -jar /opt/HmIP/hmip-copro-update.jar -p "${DEVICE}" -f "/firmware/HmIP-RFUSB/hmip_coprocessor_update-${TO_VERSION}.eq3"; then - bashio::log.info "HmIP update to ${TO_VERSION} was successful" - else - bashio::log.error "HmIP update ${TO_VERSION} fails!" - fi - fi -} - - -function firmware_update_rfd() { - if "${HM_HOME}/bin/eq3configcmd" update-coprocessor -lgw -u -rfdconf /etc/config/rfd.conf -l 1; then - bashio::log.info "RFd update was successful" - else - bashio::log.error "RFd update fails!" - fi -} - - -function firmware_update_wired() { - if "${HM_HOME}/bin/eq3configcmd" update-lgw-firmware -m /firmware/fwmap -c /etc/config/hs485d.conf -l 1; then - bashio::log.info "Wired update was successful" - else - bashio::log.error "Wired update fails!" - fi -} diff --git a/homematic/data/hm-interface.sh b/homematic/data/hm-interface.sh deleted file mode 100755 index 687d702..0000000 --- a/homematic/data/hm-interface.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bashio - - -function enable_interface(){ - local name="$1" - local description="$2" - local port="$3" - - ( - echo " " - echo " ${name}" - echo " xmlrpc://127.0.0.1:${port}" - echo " ${description}" - echo " " - ) >> /etc/config/InterfacesList.xml -} - - -function init_interface_list() { - local rf=$1 - local ip=$2 - local wired=$3 - - echo -e "\n" > /etc/config/InterfacesList.xml - enable_interface "VirtualDevices" "Virtual Devices" "9292/groups" - - if [ "$rf" == "true" ]; then - enable_interface "BidCos-RF" "BidCos-RF" "2001" - fi - - if [ "$ip" == "true" ]; then - enable_interface "HmIP-RF" "HmIP-RF" "2010" - fi - - if [ "$wired" == "true" ]; then - enable_interface "Hm-Wired" "Hm-Wired" "2000" - fi - - echo "" >> /etc/config/InterfacesList.xml -} \ No newline at end of file diff --git a/homematic/data/run.sh b/homematic/data/run.sh deleted file mode 100755 index ea3f375..0000000 --- a/homematic/data/run.sh +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/env bashio -# shellcheck disable=SC1091 -set -e - -WAIT_PIDS=() - -# Init folder -mkdir -p /share/hm-firmware -mkdir -p /share/hmip-firmware -mkdir -p /data/crRFD -mkdir -p /data/rfd -mkdir -p /data/hs485d -mkdir -p /data/userprofiles - -ln -s /data/userprofiles /etc/config/userprofiles - -# Init files -touch /data/hmip_user.conf -touch /data/rega_user.conf -touch /data/homematic.regadom -touch /data/userprofiles/userAckInstallWizard_Admin - -# Import helpers -. /usr/lib/hm-firmware.sh -. /usr/lib/hm-interface.sh - -# Setup Interfaces -init_interface_list "$(bashio::config 'rf_enable')" \ - "$(bashio::config 'hmip_enable')" \ - "$(bashio::config 'wired_enable')" - -# RF support -if bashio::config.true 'rf_enable'; then - bashio::log.info "Setup BidCos-RF" - - for rf_device in $(bashio::config 'rf|keys'); do - TYPE=$(bashio::config "rf[${rf_device}].type") - - # Update config - if [ "$TYPE" == "CCU2" ]; then - DEVICE=$(bashio::config "rf[${rf_device}].device") - ( - echo "[Interface $1]" - echo "Type = CCU2" - echo "ComPortFile = $DEVICE" - echo "AccessFile = /dev/null" - echo "ResetFile = /sys/class/gpio/gpio18/value" - ) >> /etc/config/rfd.conf - - # Init GPIO - if [ ! -d /sys/class/gpio/gpio18 ]; then - echo 18 > /sys/class/gpio/export - sleep 2 - fi - if [ "$(cat /sys/class/gpio/gpio18/direction)" != "out" ]; then - echo out > /sys/class/gpio/gpio18/direction - sleep 2 - fi - - echo 0 > /sys/class/gpio/gpio18/value || echo "Can't set default value!" - sleep 0.5 - fi - done - - # Update Firmware - firmware_update_rfd - - # Run RFD - "$HM_HOME/bin/rfd" -c -l 0 -f /opt/hm/etc/config/rfd.conf & - WAIT_PIDS+=($!) -fi - -# Wired support -if bashio::config.true 'wired_enable'; then - bashio::log.info "Setup Hm-Wired" - - for wired_device in $(bashio::config 'wired|keys'); do - SERIAL=$(bashio::config "wired[${wired_device}].serial") - KEY=$(bashio::config "wired[${wired_device}].key") - IP=$(bashio::config "wired[${wired_device}].ip") - - # Update config - ( - echo "[Interface $1]" - echo "Type = HMWLGW" - echo "Serial Number = $SERIAL" - echo "Encryption Key = $KEY" - echo "IP Address = $IP" - ) >> /etc/config/hs485d.conf - done - - # Update Firmware - firmware_update_wired - - # Run hs485d - "$HM_HOME/bin/hs485d" -g -i 0 -f /opt/hm/etc/config/hs485d.conf & - WAIT_PIDS+=($!) -fi - -# HMIP support -if bashio::config.true 'hmip_enable'; then - bashio::log.info "Setup HmIP-RF" - - # Restore data - if [ -f /data/hmip_address.conf ]; then - cp -f /data/hmip_address.conf /etc/config/ - fi - - # Setup settings - for hmip_device in $(bashio::config 'hmip|keys'); do - TYPE=$(bashio::config "hmip[${hmip_device}].type") - DEVICE=$(bashio::config "hmip[${hmip_device}].device") - ADAPTER=$((hmip_device+1)) - - # Update Firmware - firmware_update_hmip "${DEVICE}" - - # Update config - ( - echo "Adapter.${ADAPTER}.Type=${TYPE}" - echo "Adapter.${ADAPTER}.Port=${DEVICE}" - ) >> /etc/config/crRFD.conf - done - - # Run HMIPServer - # shellcheck disable=SC2086 - java -Xmx64m -Dlog4j.configuration=file:///etc/config/log4j.xml -Dfile.encoding=ISO-8859-1 -jar /opt/HMServer/HMIPServer.jar /etc/config/crRFD.conf /etc/config/HMServer.conf & - WAIT_PIDS+=($!) - - if [ ! -f /data/hmip_address.conf ]; then - bashio::log.info "Wait for HMIPServer" - - bashio::net.wait_for 9292 - cp -f /etc/config/hmip_address.conf /data/ - fi -else - java -Xmx64m -Dlog4j.configuration=file:///etc/config/log4j.xml -Dfile.encoding=ISO-8859-1 -jar /opt/HMServer/HMServer.jar /etc/config/HMServer.conf & - WAIT_PIDS+=($!) -fi - -# Register stop -function stop_homematic() { - # Store Regahss - echo "load tclrega.so; rega system.Save()" | "${HM_HOME}/bin/tclsh" 2> /dev/null || true - sleep 5 - - # Forward kill process - bashio::log.info "Kill Processes..." - kill -15 "${WAIT_PIDS[@]}" - wait "${WAIT_PIDS[@]}" - bashio::log.info "Done." -} -trap "stop_homematic" SIGTERM SIGHUP - -# Wait until interfaces are initialized -bashio::log.info "Wait until HomeMatic is setup" -bashio::net.wait_for 9292 - -# Reset Regahss -if bashio::config.true "regahss_reset"; then - bashio::log.warning "Reset ReGaHss" - rm -f /data/homematic.regadom - touch /data/homematic.regadom -fi - -# Start Regahss -bashio::log.info "Start ReGaHss" -"$HM_HOME/bin/ReGaHss" -c -f /etc/config/rega.conf & -WAIT_PIDS+=($!) - -# Start WebInterface -bashio::log.info "Initialize webinterface routing" -openssl req -new -x509 -nodes -keyout /etc/config/server.pem -out /etc/config/server.pem -days 3650 -subj "/C=DE/O=HomeMatic/OU=Hass.io/CN=$(hostname)" -lighttpd-angel -D -f "${HM_HOME}/etc/lighttpd/lighttpd.conf" & -WAIT_PIDS+=($!) - -# Start Ingress -bashio::log.info "Starting Nginx" -ingress_entry=$(bashio::addon.ingress_entry) -sed -i "s#%%INGRESS_ENTRY%%#${ingress_entry}#g" /etc/nginx/nginx.conf -nginx & -WAIT_PIDS+=($!) - -# Sync time periodically -if bashio::config.true 'rf_enable'; then - while true - do - sleep 30m - bashio::log.info "$(date '+%Y-%m-%d %H:%M:%S.%3N') Run SetInterfaceClock now." - "$HM_HOME/bin/SetInterfaceClock" 127.0.0.1:2001 - done -fi - -# Wait until all is done -wait "${WAIT_PIDS[@]}" diff --git a/homematic/rootfs/etc/cont-finish.d/hmip.sh b/homematic/rootfs/etc/cont-finish.d/hmip.sh new file mode 100755 index 0000000..ebc1f2f --- /dev/null +++ b/homematic/rootfs/etc/cont-finish.d/hmip.sh @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Backup hmip_address +# ============================================================================== +if bashio::config.true 'hmip_enable' && [ -f /data/hmip_address.conf ]; then + cp -f /etc/config/hmip_address.conf /data/ || bashio::log.warning "Failed to backup hmip address" +fi diff --git a/homematic/rootfs/etc/cont-finish.d/regahss.sh b/homematic/rootfs/etc/cont-finish.d/regahss.sh new file mode 100755 index 0000000..69f985a --- /dev/null +++ b/homematic/rootfs/etc/cont-finish.d/regahss.sh @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Store RegaHss data +# ============================================================================== + +echo "load tclrega.so; rega system.Save()" | "/opt/hm/bin/tclsh" 2> /dev/null || true diff --git a/homematic/rootfs/etc/cont-init.d/certs.sh b/homematic/rootfs/etc/cont-init.d/certs.sh new file mode 100644 index 0000000..2f153f3 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/certs.sh @@ -0,0 +1,5 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Configure NGINX for use with ReGaHss +# ============================================================================== +openssl req -new -x509 -nodes -keyout /etc/config/server.pem -out /etc/config/server.pem -days 3650 -subj "/C=DE/O=HomeMatic/OU=Hass.io/CN=$(hostname)" diff --git a/homematic/rootfs/etc/cont-init.d/env.sh b/homematic/rootfs/etc/cont-init.d/env.sh new file mode 100644 index 0000000..8a878a7 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/env.sh @@ -0,0 +1,19 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Initialize file system layout /data +# ============================================================================== + +mkdir -p /share/hm-firmware +mkdir -p /share/hmip-firmware +mkdir -p /data/crRFD +mkdir -p /data/rfd +mkdir -p /data/hs485d +mkdir -p /data/userprofiles + +ln -s /data/userprofiles /etc/config/userprofiles + +# Init files +touch /data/hmip_user.conf +touch /data/rega_user.conf +touch /data/homematic.regadom +touch /data/userprofiles/userAckInstallWizard_Admin diff --git a/homematic/rootfs/etc/cont-init.d/hm_ip.sh b/homematic/rootfs/etc/cont-init.d/hm_ip.sh new file mode 100755 index 0000000..86e3b9b --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/hm_ip.sh @@ -0,0 +1,41 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Update HomeMatic firmware +# ============================================================================== +# shellcheck disable=SC2012 +declare hmip_index +declare hmip_device +declare version_to +declare version_from + +# HMIP support +if bashio::config.false 'hmip_enable'; then + bashio::exit.ok +fi +bashio::log.info "Setup HmIP-RF" + +# Generate config +tempio \ + -conf /data/options.json \ + -template /usr/share/tempio/crRFD.conf \ + -out /etc/config/crRFD.conf + +# Restore data +if [ -f /data/hmip_address.conf ]; then + cp -f /data/hmip_address.conf /etc/config/ +fi + +# Update Firmware +for hmip_index in $(bashio::config 'hmip|keys'); do + hmip_device=$(bashio::config "hmip[${hmip_index}].device") + version_from="$(java -Xmx64m -jar /opt/HmIP/hmip-copro-update.jar -p "${hmip_device}" -v | grep "Application version =" | cut -d' ' -f5)" + version_to="$(ls /firmware/HmIP-RFUSB/hmip_coprocessor_update-*.eq3 | sed 's/.*hmip_coprocessor_update-\(.*\)\.eq3/\1/' | tail -n1)" + + if [ "${version_from}" != "${version_to}" ]; then + if java -Xmx64m -jar /opt/HmIP/hmip-copro-update.jar -p "${hmip_device}" -f "/firmware/HmIP-RFUSB/hmip_coprocessor_update-${version_to}.eq3"; then + bashio::log.info "HmIP update to ${version_to} was successful" + else + bashio::log.error "HmIP update ${version_to} fails!" + fi + fi +done diff --git a/homematic/rootfs/etc/cont-init.d/hm_rfd.sh b/homematic/rootfs/etc/cont-init.d/hm_rfd.sh new file mode 100755 index 0000000..a689d53 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/hm_rfd.sh @@ -0,0 +1,36 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Update HomeMatic firmware +# ============================================================================== + +# RF support +if bashio::config.false 'rf_enable'; then + bashio::exit.ok +fi +bashio::log.info "Setup BidCos-RF" + +# Generate config +tempio \ + -conf /data/options.json \ + -template /usr/share/tempio/rfd.conf \ + -out /etc/config/rfd.conf + +# Init GPIO +if [ ! -d /sys/class/gpio/gpio18 ]; then + echo 18 > /sys/class/gpio/export + sleep 2 +fi +if [ "$(cat /sys/class/gpio/gpio18/direction)" != "out" ]; then + echo out > /sys/class/gpio/gpio18/direction + sleep 2 +fi + +echo 0 > /sys/class/gpio/gpio18/value || echo "Can't set default value!" +sleep 0.5 + +# Update Firmware +if "/opt/hm/bin/eq3configcmd" update-coprocessor -lgw -u -rfdconf /etc/config/rfd.conf -l 1; then + bashio::log.info "RFd update was successful" +else + bashio::log.error "RFd update fails!" +fi diff --git a/homematic/rootfs/etc/cont-init.d/hm_wired.sh b/homematic/rootfs/etc/cont-init.d/hm_wired.sh new file mode 100755 index 0000000..2a5fd29 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/hm_wired.sh @@ -0,0 +1,23 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Update HomeMatic firmware +# ============================================================================== + +# Wired support +if bashio::config.false 'wired_enable'; then + bashio::exit.ok +fi +bashio::log.info "Setup Hm-Wired" + +# Generate config +tempio \ + -conf /data/options.json \ + -template /usr/share/tempio/hs485d.conf \ + -out /etc/config/hs485d.conf + +# Update Firmware +if "/opt/hm/bin/eq3configcmd" update-lgw-firmware -m /firmware/fwmap -c /etc/config/hs485d.conf -l 1; then + bashio::log.info "Wired update was successful" +else + bashio::log.error "Wired update fails!" +fi diff --git a/homematic/rootfs/etc/cont-init.d/interface.sh b/homematic/rootfs/etc/cont-init.d/interface.sh new file mode 100755 index 0000000..d6ec917 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/interface.sh @@ -0,0 +1,8 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Generate InterfacesList.xml +# ============================================================================== +tempio \ + -conf /data/options.json \ + -template /usr/share/tempio/InterfacesList.xml \ + -out /etc/config/InterfacesList.xml diff --git a/homematic/rootfs/etc/cont-init.d/nginx.sh b/homematic/rootfs/etc/cont-init.d/nginx.sh new file mode 100644 index 0000000..e98e5d8 --- /dev/null +++ b/homematic/rootfs/etc/cont-init.d/nginx.sh @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Configure NGINX for use with ReGaHss +# ============================================================================== +ingress_entry=$(bashio::addon.ingress_entry) +sed -i "s#%%ingress_entry%%#${ingress_entry}#g" /etc/nginx/nginx.conf diff --git a/homematic/data/nginx.conf b/homematic/rootfs/etc/nginx/nginx.conf similarity index 100% rename from homematic/data/nginx.conf rename to homematic/rootfs/etc/nginx/nginx.conf diff --git a/homematic/rootfs/etc/services.d/hmserver/finish b/homematic/rootfs/etc/services.d/hmserver/finish new file mode 100644 index 0000000..a29ced9 --- /dev/null +++ b/homematic/rootfs/etc/services.d/hmserver/finish @@ -0,0 +1,8 @@ +#!/usr/bin/execlineb -S1 +# ============================================================================== +# Take down the S6 supervision tree based on service exit code +# ============================================================================== +if { s6-test ${1} -ne 0 } +if { s6-test ${1} -ne 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/homematic/rootfs/etc/services.d/hmserver/run b/homematic/rootfs/etc/services.d/hmserver/run new file mode 100644 index 0000000..0de97f2 --- /dev/null +++ b/homematic/rootfs/etc/services.d/hmserver/run @@ -0,0 +1,12 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start HomeMatic HMServer service +# ============================================================================== +# shellcheck disable=SC2086 +if bashio::config.true 'hmip_enable'; then + bashio::log.info "Starting HMIPServer..." + exec java -Xmx64m -Dlog4j.configuration=file:///etc/config/log4j.xml -Dfile.encoding=ISO-8859-1 -jar /opt/HMServer/HMIPServer.jar /etc/config/crRFD.conf /etc/config/HMServer.conf +else + bashio::log.info "Starting HMServer..." + exec java -Xmx64m -Dlog4j.configuration=file:///etc/config/log4j.xml -Dfile.encoding=ISO-8859-1 -jar /opt/HMServer/HMServer.jar /etc/config/HMServer.conf +fi diff --git a/homematic/rootfs/etc/services.d/lighttpd/run b/homematic/rootfs/etc/services.d/lighttpd/run new file mode 100644 index 0000000..b18efea --- /dev/null +++ b/homematic/rootfs/etc/services.d/lighttpd/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start light httpd service +# ============================================================================== +bashio::log.info "Initialize webinterface routing..." +exec lighttpd-angel -D -f "/opt/hm/etc/lighttpd/lighttpd.conf" diff --git a/homematic/rootfs/etc/services.d/nginx/finish b/homematic/rootfs/etc/services.d/nginx/finish new file mode 100644 index 0000000..a29ced9 --- /dev/null +++ b/homematic/rootfs/etc/services.d/nginx/finish @@ -0,0 +1,8 @@ +#!/usr/bin/execlineb -S1 +# ============================================================================== +# Take down the S6 supervision tree based on service exit code +# ============================================================================== +if { s6-test ${1} -ne 0 } +if { s6-test ${1} -ne 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/homematic/rootfs/etc/services.d/nginx/run b/homematic/rootfs/etc/services.d/nginx/run new file mode 100644 index 0000000..2b9b8e0 --- /dev/null +++ b/homematic/rootfs/etc/services.d/nginx/run @@ -0,0 +1,9 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start NGINX service +# ============================================================================== +# Wait for HomeMatic httpd +bashio::net.wait_for 80 + +bashio::log.info "Starting Nginx..." +exec nginx diff --git a/homematic/rootfs/etc/services.d/regahss/run b/homematic/rootfs/etc/services.d/regahss/run new file mode 100644 index 0000000..75827bd --- /dev/null +++ b/homematic/rootfs/etc/services.d/regahss/run @@ -0,0 +1,18 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start ReGaHss service +# ============================================================================== +# Wait until interfaces are initialized +bashio::log.info "Wait until HMServer is setup" +bashio::net.wait_for 9292 + +# Reset Regahss +if bashio::config.true "regahss_reset"; then + bashio::log.warning "Reset ReGaHss" + rm -f /data/homematic.regadom + touch /data/homematic.regadom +fi + +# Start Regahss +bashio::log.info "Starting ReGaHss..." +exec "/opt/hm/bin/ReGaHss" -c -f /etc/config/rega.conf diff --git a/homematic/rootfs/etc/services.d/rfd/finish b/homematic/rootfs/etc/services.d/rfd/finish new file mode 100644 index 0000000..a29ced9 --- /dev/null +++ b/homematic/rootfs/etc/services.d/rfd/finish @@ -0,0 +1,8 @@ +#!/usr/bin/execlineb -S1 +# ============================================================================== +# Take down the S6 supervision tree based on service exit code +# ============================================================================== +if { s6-test ${1} -ne 0 } +if { s6-test ${1} -ne 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/homematic/rootfs/etc/services.d/rfd/run b/homematic/rootfs/etc/services.d/rfd/run new file mode 100644 index 0000000..0653dcd --- /dev/null +++ b/homematic/rootfs/etc/services.d/rfd/run @@ -0,0 +1,10 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start HomeMatic RFD service +# ============================================================================== +if bashio::config.false 'rf_enable'; then + exec sleep infinity +fi + +bashio::log.info "Starting rfd..." +exec "/opt/hm/bin/rfd" -c -l 0 -f /opt/hm/etc/config/rfd.conf diff --git a/homematic/rootfs/etc/services.d/timesync/run b/homematic/rootfs/etc/services.d/timesync/run new file mode 100644 index 0000000..62138a9 --- /dev/null +++ b/homematic/rootfs/etc/services.d/timesync/run @@ -0,0 +1,14 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start HomeMatic RF timesync service +# ============================================================================== +if bashio::config.false 'rf_enable'; then + exec sleep infinity +fi + +while true +do + sleep 30m + bashio::log.info "$(date '+%Y-%m-%d %H:%M:%S.%3N') Run SetInterfaceClock now." + "/opt/hm/bin/SetInterfaceClock" 127.0.0.1:2001 +done diff --git a/homematic/rootfs/etc/services.d/wired/finish b/homematic/rootfs/etc/services.d/wired/finish new file mode 100644 index 0000000..a29ced9 --- /dev/null +++ b/homematic/rootfs/etc/services.d/wired/finish @@ -0,0 +1,8 @@ +#!/usr/bin/execlineb -S1 +# ============================================================================== +# Take down the S6 supervision tree based on service exit code +# ============================================================================== +if { s6-test ${1} -ne 0 } +if { s6-test ${1} -ne 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/homematic/rootfs/etc/services.d/wired/run b/homematic/rootfs/etc/services.d/wired/run new file mode 100644 index 0000000..6a6fe0b --- /dev/null +++ b/homematic/rootfs/etc/services.d/wired/run @@ -0,0 +1,10 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Start HomeMatic wired service +# ============================================================================== +if bashio::config.false 'wired_enable'; then + exec sleep infinity +fi + +bashio::log.info "Starting wired..." +exec "/opt/hm/bin/hs485d" -g -i 0 -f /opt/hm/etc/config/hs485d.conf diff --git a/homematic/data/config/HMServer.conf b/homematic/rootfs/opt/hm/etc/config/HMServer.conf similarity index 100% rename from homematic/data/config/HMServer.conf rename to homematic/rootfs/opt/hm/etc/config/HMServer.conf diff --git a/homematic/data/config/log4j.xml b/homematic/rootfs/opt/hm/etc/config/log4j.xml similarity index 100% rename from homematic/data/config/log4j.xml rename to homematic/rootfs/opt/hm/etc/config/log4j.xml diff --git a/homematic/data/config/rega.conf b/homematic/rootfs/opt/hm/etc/config/rega.conf similarity index 100% rename from homematic/data/config/rega.conf rename to homematic/rootfs/opt/hm/etc/config/rega.conf diff --git a/homematic/rootfs/usr/share/tempio/InterfacesList.xml b/homematic/rootfs/usr/share/tempio/InterfacesList.xml new file mode 100644 index 0000000..f0445b8 --- /dev/null +++ b/homematic/rootfs/usr/share/tempio/InterfacesList.xml @@ -0,0 +1,29 @@ + + + {{ if .rf_enable }} + + BidCos-RF + xmlrpc_bin://127.0.0.1:2001 + BidCos-RF + + {{ end }} + + VirtualDevices + xmlrpc://127.0.0.1:9292/groups + Virtual Devices + + {{ if .hmip_enable }} + + HmIP-RF + xmlrpc://127.0.0.1:2010 + HmIP-RF + + {{ end }} + {{ if .wired_enable }} + + Hm-Wired + xmlrpc://127.0.0.1:2000 + Hm-Wired + + {{ end }} + \ No newline at end of file diff --git a/homematic/data/config/crRFD.conf b/homematic/rootfs/usr/share/tempio/crRFD.conf similarity index 91% rename from homematic/data/config/crRFD.conf rename to homematic/rootfs/usr/share/tempio/crRFD.conf index 82b1063..1d889fe 100644 --- a/homematic/data/config/crRFD.conf +++ b/homematic/rootfs/usr/share/tempio/crRFD.conf @@ -42,3 +42,7 @@ KeyServer.Gateway.URL=secgtw.homematic.com Vertx.WorkerPoolSize=5 # USB HM/IP TRX Adapter Configuration +{{ range $index, $device := .hmip }} +Adapter.{{ $index }}.Type={{ $device.type }} +Adapter.{{ $index }}.Port={{ $device.device }} +{{ end }} \ No newline at end of file diff --git a/homematic/data/config/hs485d.conf b/homematic/rootfs/usr/share/tempio/hs485d.conf similarity index 55% rename from homematic/data/config/hs485d.conf rename to homematic/rootfs/usr/share/tempio/hs485d.conf index 328cab7..436244a 100644 --- a/homematic/data/config/hs485d.conf +++ b/homematic/rootfs/usr/share/tempio/hs485d.conf @@ -9,3 +9,11 @@ Device Description Dir = /firmware/hs485types Device Files Dir = /data/hs485d Firmware Dir = /firmware User Firmware Dir = /share/hm-firmware + +{{ range $index, $device := .wired }} +[Interface {{ $index }}] +Type = HMWLGW +Serial Number = {{ $device.serial }} +Encryption Key = {{ $device.key }} +IP Address = {{ $device.ip }} +{{ end }} \ No newline at end of file diff --git a/homematic/data/config/rfd.conf b/homematic/rootfs/usr/share/tempio/rfd.conf similarity index 65% rename from homematic/data/config/rfd.conf rename to homematic/rootfs/usr/share/tempio/rfd.conf index b197b35..d386fb3 100644 --- a/homematic/data/config/rfd.conf +++ b/homematic/rootfs/usr/share/tempio/rfd.conf @@ -12,3 +12,11 @@ Address File = /data/ids Firmware Dir = /firmware User Firmware Dir = /share/hm-firmware Replacemap File = /firmware/rftypes/replaceMap/rfReplaceMap.xml + +{{ range $index, $device := .rf }} +[Interface {{ $index }}] +Type = CCU2 +ComPortFile = {{ $device.device }} +AccessFile = /dev/null +ResetFile = /sys/class/gpio/gpio18/value +{{ end }} \ No newline at end of file