Use alternate method for addon detection

This commit is contained in:
tsightler
2022-10-10 20:24:22 -04:00
parent 6368a75665
commit d3a6376ccd
6 changed files with 635 additions and 574 deletions

View File

@@ -8,8 +8,8 @@
# for the detected environment.
# ==============================================================================
# If options.json exist we are running as addon
if [ -f /data/options.json ]; then
# If HASSIO_TOKEN variable exist we are running as addon
if [ -v HASSIO_TOKEN ]; then
RUNMODE_BANNER_DESCRIPTION="Addon for Home Assistant "
# Use bashio to get configured branch
export BRANCH=$(bashio::config "branch")

View File

@@ -11,28 +11,6 @@
# Delay to keep logs messages from overlapping with s6 logs
sleep .5
if [ -f /data/options.json ]; then
export RUNMODE=addon
export BRANCH=$(bashio::config "branch")
export DEBUG=$(bashio::config "debug")
else
export RUNMODE=docker
# If debug is not explicitly defined, use default
if [ ! -v DEBUG ]; then
export DEBUG="ring-*"
fi
fi
if [ -v BRANCH ]; then
if [ "${BRANCH}" = "latest" ] || [ "${BRANCH}" = "dev" ]; then
cd "/app/ring-mqtt-${BRANCH}"
else
cd /app/ring-mqtt
fi
else
cd /app/ring-mqtt
fi
echo "-------------------------------------------------------"
echo -n "ring-mqtt.js version: "
echo $(cat package.json | grep version | cut -f4 -d'"')
@@ -41,21 +19,46 @@ echo NPM version $(npm -v)
git --version
echo "-------------------------------------------------------"
if [ "${RUNMODE}" = "addon" ]; then
# Export a few helper variables for building the Streaming and Still Image URLs
export HAHOSTNAME=$(bashio::info.hostname)
export ADDONHOSTNAME=$HOSTNAME
# If HASSIO_TOKEN variable exist we are running as addon
if [ -v HASSIO_TOKEN ]; then
export RUNMODE="addon"
bashio::config.require 'mqtt_url'
# Wait just a few seconds to give HA a little more time for service discovery to initialize
sleep 5
# Export MQTT service discovery data for use within NodeJS process
if bashio::services.available 'mqtt'; then
export HAMQTTHOST=$(bashio::services mqtt "host")
export HAMQTTPORT=$(bashio::services mqtt "port")
export HAMQTTUSER=$(bashio::services mqtt "username")
export HAMQTTPASS=$(bashio::services mqtt "password")
export BRANCH=$(bashio::config "branch")
export DEBUG=$(bashio::config "debug")
# Export MQTT service discovery data for use within NodeJS process
if bashio::services.available 'mqtt'; then
export HAMQTTHOST=$(bashio::services mqtt "host")
export HAMQTTPORT=$(bashio::services mqtt "port")
export HAMQTTUSER=$(bashio::services mqtt "username")
export HAMQTTPASS=$(bashio::services mqtt "password")
fi
# Export a few helper variables for building the Streaming and Still Image URLs
export HAHOSTNAME=$(bashio::info.hostname)
export ADDONHOSTNAME=$HOSTNAME
fi
else
export RUNMODE=docker
# If branch is not explicitly defined, use builtin branch
if [ ! -v BRANCH]; then
export BRANCH="builtin"
fi
# If debug is not explicitly defined, use default
if [ ! -v DEBUG ]; then
export DEBUG="ring-*"
fi
fi
if [ "${BRANCH}" = "latest" ] || [ "${BRANCH}" = "dev" ]; then
cd "/app/ring-mqtt-${BRANCH}"
else
cd /app/ring-mqtt
fi
echo "Running ring-mqtt..."
exec ./ring-mqtt.js