ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/utils/domoticz/files/domoticz.config b/external/subpack/utils/domoticz/files/domoticz.config
new file mode 100644
index 0000000..870701c
--- /dev/null
+++ b/external/subpack/utils/domoticz/files/domoticz.config
@@ -0,0 +1,29 @@
+config domoticz
+ option disabled '1'
+ option loglevel '1'
+ option syslog 'daemon'
+ # option sslcert '/path/to/ssl.crt'
+ # option sslkey '/path/to/ssl.key'
+ # option sslpass 'passphrase'
+ # option ssldhparam '/path/to/dhparam.pem'
+ option sslwww '0'
+ # CAUTION - by default, /var is not persistent accross reboots
+ # Don't forget the trailing / - domoticz requires it
+ option userdata '/var/lib/domoticz/'
+
+#config device
+# option product '658/200/0'
+# option symlink 'ttyACM-aeotec-zstick-g5'
+
+#config device
+# option serial '526359'
+# option symlink 'ttyUSB-serial'
+
+#config device
+# option usbif '2-1:1.0'
+# option symlink 'ttyUSB-port1'
+
+#config device
+# option product '67b/2303/202'
+# option usbif '2-2:1.0'
+# option symlink 'ttyUSB-port2'
diff --git a/external/subpack/utils/domoticz/files/domoticz.hotplug b/external/subpack/utils/domoticz/files/domoticz.hotplug
new file mode 100644
index 0000000..3cd8651
--- /dev/null
+++ b/external/subpack/utils/domoticz/files/domoticz.hotplug
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+. /lib/functions.sh
+
+[ "$SUBSYSTEM" = "tty" ] || exit 0
+
+add() {
+ local cfg="$1"
+ local product serial symlink usbif
+
+ [ -c "/dev/$DEVICENAME" ] || return
+
+ config_get product "$cfg" product
+ config_get serial "$cfg" serial
+ config_get symlink "$cfg" symlink
+ config_get usbif "$cfg" usbif
+
+ [ -z "$product" -a -z "$serial" -a -z "$usbif" ] && return
+
+ . "/sys/$DEVPATH/device/../uevent"
+ SERIAL="$(cat /sys/$DEVPATH/device/../../serial)" 2>/dev/null
+ USBIF="$(echo $DEVPATH | awk -F/ 'BEGIN {i=3}; /ACM/ {i=2}; END {print $(NF-i)}')"
+
+ [ -n "$product" -a "$product" != "$PRODUCT" ] && return
+ [ -n "$serial" -a "$serial" != "$SERIAL" ] && return
+ [ -n "$usbif" -a "$usbif" != "$USBIF" ] && return
+
+ chgrp domoticz "/dev/$DEVICENAME"
+ chmod g+rw "/dev/$DEVICENAME"
+
+ [ -n "$symlink" ] && ln -sf "/dev/$DEVICENAME" "/dev/$symlink"
+}
+
+remove() {
+ local cfg="$1"
+ local symlink
+
+ config_get symlink "$cfg" symlink
+
+ [ "/dev/$DEVICENAME" = "$(readlink /dev/$symlink)" ] && rm "/dev/$symlink"
+}
+
+config_load "domoticz"
+config_foreach "$ACTION" device
diff --git a/external/subpack/utils/domoticz/files/domoticz.init b/external/subpack/utils/domoticz/files/domoticz.init
new file mode 100644
index 0000000..8c0c129
--- /dev/null
+++ b/external/subpack/utils/domoticz/files/domoticz.init
@@ -0,0 +1,71 @@
+#!/bin/sh /etc/rc.common
+
+START=99
+USE_PROCD=1
+PROG=/usr/bin/domoticz
+PIDFILE=/var/run/domoticz.pid
+
+start_domoticz() {
+ local section="$1"
+ local loglevel sslcert sslpass sslwww syslog userdata
+
+ config_get loglevel "$section" "loglevel"
+ config_get sslcert "$section" "sslcert"
+ config_get sslkey "$section" "sslkey"
+ config_get sslpass "$section" "sslpass"
+ config_get ssldhparam "$section" "ssldhparam"
+ config_get sslwww "$section" "sslwww"
+ config_get syslog "$section" "syslog"
+ config_get userdata "$section" "userdata" userdata /var/lib/domoticz
+
+ [ -n "$loglevel" ] && procd_append_param command -loglevel "$loglevel"
+ [ -n "$syslog" ] && procd_append_param command -syslog "$syslog"
+
+ [ -d "${userdata}" ] || {
+ mkdir -p "${userdata}"
+ chmod 0770 "$userdata"
+ chown domoticz:domoticz "$userdata"
+ }
+
+ # By default, ${userdata}/scripts is a symlink to /etc/domoticz/scripts
+ # and the two dzVents directories under there which Domoticz will actually
+ # write to at runtime are symlinked back to /var/lib again.
+ [ -d "${userdata}/plugins" ] || ln -sf /etc/domoticz/plugins "${userdata}/plugins"
+ [ -d "${userdata}/scripts" ] || ln -sf /etc/domoticz/scripts "${userdata}/scripts"
+ for DIR in data generated_scripts; do
+ [ -d /var/lib/domoticz/dzVents/$DIR ] || {
+ mkdir -p /var/lib/domoticz/dzVents/$DIR
+ chown domoticz.domoticz /var/lib/domoticz/dzVents/$DIR
+ }
+ done
+ procd_append_param command -userdata "$userdata"
+
+ [ -n "$sslcert" -a "${sslwww:-0}" -gt 0 ] && {
+ procd_append_param command -sslcert "$sslcert"
+ procd_append_param command -sslwww "$sslwww"
+ [ -n "$sslkey" ] && procd_append_param command -sslkey "$sslkey"
+ [ -n "$sslpass" ] && procd_append_param command -sslpass "$sslpass"
+ [ -n "$ssldhparam" ] && procd_append_param command -ssldhparam "$ssldhparam"
+ } || procd_append_param command -sslwww 0
+}
+
+start_service() {
+ procd_open_instance
+
+ procd_set_param command "$PROG"
+ procd_append_param command -noupdates
+ procd_append_param command -approot /usr/share/domoticz/
+
+ config_load "domoticz"
+ config_get_bool disabled "$section" "disabled" 0
+ [ "$disabled" -gt 0 ] && return 1
+ config_foreach start_domoticz domoticz
+
+ procd_set_param pidfile "$PIDFILE"
+ procd_set_param respawn
+ procd_set_param stdout 0
+ procd_set_param term_timeout 10
+ procd_set_param user "domoticz"
+
+ procd_close_instance
+}