Browse Source

Add more logic

Joachim M. Giæver 1 year ago
parent
commit
d4c8e6c59e
2 changed files with 12 additions and 4 deletions
  1. 10 4
      src/helper/functions
  2. 2 0
      src/hooks/connect-plug-zui-store

+ 10 - 4
src/helper/functions

@@ -40,10 +40,16 @@ function same_network_key {
 }
 
 function cpy_2_zui {
-	if snapctl is-connected store-dir; then
-		cp -rf "${SNAP_DATA}/"* "${SNAP_COMMON}/zui-store"
-		if [ $? -ne 0 ]; then
-			return 1;
+	if snapctl is-connected zui-store; then
+		if [ -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";
+				return 1;
+			fi
+		else
+			echo "Missing directory ${SNAP_COMMON}/zui-store, cannot write to it. Exiting..." >&2
+			exit 1;
 		fi
 	else
 		echo "Cannot copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: `snap install zwave-js-ui`)." >&2

+ 2 - 0
src/hooks/connect-plug-zui-store

@@ -6,6 +6,8 @@ echo "$(ls -al ${ZUI_STORE})" >&2
 if [ ! -d "${ZUI_STORE}" ]; then
 	echo "Missing store-dir for ZUI. Failed, exiting...." >&2
 	exit 1
+else 
+	"Have store dir, copy over" >&2 
 fi
 
 if [ $(ls "${ZUI_STORE}" | wc -l) -eq 0 ]; then