YYP0502 commited on
Commit
441269b
·
verified ·
1 Parent(s): bedf0a7

Upload start-homeassistant

Browse files
Files changed (1) hide show
  1. scripts/start-homeassistant +20 -3
scripts/start-homeassistant CHANGED
@@ -3,9 +3,10 @@ set -eu
3
 
4
  CONFIG_DIR="${HOME_ASSISTANT_CONFIG:-/data/home-assistant}"
5
  CUSTOM_COMPONENT="/opt/ha-custom-components/xiaomi_miot"
 
6
 
7
  mkdir -p "$CONFIG_DIR/custom_components"
8
- if [ ! -f "$CONFIG_DIR/configuration.yaml" ]; then
9
  python3 /usr/local/bin/backup-homeassistant.py restore --config "$CONFIG_DIR" || true
10
  fi
11
 
@@ -13,13 +14,29 @@ if [ ! -d "$CONFIG_DIR/custom_components/xiaomi_miot" ]; then
13
  cp -a "$CUSTOM_COMPONENT" "$CONFIG_DIR/custom_components/xiaomi_miot"
14
  fi
15
 
16
- if [ ! -f "$CONFIG_DIR/configuration.yaml" ]; then
17
- cat > "$CONFIG_DIR/configuration.yaml" <<'YAML'
18
  default_config:
19
 
20
  http:
21
  server_port: 7860
 
 
 
22
  YAML
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  fi
24
 
25
  if [ -n "${HF_TOKEN:-}" ] && [ -n "${BACKUP_REPO_ID:-}" ]; then
 
3
 
4
  CONFIG_DIR="${HOME_ASSISTANT_CONFIG:-/data/home-assistant}"
5
  CUSTOM_COMPONENT="/opt/ha-custom-components/xiaomi_miot"
6
+ CONFIG_FILE="$CONFIG_DIR/configuration.yaml"
7
 
8
  mkdir -p "$CONFIG_DIR/custom_components"
9
+ if [ ! -f "$CONFIG_FILE" ]; then
10
  python3 /usr/local/bin/backup-homeassistant.py restore --config "$CONFIG_DIR" || true
11
  fi
12
 
 
14
  cp -a "$CUSTOM_COMPONENT" "$CONFIG_DIR/custom_components/xiaomi_miot"
15
  fi
16
 
17
+ if [ ! -f "$CONFIG_FILE" ]; then
18
+ cat > "$CONFIG_FILE" <<'YAML'
19
  default_config:
20
 
21
  http:
22
  server_port: 7860
23
+ use_x_forwarded_for: true
24
+ trusted_proxies:
25
+ - 10.0.0.0/8
26
  YAML
27
+ elif ! grep -q 'use_x_forwarded_for:' "$CONFIG_FILE"; then
28
+ if grep -q '^ server_port: 7860' "$CONFIG_FILE"; then
29
+ sed -i '/^ server_port: 7860/a\ use_x_forwarded_for: true\n trusted_proxies:\n - 10.0.0.0/8' "$CONFIG_FILE"
30
+ else
31
+ cat >> "$CONFIG_FILE" <<'YAML'
32
+
33
+ http:
34
+ server_port: 7860
35
+ use_x_forwarded_for: true
36
+ trusted_proxies:
37
+ - 10.0.0.0/8
38
+ YAML
39
+ fi
40
  fi
41
 
42
  if [ -n "${HF_TOKEN:-}" ] && [ -n "${BACKUP_REPO_ID:-}" ]; then