Browse Source

Added writeable config directory for zwave-js

Joachim M. Giæver 3 years ago
parent
commit
f2d80ef9da
4 changed files with 23 additions and 2 deletions
  1. 4 2
      snap/snapcraft.yaml
  2. 9 0
      src/helper/functions
  3. 3 0
      src/hooks/install
  4. 7 0
      src/hooks/post-refresh

+ 4 - 2
snap/snapcraft.yaml

@@ -61,9 +61,9 @@ apps:
 layout:
   /usr/src/app/store:
     bind: $SNAP_DATA/zwavejs2mqtt/store
-  $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config/devices/index.json:
+  $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config:
     # bind-file: $SNAP_DATA/config/devices/index.json
-    bind-file: $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config/devices/index.json
+    bind: $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config
 
 parts:
   zwavejs2mqtt:
@@ -93,6 +93,8 @@ parts:
       - -usr/lib/zwavejs2mqtt/docker
       - -usr/lib/zwavejs2mqtt/.dockerignore
       - -usr/lib/zwavejs2mqtt/.markdown*
+    organize:
+      usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config: snap/zwave-js/config
   nodejs:
     plugin: dump
     source:

+ 9 - 0
src/helper/functions

@@ -1,5 +1,14 @@
 #!/usr/bin/env bash
 
+function ensure_zwavejs_config {
+    ZWAVE_JS_CONF="${SNAP}/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config"
+
+    if [ "$(find ${ZWAVE_JS_CONF} -maxdepth 0 -empty -exec echo empty \;)" == "empty" ]; then
+        logger "Config directory is empty, copying data"
+        cp -rf $SNAP/snap/zwave-js/config/* "${ZWAVE_JS_CONF}" 
+    fi
+}
+
 function plugs_connected {
     MISSING=0
     if ! snapctl is-connected raw-usb; then

+ 3 - 0
src/hooks/install

@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 
 set -e
+source $SNAP/helper/functions
 
 snapctl set network.key="$(cat /dev/urandom | LC_ALL=C tr -dc '0-9A-F' | fold -w 32 | head -n 1)"
 snapctl set server.ssl=false
@@ -10,3 +11,5 @@ snapctl set server.url=false
 snapctl set server.ws-url=false
 
 snapctl stop --disable "${SNAP_NAME}.${SNAP_NAME}"
+
+ensure_zwavejs_config

+ 7 - 0
src/hooks/post-refresh

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+set -e
+
+source $SNAP/helper/functions
+
+ensure_zwavejs_config