diff --git a/gazpar2mqtt/rootfs/scripts/91-run_mqtt_autodiscover.sh b/gazpar2mqtt/rootfs/scripts/91-run_mqtt_autodiscover.sh new file mode 100644 index 000000000..559d75075 --- /dev/null +++ b/gazpar2mqtt/rootfs/scripts/91-run_mqtt_autodiscover.sh @@ -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 diff --git a/gazpar2mqtt/rootfs/scripts/90-config_yaml.sh b/gazpar2mqtt/rootfs/scripts/92-config_yaml.sh similarity index 89% rename from gazpar2mqtt/rootfs/scripts/90-config_yaml.sh rename to gazpar2mqtt/rootfs/scripts/92-config_yaml.sh index 72f51ed13..943fd57f1 100644 --- a/gazpar2mqtt/rootfs/scripts/90-config_yaml.sh +++ b/gazpar2mqtt/rootfs/scripts/92-config_yaml.sh @@ -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 diff --git a/gazpar2mqtt/rootfs/scripts/99-run.sh b/gazpar2mqtt/rootfs/scripts/99-run.sh index 2ea5ad390..9f72cada8 100644 --- a/gazpar2mqtt/rootfs/scripts/99-run.sh +++ b/gazpar2mqtt/rootfs/scripts/99-run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bashio +#!/usr/bin/env bashio ############## # Launch App #