Files
addons/almond/data/run.sh
Pascal Vizeli b48fa995b3 Almond (#807)
* Initial support for almond

* Fix execution

* Fix package

* fix style

* Use package

* Try origin

* Fix build

* Fix build

* Support multiarch

* Fix readme

* Remove i386

* Fix pipeline

* Update version

* cleanup

* Fix name

* test-ingress

* Improve nginx

* cleanup config

* add panel icon

* Add support for ingress

* Add API access

* Fix script

* Fix panel icon

* fix quite mode

* Update run.sh

* Fix auth

* Update almond version

* Update version

* Fix lint

* do not modify hostname

* Update version

* Address comments

* Fix nginx

* cleanup

* working

* Update version

* Fix API injection

* cleanup nginx config

* do not set an refresh token

* Update almond/data/run.sh

Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>

* Fix command

* change timehandling

* debug code

* debug v2

* Fix value

* Debug v3

* Cleanup

* Fix token valid

* Fix command

* Add debug

* Add unzip

* Fix config settings
2019-10-29 19:04:33 +01:00

64 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bashio
WAIT_PIDS=()
TOKEN_VALID="$(python3 -c "import time; print((time.time() + 60 * 60 * 24 * 365 * 5) * 1000)")"
ha_config=$(\
bashio::var.json \
host "$(hostname)" \
port "3001" \
)
almond_config=$(\
bashio::var.json \
kind "io.home-assistant" \
hassUrl "http://hassio/homeassistant" \
accessToken "${HASSIO_TOKEN}" \
refreshToken "" \
accessTokenExpires "^${TOKEN_VALID}" \
)
# HA Discovery
if bashio::discovery "almond" "${ha_config}" > /dev/null; then
bashio::log.info "Successfully send discovery information to Home Assistant."
else
bashio::log.error "Discovery message to Home Assistant failed!"
fi
# Ingress handling
# shellcheck disable=SC2155
export THINGENGINE_BASE_URL=$(bashio::addon.ingress_entry)
# Setup nginx
nginx -c /etc/nginx/nginx.conf &
WAIT_PIDS+=($!)
# Skip Auth handling
if ! bashio::fs.file_exists "${THINGENGINE_HOME}/prefs.db"; then
mkdir -p "${THINGENGINE_HOME}"
echo '{"server-login":{"password":"x","salt":"x","sqliteKeySalt":"x"}}' > "${THINGENGINE_HOME}/prefs.db"
fi
# Start Almond
yarn start &
WAIT_PIDS+=($!)
# Insert HA connection settings
bashio::net.wait_for 3000
if curl -f -s -X POST -H "Content-Type: application/json" -d "${almond_config}" http://127.0.0.1:3000/api/devices/create; then
bashio::log.info "Successfully register local Home Assistant on Almond"
else
bashio::log.error "Almond registration of local Home Assistant fails!"
fi
# Register stop
function stop_addon() {
echo "Kill Processes..."
kill -15 "${WAIT_PIDS[@]}"
wait "${WAIT_PIDS[@]}"
echo "Done."
}
trap "stop_addon" SIGTERM SIGHUP
# Wait until all is done
wait "${WAIT_PIDS[@]}"