File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
node-red/rootfs/etc/cont-init.d Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/with-contenv bash
2
+ # ==============================================================================
3
+ # Community Hass.io Add-ons: Node-RED
4
+ # Ensures the correct API key is in the Node-RED configuration
5
+ # ==============================================================================
6
+ # shellcheck disable=SC1091
7
+ source /usr/lib/hassio-addons/base.sh
8
+
9
+ readonly CONFIG_FILE=" /config/node-red/flows.json"
10
+
11
+ declare TMP_FILE
12
+ declare url
13
+ declare key
14
+ declare base_query
15
+ declare query
16
+
17
+ base_query=' .[] | select(.url=="http://hassio/homeassistant" and .type=="server")'
18
+
19
+ url=$( jq -r " ${base_query} | .url" " ${CONFIG_FILE} " )
20
+ key=$( jq -r " ${base_query} | .pass" " ${CONFIG_FILE} " )
21
+
22
+ if [[ " ${url} " = " http://hassio/homeassistant"
23
+ && " ${key} " != " ${HASSIO_TOKEN} "
24
+ ]];
25
+ then
26
+ TMP_FILE=$( mktemp)
27
+
28
+ hass.log.info ' API token is incorrect in the Node-RED configuration, fixing...'
29
+
30
+ jq " (${base_query} ) = ((${base_query} ) + {\" pass\" : \" ${HASSIO_TOKEN} \" })" " ${CONFIG_FILE} " > " ${TMP_FILE} " \
31
+ || hass.die ' Failed to set Hass.io API token into the Node-RED config'
32
+
33
+ mv " ${TMP_FILE} " " ${CONFIG_FILE} " \
34
+ || hass.die ' Failed updating the Hass.io configuration'
35
+ fi
You can’t perform that action at this time.
0 commit comments