The four-levels-up guess resolved to ~/ once this repo moved to ~/projects; fall back to the homelab checkout (HOMELAB_DIR, default ~/homelab). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
65 lines
2.7 KiB
Bash
Executable File
65 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install (or update) the ai_agent custom integration into the homelab's
|
|
# Home Assistant config, wire its configuration.yaml block, and optionally
|
|
# restart HA to load it.
|
|
#
|
|
# Usage:
|
|
# ./install.sh # copy component + ensure config block
|
|
# ./install.sh --restart # …then docker restart home-assistant
|
|
#
|
|
# Idempotent: re-running just refreshes the component files.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# Where Home Assistant's config lives. This repo used to sit inside the homelab
|
|
# (services/ai-agent/…), so the legacy four-levels-up guess is tried first and
|
|
# the homelab checkout second; $HA_CONFIG overrides both.
|
|
LEGACY_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
if [[ -z "${HA_CONFIG:-}" ]]; then
|
|
for candidate in "$LEGACY_ROOT/services/home-assistant/config" \
|
|
"${HOMELAB_DIR:-$HOME/homelab}/services/home-assistant/config"; do
|
|
[[ -d "$candidate" ]] && { HA_CONFIG="$candidate"; break; }
|
|
done
|
|
fi
|
|
HA_CONFIG="${HA_CONFIG:-$LEGACY_ROOT/services/home-assistant/config}"
|
|
RESTART=0
|
|
[[ "${1:-}" == "--restart" ]] && RESTART=1
|
|
|
|
[[ -d "$HA_CONFIG" ]] || { echo "error: HA config dir not found: $HA_CONFIG" >&2; exit 1; }
|
|
|
|
mkdir -p "$HA_CONFIG/custom_components"
|
|
rm -rf "$HA_CONFIG/custom_components/ai_agent"
|
|
cp -r "$SCRIPT_DIR/custom_components/ai_agent" "$HA_CONFIG/custom_components/ai_agent"
|
|
echo "installed custom_components/ai_agent -> $HA_CONFIG/custom_components/"
|
|
|
|
# Ensure the ai_agent: block exists in configuration.yaml (append if missing).
|
|
CONF="$HA_CONFIG/configuration.yaml"
|
|
if ! grep -qE '^ai_agent:' "$CONF"; then
|
|
cat >>"$CONF" <<'EOF'
|
|
|
|
# AI Agent notifications: webhook target for the ai-agent backend's notify hub
|
|
# (services/ai-agent/integrations/home-assistant). Receives notify/ask events
|
|
# on /api/webhook/ai_agent and pushes them to the phone; ask answers are
|
|
# POSTed back to the ai-agent backend on the host port.
|
|
# `phone_service` (optional) is called for the voice leg of every notify —
|
|
# in the homelab that rings the AI desk phone (services/phone) through
|
|
# packages/ai_agent_phone.yaml. Drop the line for screen-only notifications.
|
|
ai_agent:
|
|
webhook_id: ai_agent
|
|
notify_target: mobile_app_pixel_9
|
|
callback_url: http://127.0.0.1:8096
|
|
phone_service: script.ai_agent_phone_notify
|
|
EOF
|
|
echo "appended ai_agent: block to configuration.yaml"
|
|
else
|
|
echo "configuration.yaml already has an ai_agent: block — left untouched"
|
|
fi
|
|
|
|
if [[ "$RESTART" == "1" ]]; then
|
|
echo "restarting home-assistant…"
|
|
docker restart home-assistant
|
|
echo "done — check the log: docker logs home-assistant 2>&1 | grep ai_agent"
|
|
else
|
|
echo "now restart HA to load it: docker restart home-assistant"
|
|
fi
|