mirror of
https://github.com/lildude/ha-addon-teslamate.git
synced 2026-10-13 21:19:16 -04:00
Update, refactor and restructure repo (#1)
* Remove unused files * Update dev env * Update config * Update docker config * Add translations * Update run script * Auto-gen enc key if not set * Replace workflows * Replace dependabot with renovate * Remove armhf * Lint * Remove armhf * Whoops * Remove stray comma * Add image * Reorder options * Split and improve docs * Add back image line * Update cw * Typo * Use correct org * Move bootstrap to run * Update scripts * Update config * Add note about database * Label in dockerfile * tmp force devcontainer version * Start implementing db creation if not exists * Create DB if doesn't exist * Update words * Remove unused file
This commit is contained in:
@@ -1,2 +1,9 @@
|
||||
#!/bin/sh
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
#!/command/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
|
||||
bashio::log.warning "Nginx crashed, halting add-on"
|
||||
/run/s6/basedir/bin/halt
|
||||
fi
|
||||
|
||||
bashio::log.info "Nginx stopped, restarting..."
|
||||
+4
-2
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/with-contenv sh
|
||||
#!/command/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
mkdir /run/nginx
|
||||
exec nginx -g 'daemon off;'
|
||||
exec nginx -g 'daemon off;error_log /proc/1/fd/1 error;'
|
||||
@@ -1,2 +1,9 @@
|
||||
#!/bin/sh
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
#!/command/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
|
||||
bashio::log.warning "TeslaMate crashed, halting add-on"
|
||||
/run/s6/basedir/bin/halt
|
||||
fi
|
||||
|
||||
bashio::log.info "TeslaMate stopped, restarting..."
|
||||
+70
-3
@@ -1,4 +1,36 @@
|
||||
#!/usr/bin/with-contenv sh
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Database things
|
||||
DATABASE_HOST=$(bashio::config 'database_host')
|
||||
DATABASE_NAME=$(bashio::config 'database_name')
|
||||
DATABASE_PASS=$(bashio::config 'database_pass')
|
||||
DATABASE_PORT=$(bashio::config 'database_port')
|
||||
DATABASE_USER=$(bashio::config 'database_user')
|
||||
|
||||
# MQTT things
|
||||
DISABLE_MQTT=$(bashio::config 'disable_mqtt')
|
||||
MQTT_HOST=$(bashio::config 'mqtt_host')
|
||||
MQTT_NAMESPACE=$(bashio::config 'mqtt_namespace')
|
||||
MQTT_PASSWORD=$(bashio::config 'mqtt_pass')
|
||||
MQTT_TLS_ACCEPT_INVALID_CERTS=$(bashio::config 'mqtt_tls_accept_invalid_certs')
|
||||
MQTT_TLS=$(bashio::config 'mqtt_tls')
|
||||
MQTT_USERNAME=$(bashio::config 'mqtt_user')
|
||||
|
||||
# Other things
|
||||
IMPORT_DIR=$(bashio::config 'import_dir')
|
||||
PORT=4000
|
||||
TZ=$(bashio::config 'timezone')
|
||||
DEFAULT_GEOFENCE=$(bashio::config 'default_geofence')
|
||||
|
||||
encryption_key=$(bashio::config 'encryption_key')
|
||||
if bashio::config.is_empty 'encryption_key'; then
|
||||
encryption_key=$(openssl rand -hex 32)
|
||||
bashio::addon.option 'encryption_key' "$encryption_key"
|
||||
fi
|
||||
ENCRYPTION_KEY=$(bashio::config 'encryption_key')
|
||||
|
||||
ingress_entry=$(curl -X GET \
|
||||
-H "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||
@@ -6,7 +38,42 @@ ingress_entry=$(curl -X GET \
|
||||
-s http://supervisor/addons/self/info | \
|
||||
jq -r '.data.ingress_entry')
|
||||
|
||||
sed -i "s^url: \[^url: \[path: \"${ingress_entry}\", ^" /opt/app/releases/*/runtime.exs
|
||||
export URL_PATH=$ingress_entry
|
||||
|
||||
export DATABASE_HOST DATABASE_NAME DATABASE_PASS DATABASE_PORT DATABASE_USER \
|
||||
DISABLE_MQTT MQTT_HOST MQTT_NAMESPACE MQTT_PASSWORD MQTT_TLS_ACCEPT_INVALID_CERTS \
|
||||
MQTT_TLS MQTT_USERNAME IMPORT_DIR PORT TZ DEFAULT_GEOFENCE ENCRYPTION_KEY URL_PATH
|
||||
|
||||
# Import dashboards
|
||||
if bashio::config.true 'grafana_import_dashboards'; then
|
||||
/dashboards.sh restore
|
||||
fi
|
||||
|
||||
# Create the PostgreSQL database if it doesn't exist
|
||||
if pg_isready -h "$DATABASE_HOST" -p "$DATABASE_PORT" > /dev/null 2>&1; then
|
||||
bashio::log.info "Creating database $DATABASE_NAME on $DATABASE_HOST"
|
||||
|
||||
res=$(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -c "CREATE DATABASE $DATABASE_NAME" 2>&1) || true
|
||||
case "$res" in
|
||||
"CREATE DATABASE")
|
||||
bashio::log.info "Database $DATABASE_NAME created"
|
||||
;;
|
||||
*"already exists"*)
|
||||
bashio::log.info "Database $DATABASE_NAME already exists"
|
||||
;;
|
||||
*)
|
||||
bashio::log.error "Failed to create database $DATABASE_NAME: $res"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
bashio::log.error "PostgreSQL is not ready"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ulimit -n 1048576
|
||||
|
||||
bashio::log.info "Starting TeslaMate"
|
||||
|
||||
cd /opt/app
|
||||
exec /ha-bootstrap.sh bin/teslamate start
|
||||
exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start
|
||||
|
||||
Reference in New Issue
Block a user