Browse Source

Add plug to extend library

Joachim M. Giæver 3 years ago
parent
commit
e960065fee
4 changed files with 27 additions and 1 deletions
  1. 15 0
      scripts/config/plug-bin
  2. 3 0
      scripts/hooks/connect-plug-bin
  3. 3 0
      snap/hooks/disconnect-plug-bin
  4. 6 1
      snap/snapcraft.yaml

+ 15 - 0
scripts/config/plug-bin

@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+snapctl is-connected bin
+
+if [ $? -eq 0 ]; then
+    readarray -d '' PATHS < <(find $SNAP -maxdepth 2 -type d -name bin -path "$SNAP/shared-bin*" -print0)
+
+    if [ "${#PATHS[@]}" -ne 0 ]; then
+        for TPATH in "${PATHS[@]}"; do
+            PATH="${PATH}:${TPATH}"
+        done
+    fi
+fi
+
+eval $@

+ 3 - 0
scripts/hooks/connect-plug-bin

@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+snapctl restart "${SNAP_NAME}"

+ 3 - 0
snap/hooks/disconnect-plug-bin

@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+snapctl restart "${SNAP_NAME}"

+ 6 - 1
snap/snapcraft.yaml

@@ -53,6 +53,8 @@ hooks:
 apps:
   home-assistant-snap:
     command: bin/hass --config $SNAP_DATA
+    command-chain:
+      - bin/plug-bin
     daemon: simple
     environment:
       PIP_USER: 1
@@ -62,7 +64,7 @@ apps:
       - network
       - network-bind
       - raw-usb
-      # GPIO devices etc.. (e.g RaZberry GPIO hat)
+      # GPIO devices etc.. (e.g RaZberry HAT)
       - physical-memory-control
     slots: 
       - components
@@ -152,6 +154,7 @@ parts:
       configure: snap/hooks/configure
       post-refresh: snap/hooks/post-refresh
       prepare-slot-certs: snap/hooks/prepare-slot-certs
+      connect-plug-bin: snap/hooks/connect-plug-bin
   bins:
     plugin: dump
     source: ./scripts/bin
@@ -163,3 +166,5 @@ parts:
     plugin: dump
     source: ./scripts/config
     source-type: local
+    organize:
+      plug-bin: bin/plug-bin