From f7ce6199f91c6f7288e41110d12bebd935261ea1 Mon Sep 17 00:00:00 2001 From: Gyurix Date: Sat, 19 Oct 2024 11:01:52 +0200 Subject: [PATCH] created initial files for deploying homeassistant server --- Dockerfile | 6 ++++++ entrypoint.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fc7ab8f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:latest + +RUN apk --update --no-cache add yq + +COPY entrypoint.sh /entrypoint.sh +RUN chmod a+x /entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c46e614 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +DOMAIN=$DOMAIN +SELECTOR=$HOMEASSISTANT +HOMEASSISTANT_IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d '/' -f1) +HOST_FILE=/etc/system/data/dns/host.local; + +EXISTS=$(grep -w -F $SELECTOR $HOST_FILE); +if [ -n "$EXISTS" ]; then + # selector already exists in hosts file and SCALE is not in use + IP=$(echo $EXISTS | cut -d ' ' -f1); + sed "s/'$IP'/'$HOMEASSISTANT_IP'/g" $HOST_FILE > /tmp/host.local + mv /tmp/host.local $HOST_FILE; +else + echo "'$HOMEASSISTANT_IP' '$SELECTOR'" >> $HOST_FILE +fi + +mkdir -p /etc/user/data/homeassistant/config + +if [ ! -f /etc/user/data/homeassistant/config/config.yaml ]; then + + echo '# Loads default set of integrations. Do not remove. +default_config: +homeassistant: + external_url: "DOMAIN" +http: + use_x_forwarded_for: true + trusted_proxies: + - 172.18.104.2 + - 172.18.105.2 +# Load frontend themes from the themes folder +frontend: + themes: !include_dir_merge_named themes + +automation: !include automations.yaml +script: !include scripts.yaml +scene: !include scenes.yaml + ' >/etc/user/data/homeassistant/config/config.yaml +fi + +yq eval .'.homeassistant.external_url = "'$DOMAIN'"' -i /etc/user/data/homeassistant/config/config.yaml