35 lines
1.0 KiB
Bash
35 lines
1.0 KiB
Bash
#!/bin/sh
|
|
|
|
HOMEASSISTANT_DOMAIN="https://$DOMAIN";
|
|
SELECTOR=$HOMEASSISTANT
|
|
HOMEASSISTANT_IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d '/' -f1)
|
|
HOST_FILE=/etc/system/data/dns/hosts.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/hosts.local
|
|
mv /tmp/hosts.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/configuration.yaml ]; then
|
|
|
|
echo '# Loads default set of integrations. Do not remove.
|
|
default_config:
|
|
homeassistant:
|
|
external_url: "http://localhost"
|
|
http:
|
|
use_x_forwarded_for: true
|
|
trusted_proxies:
|
|
- 172.18.104.2
|
|
- 172.18.105.2' >/etc/user/data/homeassistant/config/configuration.yaml
|
|
|
|
fi
|
|
|
|
yq eval '.homeassistant.external_url = "'$HOMEASSISTANT_DOMAIN'"' -i /etc/user/data/homeassistant/config/configuration.yaml
|