Browse Source

Add missing files

Joachim M. Giæver 2 years ago
parent
commit
468060ca88
3 changed files with 78 additions and 0 deletions
  1. 8 0
      source/hooks/connect-plug-components
  2. 8 0
      source/hooks/disconnect-plug-components
  3. 62 0
      source/install

+ 8 - 0
source/hooks/connect-plug-components

@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+CWD=$(pwd)
+
+export CONNECT=1
+$SNAP/bin/install
+
+cd "${CWD}"

+ 8 - 0
source/hooks/disconnect-plug-components

@@ -0,0 +1,8 @@
+#!/bin/sh -e
+
+CC="${SNAP_DATA}/custom_components/hacs"
+logger "${SNAP_NAME} removing: - ${CC}"
+rm -rf "${CC}"
+if [ $? -eq 0 ]; then
+    logger "Removed ${CC}"
+fi

+ 62 - 0
source/install

@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+
+function is_root {
+    if [ ${EUID:-$(id -u)} -eq 0 ]; then
+        return 0
+    fi
+    return 1
+}
+
+function lognecho {
+    for STR in "${@}"; do
+        logger "${STR}"
+        echo "${STR}"
+    done
+}
+
+function yn {
+    read -p "Procced? [y/n]: " CHOICE
+    case ${CHOICE} in
+        y)
+            return 0
+            ;;
+        n)
+            return 1
+            ;;
+        *)
+            yn
+            ;;
+    esac
+}
+
+is_root
+if [ $? -ne 0 ]; then
+    lognecho "Root is required. Run with sudo:" "$ sudo ${SNAP_NAME}.install"
+    exit 1
+fi
+
+if snapctl is-connected components; then
+    if [ -n ${CONNECT-} ]; then 
+        if [ -d "$SNAP_DATA/custom_components/hacs" ]; then
+            lognecho "${SNAP_NAME} is already installed. Re-installing it will overwrite current installation."
+            yn
+            if [ $? -ne 0 ]; then
+                exit 1
+            fi
+        fi
+    fi
+
+    lognecho "Installing ${SNAP_NAME} into your Home Assistant installation: ${SNAP_DATA}"
+
+    cd "${SNAP_DATA}"
+    export haPath="${SNAP_DATA}"
+    ${SNAP}/hacs
+    if [ $? -ne 0 ]; then
+        lognecho "Installation of ${SNAP_DATA} failed!"
+    else
+        lognecho "Installation of ${SNAP_DATA} successful."
+    fi
+else
+    lognecho "${SNAP_NAME}:components is not connected, connect with:" "$ snap connect ${SNAP_NAME}:components home-assistant-snap:components"
+    exit 1
+fi