mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-27 23:17:38 +01:00
allow mqtt autodiscover
This commit is contained in:
25
gazpar2mqtt/rootfs/scripts/91-run_mqtt_autodiscover.sh
Normal file
25
gazpar2mqtt/rootfs/scripts/91-run_mqtt_autodiscover.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bashio
|
||||
|
||||
#####################
|
||||
# Autodiscover mqtt #
|
||||
#####################
|
||||
|
||||
if bashio::config.true 'mqtt_autodiscover'; then
|
||||
bashio::log.info "mqtt_autodiscover is defined in options, attemption autodiscovery..."
|
||||
# Check if available
|
||||
[ ! bashio::services.available "mqtt" ] && bashio::exit.nok "No internal MQTT service found. Please install Mosquitto broker"
|
||||
# Get variables
|
||||
bashio::log.info "... MQTT service found, fetching server detail ..."
|
||||
export MQTT_HOST=$(bashio::services mqtt "host")
|
||||
export MQTT_PORT=$(bashio::services mqtt "port")
|
||||
export MQTT_SSL=$(bashio::services mqtt "ssl")
|
||||
export MQTT_USERNAME=$(bashio::services mqtt "username")
|
||||
export MQTT_PASSWORD=$(bashio::services mqtt "password")
|
||||
# Export variables
|
||||
for variables in "MQTT_HOST=$MQTT_HOST" "MQTT_PORT=$MQTT_PORT" "MQTT_SSL=$MQTT_SSL" "MQTT_USERNAME=$MQTT_USERNAME" "MQTT_PASSWORD=$MQTT_PASSWORD"; do
|
||||
sed -i "1a export $variables" /etc/services.d/*/*run*
|
||||
sed -i "1a export $variables" /scripts/*run*
|
||||
done
|
||||
# Log
|
||||
bashio::log.info "Received user: '$MQTT_USERNAME' for MQTT at '$MQTT_HOST:$MQTT_PORT'!"
|
||||
fi
|
||||
@@ -45,10 +45,10 @@ function parse_yaml {
|
||||
local prefix=$2 || local prefix=""
|
||||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
|
||||
sed -ne "s|^\($s\):|\1|" \
|
||||
-e "s| #.*$||g" \
|
||||
-e "s|#.*$||g" \
|
||||
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||
-e "s| #.*$||g" \
|
||||
-e "s|#.*$||g" \
|
||||
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||
awk -F$fs '{
|
||||
indent = length($1)/2;
|
||||
vname[indent] = $2;
|
||||
@@ -84,11 +84,11 @@ while IFS= read -r line; do
|
||||
export $line # Export the variable
|
||||
logmsg="Variable set : $line"
|
||||
if [ -f /etc/services.d/*/*run* ]; then
|
||||
sed -i "1a export $line" /etc/services.d/*/run # Export the variable
|
||||
sed -i "1a export $line" /etc/services.d/*/run # Export the variable
|
||||
sed -i "1a bashio::log.blue \"$logmsg\" || echo \"$logmsg\"" /etc/services.d/*/run # Show text in colour
|
||||
fi
|
||||
if [ -f /scripts/*run* ]; then
|
||||
sed -i "1a export $line" /scripts/*run* # Export the variable
|
||||
sed -i "1a export $line" /scripts/*run* # Export the variable
|
||||
sed -i "1a bashio::log.blue \"$logmsg\" || echo \"$logmsg\"" /scripts/*run* # Show text in colour
|
||||
fi
|
||||
bashio::log.blue "$line"
|
||||
@@ -101,8 +101,8 @@ done <"/tmpfile"
|
||||
# Test mode
|
||||
TZ=$(bashio::config "TZ")
|
||||
if [ $TZ = "test" ]; then
|
||||
echo "secret mode found, launching script in /config/test.sh"
|
||||
cd /config
|
||||
chmod 777 test.sh
|
||||
./test.sh
|
||||
echo "secret mode found, launching script in /config/test.sh"
|
||||
cd /config
|
||||
chmod 777 test.sh
|
||||
./test.sh
|
||||
fi
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bashio
|
||||
#!/usr/bin/env bashio
|
||||
|
||||
##############
|
||||
# Launch App #
|
||||
|
||||
Reference in New Issue
Block a user