added statement when IP is in local network

This commit is contained in:
2025-02-12 08:51:16 +01:00
parent 95aebca03a
commit d58638800d

View File

@@ -1,18 +1,22 @@
#!/bin/sh #!/bin/sh
HOMEASSISTANT_DOMAIN="https://$DOMAIN"; HOMEASSISTANT_DOMAIN="https://$DOMAIN";
SELECTOR=$HOMEASSISTANT
HOMEASSISTANT_IP=$(hostname -i | awk '{print $1}')
HOST_FILE=/etc/system/data/dns/hosts.local;
EXISTS=$(grep -w -F $SELECTOR $HOST_FILE); if [ "$DOMAIN" == "localhost" ]; then
if [ -n "$EXISTS" ]; then
# selector already exists in hosts file and SCALE is not in use SELECTOR=$HOMEASSISTANT
IP=$(echo $EXISTS | cut -d ' ' -f1); HOMEASSISTANT_IP=$(hostname -i | awk '{print $1}')
sed "s/$IP/$HOMEASSISTANT_IP/g" $HOST_FILE > /tmp/hosts.local HOST_FILE=/etc/system/data/dns/hosts.local;
mv /tmp/hosts.local $HOST_FILE;
else EXISTS=$(grep -w -F $SELECTOR $HOST_FILE);
echo "$HOMEASSISTANT_IP $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
fi fi
mkdir -p /etc/user/data/homeassistant/config mkdir -p /etc/user/data/homeassistant/config
@@ -22,13 +26,16 @@ if [ ! -f /etc/user/data/homeassistant/config/configuration.yaml ]; then
echo '# Loads default set of integrations. Do not remove. echo '# Loads default set of integrations. Do not remove.
default_config: default_config:
homeassistant: homeassistant:
external_url: "http://localhost" external_url: "'$HOMEASSISTANT_DOMAIN'"
http: http:
use_x_forwarded_for: true use_x_forwarded_for: true
trusted_proxies: trusted_proxies:' >/etc/user/data/homeassistant/config/configuration.yaml
- 172.18.104.2
- 172.18.105.2' >/etc/user/data/homeassistant/config/configuration.yaml
PROXIES=$(grep -w smarthostbackend $HOST_FILE| awk '{print $1}')
for PROXY in $(echo $PROXIES) ; do
echo " - '$PROXY'" >>/etc/user/data/homeassistant/config/configuration.yaml
done
fi fi
yq eval '.homeassistant.external_url = "'$HOMEASSISTANT_DOMAIN'"' -i /etc/user/data/homeassistant/config/configuration.yaml yq eval '.homeassistant.external_url = "'$HOMEASSISTANT_DOMAIN'"' -i /etc/user/data/homeassistant/config/configuration.yaml