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

+ 0 - 29
src/helper/functions

@@ -51,35 +51,6 @@ function same_network_key {
     return 0
 }
 
-function cpy_2_zui {
-	if snapctl is-connected zui-store; then
-		if [ "$(ls "${SNAP_COMMON}/zui-store" | wc -l)" -ne 0 ]; then
-			lprint "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
-				lprint "Failed copying data from ${SNAP_COMMON}/zui-store" >&2
-				return 1
-			fi
-			mkdir -p "${SNAP_COMMON}/zui-store/logs/zwave-js"
-			mv "${SNAP_COMMON}/zui-store/zwave"*.{log,json} "${SNAP_COMMON}/zui-store/logs/zwave-js"
-			mv "${SNAP_COMMON}/zui-store/logs" "${SNAP_COMMON}/zui-store/.old-z2m-logs"
-			rm -rf "${SNAP_COMMON}/zui-store/.ext-config"
-			touch "${SNAP_DATA}/.z2m-cpy"
-		else
-			lprint "Missing directory ${SNAP_COMMON}/zui-store, cannot write to it. Exiting..." >&2
-			exit 1
-		fi
-	else
-		lprint "Can not copy config: Missing connection «store-dir» (offered by <zwave-js-ui>: 'snap install zwave-js-ui')." >&2
-		lprint "Please install and connect with:" 1>&2
-		lprint "$ snap connect ${SNAP_NAME}:zui-store zwave-js-ui:store-dir" >&2
-		return 1
-	fi
-	return 0
-}
-
 function plug_connected {
     if ! snapctl is-connected "${1}"; then
         lprint "Missing plug: «${1}»" >&2

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

@@ -11,12 +11,22 @@ if snapctl is-connected zui-store; then
 	if [ "$(ls "${ZUI_STORE}" | wc -l)" -ne 0 ]; then
 		lprint "ZUI-store (${ZUI_STORE}) is not empty: $(ls "${ZUI_STORE}")"
 		exit 1
+	elif [ -d "${ZUI_STORE}" ]; then
+		lprint "ZUI-store is empty, copying over data: $(ls "${SNAP_DATA}") to «${ZUI_STORE}»"
+		cp -rf "${SNAP_DATA}"* "${ZUI_STORE}"
+		rm -rf "${ZUI_STORE}/.ext-config"
+		mv -rf "${ZUI_STORE}/logs" "${ZUI_STORE}/.z2m-logs"
+		if [[ ! -d "${ZUI_STORE}/.z2m-logs" ]]; then
+			mkdir "${ZUI_STORE}/.z2m-logs"
+		fi
+		mv -rf "${ZUI_STORE}/zwave"*.{log,json} "${ZUI_STORE}/.z2m-logs"
+		lprint "Everything seems to be in place now..."
 	else
-		lprint "ZUI-store is empty, copying over data: $(ls "${SNAP_DATA}")"
+		lprint "Plug/slot = zui-store is connected, but «${ZUI_STORE}» is missing... WHY! 🤷"
 	fi
 else
 	lprint "ZUI-store is NOT connected, but why did we end up here then??"
 fi
 
 #lprint "Connected ZUI (from: z2m)"
-#
+