#!/usr/bin/env bash set -Eeuo pipefail umask 077 repo_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) source_file=$repo_dir/platform/mcp/patches/hass_mcp/yaml_config.py ha_config_dir=${1:-} die() { printf 'FEHLER: %s\n' "$*" >&2; exit 1; } [[ $EUID -eq 0 ]] || die "Bitte als root auf dem Home-Assistant-Host ausführen." [[ -n $ha_config_dir ]] || die "Aufruf: $0 /pfad/zum/home-assistant-config" [[ -s $source_file ]] || die "Patchdatei fehlt: $source_file" target=$ha_config_dir/custom_components/hass_mcp/tools/yaml_config.py [[ -s $target ]] || die "Native hass_mcp-Installation nicht gefunden: $target" backup_dir=$ha_config_dir/.hass_mcp_patch_backups mkdir -p "$backup_dir" chmod 700 "$backup_dir" stamp=$(date +%Y%m%d-%H%M%S) backup=$backup_dir/yaml_config.py.before-guard-$stamp cp -p "$target" "$backup" chmod 600 "$backup" install -m 0644 "$source_file" "$target" printf 'YAML Guard installiert. Sicherung: %s\n' "$backup" printf 'Home Assistant muss jetzt kontrolliert neu gestartet werden.\n'