Upload start-homeassistant
Browse files- scripts/start-homeassistant +13 -13
scripts/start-homeassistant
CHANGED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
#!/
|
| 2 |
-
set -
|
| 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 [
|
| 9 |
-
python3 /usr/local/bin/backup-homeassistant.py restore --config "$CONFIG_DIR" || true
|
| 10 |
fi
|
| 11 |
|
| 12 |
-
if [
|
| 13 |
cp -a "$CUSTOM_COMPONENT" "$CONFIG_DIR/custom_components/xiaomi_miot"
|
| 14 |
fi
|
| 15 |
|
| 16 |
-
if [
|
| 17 |
cat > "$CONFIG_DIR/configuration.yaml" <<'YAML'
|
| 18 |
default_config:
|
| 19 |
|
|
@@ -22,7 +22,7 @@ http:
|
|
| 22 |
YAML
|
| 23 |
fi
|
| 24 |
|
| 25 |
-
if [
|
| 26 |
(
|
| 27 |
while sleep 600; do
|
| 28 |
python3 /usr/local/bin/backup-homeassistant.py backup --config "$CONFIG_DIR" || true
|
|
@@ -34,13 +34,13 @@ else
|
|
| 34 |
fi
|
| 35 |
|
| 36 |
cleanup() {
|
| 37 |
-
if [
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
python3 /usr/local/bin/backup-homeassistant.py backup --config "$CONFIG_DIR" || true
|
| 40 |
fi
|
| 41 |
}
|
| 42 |
trap cleanup EXIT TERM INT
|
| 43 |
|
| 44 |
-
hass --config "$CONFIG_DIR" --port 7860
|
| 45 |
-
HA_PID=$!
|
| 46 |
-
wait "$HA_PID"
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
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 |
|
| 12 |
+
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 |
|
|
|
|
| 22 |
YAML
|
| 23 |
fi
|
| 24 |
|
| 25 |
+
if [ -n "${HF_TOKEN:-}" ] && [ -n "${BACKUP_REPO_ID:-}" ]; then
|
| 26 |
(
|
| 27 |
while sleep 600; do
|
| 28 |
python3 /usr/local/bin/backup-homeassistant.py backup --config "$CONFIG_DIR" || true
|
|
|
|
| 34 |
fi
|
| 35 |
|
| 36 |
cleanup() {
|
| 37 |
+
if [ -n "$BACKUP_PID" ]; then
|
| 38 |
+
kill "$BACKUP_PID" 2>/dev/null || true
|
| 39 |
+
fi
|
| 40 |
+
if [ -n "${HF_TOKEN:-}" ] && [ -n "${BACKUP_REPO_ID:-}" ]; then
|
| 41 |
python3 /usr/local/bin/backup-homeassistant.py backup --config "$CONFIG_DIR" || true
|
| 42 |
fi
|
| 43 |
}
|
| 44 |
trap cleanup EXIT TERM INT
|
| 45 |
|
| 46 |
+
exec hass --config "$CONFIG_DIR" --port 7860
|
|
|
|
|
|