Browse Source

Prep. out trans

Joachim M. Giæver 1 year ago
parent
commit
cca96f4577
3 changed files with 17 additions and 19 deletions
  1. 1 1
      src/bin/cpy-2-zui
  2. 12 6
      src/helper/functions
  3. 4 12
      src/hooks/connect-plug-zui-store

+ 1 - 1
src/bin/cpy-2-zui

@@ -4,4 +4,4 @@ source $SNAP/helper/functions
 
 require_root
 
-cpy_2_zui && snapctl stop "${SNAP_NAME}" && snapctl disable "${SNAP_NAME}"
+cpy_2_zui && snapctl stop "${SNAP_NAME}" && snapctl stop --disable "${SNAP_NAME}"

+ 12 - 6
src/helper/functions

@@ -41,21 +41,27 @@ function same_network_key {
 
 function cpy_2_zui {
 	if snapctl is-connected zui-store; then
-		if [ -d "${SNAP_COMMON}/zui-store" ]; then
+		if [ "$(ls ${SNAP_COMMON}/zui-store) | wc -l" -ne 0 ]; then
+			echo "The zui-store (${SNAP_COMMON}/zui-store) is not empty, exiting..." >&2
+			exit 1
+		elif [ -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;
+				echo "Failed copying data from ${SNAP_COMMON}/zui-store" >&2
+				return 1
 			fi
+			mv "${SNAP_COMMON}/zui-store/logs" "${SNAP_COMMON}/zui-store/z2m-logs"
 		else
 			echo "Missing directory ${SNAP_COMMON}/zui-store, cannot write to it. Exiting..." >&2
-			exit 1;
+			exit 1
 		fi
 	else
-		echo "Cannot copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: `snap install zwave-js-ui`)." >&2
+		echo "Can not copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: `snap install zwave-js-ui`)." >&2
+		echo "Please install and connect with:" 1>&2
+		echo "$ snap connect ${SNAP_NAME}:zui-store zwave-js-ui:store-dir" >&2
 		return 1
 	fi
-	return 0;
+	return 0
 }
 
 function plug_connected {

+ 4 - 12
src/hooks/connect-plug-zui-store

@@ -1,15 +1,7 @@
 #!/usr/bin/env bash
-
-ZUI_STORE="${SNAP_COMMON}/zui-store"
-echo "$(ls -al ${ZUI_STORE})" >&2
-
-if [ ! -d "${ZUI_STORE}" ]; then
-	echo "Missing store-dir for ZUI. Failed, exiting...." >&2
+cpy_2_zui 
+if [ $? -eq 0 ]; then
+	sudo snap stop --disable "${SNAP_NAME}.${SNAP_NAME}"
+else
 	exit 1
-else 
-	"Have store dir, copy over" >&2 
-fi
-
-if [ $(ls "${ZUI_STORE}" | wc -l) -eq 0 ]; then
-	cpy_2_zui && sudo snap stop "${SNAP_NAME}" && sudo snap disable "${SNAP_NAME}"
 fi