Forráskód Böngészése

backup device config

Joachim M. Giæver 3 éve
szülő
commit
50aa08f039
5 módosított fájl, 21 hozzáadás és 7 törlés
  1. 8 4
      snap/snapcraft.yaml
  2. 1 1
      src/helper/env-wrapper
  3. 4 1
      src/helper/functions
  4. 2 0
      src/hooks/install
  5. 6 1
      src/hooks/post-refresh

+ 8 - 4
snap/snapcraft.yaml

@@ -46,7 +46,7 @@ apps:
       STORE_DIR: $SNAP_DATA
       ZWAVEJS_EXTERNAL_CONFIG: $SNAP_DATA/.ext-config
       #command: lib/node_modules/zwavejs2mqtt/bin/www.ts
-    command: lib/node_modules/yarn/bin/yarn --cwd $SNAP/lib/node_modules/zwavejs2mqtt --global-folder $SNAP/lib/node_modules/npm/node_modules start
+    command: lib/node_modules/yarn/bin/yarn --cwd $SNAP/lib/node_modules/zwavejs2mqtt start
     command-chain:
       - helper/env-wrapper
     plugs:
@@ -65,8 +65,12 @@ apps:
     command: bin/restart
 
 layout:
-  $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config:
-    bind: $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config
+  $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config:
+    bind: $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config
+  /usr/local/share/.cache/yarn:
+    bind: $SNAP/.cache/yarn
+  /usr/local/share/.yarn:
+    symlink: $SNAP/lib/node_modules
   #$SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-jspackages/zwave-js/src/lib/driver/
 
 parts:
@@ -91,7 +95,7 @@ parts:
         && cp --archive --link --no-dereference $SNAPCRAFT_PART_BUILD \
           $SNAPCRAFT_PART_INSTALL/lib/node_modules/zwavejs2mqtt \
     organize:
-      lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config: snap/zwave-js/config
+      lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config: snap/zwave-js/config
       lib/node_modules/zwavejs2mqtt/dist: lib/node_modules/zwavejs2mqtt/server/dist
       lib/node_modules/zwavejs2mqtt/views: lib/node_modules/zwavejs2mqtt/server/views
     filesets:

+ 1 - 1
src/helper/env-wrapper

@@ -75,7 +75,7 @@ if [ $? -ne 0 ]; then
     exit 1
 fi
 
-ensure_zwavejs_config
+# ensure_zwavejs_config
 
 export SERVER_SSL=$(snapctl get server.ssl)
 export SERVER_HOST=$(snapctl get server.host)

+ 4 - 1
src/helper/functions

@@ -1,10 +1,13 @@
 #!/usr/bin/env bash
 
+export ZWAVE_JS_CONF="${SNAP}/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config"
+
 function ensure_zwavejs_config {
-    ZWAVE_JS_CONF="${SNAP}/lib/node_modules/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 from ${SNAP}/snap/zwave-js/config"
         rsync -raz "${SNAP}/snap/zwave-js/config" "${ZWAVE_JS_CONF}/.."
+    else
+        logger "Config directory ${ZWAVE_JS_CONF} exists"
     fi
     return 0
 }

+ 2 - 0
src/hooks/install

@@ -10,6 +10,8 @@ if [ $? -eq 0 ]; then
     SETTINGS_KEY=$(cat /dev/urandom | LC_ALL=C tr -dc '0-9A-F' | fold -w 32 | head -n 1)
 fi
 
+ensure_zwavejs_config
+
 testnset_config "network.key" "${SETTINGS_KEY}"
 test_default_config
 

+ 6 - 1
src/hooks/post-refresh

@@ -2,6 +2,11 @@
 
 source $SNAP/helper/functions
 
-ensure_zwavejs_config
+if [ -d "${SNAP_COMMON}/latest-device-config/config" ]; then
+    logger "Restoring latest device config latest-device-config to ${ZWAVE_JS_CONF}"
+    rsync -raz "${SNAP_COMMON}/latest-device-config/config" "${ZWAVE_JS_CONF}/.."
+else
+    ensure_zwavejs_config
+fi
 
 test_default_config