Quellcode durchsuchen

Require hardware-observe, as UI will query for devices

Joachim M. Giæver vor 3 Jahren
Ursprung
Commit
bdd7c7eead
5 geänderte Dateien mit 26 neuen und 95 gelöschten Zeilen
  1. 11 3
      snap/snapcraft.yaml
  2. 5 5
      src/bin/daemonize
  3. 4 4
      src/bin/de-daemonize
  4. 0 81
      src/bin/env-wrapper
  5. 6 2
      src/bin/restart

+ 11 - 3
snap/snapcraft.yaml

@@ -15,6 +15,14 @@ description: |
 grade: stable # must be 'stable' to release into candidate/stable channels
 confinement: strict # use 'strict' once you have the right plugs and slots
 
+assumes:
+  - command-chain
+
+architectures:
+  - build-on: amd64
+  - build-on: arm64
+  - build-on: armhf
+
 apps:
   zwavejs2mqtt:
     daemon: simple
@@ -24,7 +32,7 @@ apps:
       DAEMONIZED: 1
     command: usr/lib/zwavejs2mqtt/bin/www
     command-chain:
-      - bin/env-wrapper
+      - helper/env-wrapper
     plugs:
       - network
       - network-bind
@@ -35,14 +43,14 @@ apps:
       STORE_DIR: $SNAP_DATA
     command: usr/lib/zwavejs2mqtt/bin/www
     command-chain:
-      - bin/env-wrapper
+      - helper/env-wrapper
     plugs:
       - network
       - network-bind
       - raw-usb
       - hardware-observe
   help:
-    command: bin/env-wrapper --help
+    command: helper/env-wrapper --help
   enable:
     command: bin/daemonize
   disable:

+ 5 - 5
src/bin/daemonize

@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 
-if [ $(id -u) -ne 0 ]; then
-    echo "Run as root" >&2
-    exit 1
-fi
+source $SNAP/helper/functions
+
+require_root
+plugs_connected
 
-if ! snapctl is-connected raw-usb; then
+if [ $? -ne 0 ]; then
     echo "Failed to enable ${SNAP_NAME} service!" >&2
     echo ""
     echo "Consult the help command:" >&2

+ 4 - 4
src/bin/de-daemonize

@@ -1,9 +1,8 @@
 #!/usr/bin/env bash
 
-if [ $(id -u) -ne 0 ]; then
-    echo "Run as root" >&2
-    exit 1
-fi
+source $SNAP/helper/functions 
+
+require_root
 
 snapctl stop --disable "${SNAP_NAME}.${SNAP_NAME}"
 
@@ -11,5 +10,6 @@ if [ $? -eq 0 ]; then
     echo "Service ${SNAP_NAME} disabled."
     exit 0
 fi
+
 echo "Failed disabling ${SNAP_NAME} service" >&2
 exit 1

+ 0 - 81
src/bin/env-wrapper

@@ -1,81 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-if [ -z ${DAEMONIZED} ]; then
-    DAEMONIZED=0
-fi
-
-function lprint {
-    if [ ${DAEMONIZED} -eq 0 ]; then
-        echo ${1}
-    else
-        logger "${SNAP_NAME}: ${1}"
-    fi
-}
-
-if ! snapctl is-connected raw-usb; then
-    lprint "Please connect raw-usb interface!"
-    lprint "Run: snap connect ${SNAP_NAME}:raw-usb"
-    exit 1
-fi
-
-export NETWORK_KEY=$(snapctl get network.key)
-
-if [ -f "${SNAP_DATA}/settings.json" ]; then
-    SETTINGS_KEY=$(jq '.zwave.networkKey' -r ${SNAP_DATA}/settings.json)
-    if [ "${SETTINGS_KEY}" != "" ] && [ "${NETWORK_KEY}" != "${SETTINGS_KEY}" ]; then
-        snapctl set network.key="${SETTINGS_KEY}"
-        export NETWORK_KEY="${SETTINGS_KEY}"
-    fi
-fi
-
-export SERVER_SSL=$(snapctl get server.ssl)
-export SERVER_HOST=$(snapctl get server.host)
-export SERVER_PORT=$(snapctl get server.port)
-export SERVER_URL=$(snapctl get server.url)
-export SERVER_WS_URL=$(snapctl get server.ws-url)
-
-OPT_HELP=false
-
-if [ "${1}" = "--help" ]; then
-    OPT_HELP=true
-fi
-
-export GIT_DIR="${SNAP}/usr/lib/zwavejs2mqtt/.git"
-
-if [ ${OPT_HELP} = true ]; then
-    echo "Zwavejs2mqtt ($ ($ 1 --version))"
-    echo ""
-    echo "IMPORTANT! The DAEMON/SERVICE is disabled by default after installation." 
-    echo "You have to manually 'daemonize' OpenZWave Daemon with executing the command"
-    echo ""
-    echo "$ ${SNAP_NAME}.enable"
-    echo ""
-    echo "But first set your configuration as descrived below"
-    echo ""
-    echo "Base configuration values:"
-    echo "- network.key:               $(snapctl get network.key)"
-    echo "Server configuration values: $(snapctl get server -d)"
-    echo ""
-    echo "- server.ssl: Use secure communication"
-    echo "- server.host: IP address to bind to, e.g 127.0.0.1"
-    echo "- server.port: Port to reach the web interface"
-    echo "- server.url: Hostname for http/https"
-    echo "- server.ws-url: Hostname for websocket"
-    echo ""
-    echo "Set options with:         $ snap set ${SNAP_NAME} param=key"
-    echo "For example:              $ snap set ${SNAP_NAME} server.host=0.0.0.0"
-    echo ""
-    echo "Also see 'snap info ${SNAP_NAME}'."
-    echo ""
-    echo "Follow the log with"
-    echo "$ snap logs ${SNAP_NAME} -f"
-    echo ""
-    echo "Other commands"
-    echo "Disable the daemon:       $ ${SNAP_NAME}.disable"
-    echo "Restart the daemon:       $ ${SNAP_NAME}.restart"
-    exit 0
-fi
-
-exec "$@"

+ 6 - 2
src/bin/restart

@@ -1,8 +1,12 @@
 #!/usr/bin/env bash
 set -e
 
-if [ $(id -u) -ne 0 ]; then
-    echo "Run as root!" >&2
+source $SNAP/helper/functions
+
+require_root
+
+plugs_connected
+if [ $? -ne 0 ]; then
     exit 1
 fi