#!/usr/bin/env bash set -euo pipefail echo "=== HX-KI Homepage Setup (Falkenstein) ===" ######################################## # 0. PARAMETER ######################################## # Falls dein Next.js-Projekt woanders liegt: HIER anpassen. WEB_ROOT="/opt/hx-ki/web/nextjs" WORKSPACE="/opt/hx-ki/workspaces/homepage" AGENT_DIR="/opt/hx-ki/agents" API_DIR="$WEB_ROOT/app/api/homepage" echo "WEB_ROOT: $WEB_ROOT" echo "WORKSPACE: $WORKSPACE" echo "AGENT_DIR: $AGENT_DIR" echo "API_DIR: $API_DIR" echo ######################################## # 1. VERZEICHNISSE ANLEGEN ######################################## mkdir -p "$WORKSPACE" mkdir -p "$AGENT_DIR" mkdir -p "$API_DIR" echo "✔ Verzeichnisse angelegt." ######################################## # 2. BASIS-HOMEPAGE.JSON ANLEGEN (FALLS NICHT VORHANDEN) ######################################## HOMEPAGE_JSON="$WORKSPACE/homepage.json" if [[ ! -f "$HOMEPAGE_JSON" ]]; then cat > "$HOMEPAGE_JSON" < "$AGENT_SCRIPT" <<'EOF' #!/usr/bin/env python3 import json import os WORKSPACE = "/opt/hx-ki/workspaces/homepage" FILE = os.path.join(WORKSPACE, "homepage.json") os.makedirs(WORKSPACE, exist_ok=True) content = { "hero_title": "HX-KI – Dynamischer JSON-Agent", "hero_sub": "Content kommt aus dem Workspace auf Falkenstein – kein Zugriff auf Gehirn oder Motor.", "sections": [ { "title": "Agent-Status", "text": "Dieser JSON-Agent kann von Events, Cron, KI oder Mautic getriggert werden." }, { "title": "Architektur-Sicherheit", "text": "Falkenstein liest nur den Workspace. Nürnberg & Helsinki bleiben intern." } ] } with open(FILE, "w") as f: json.dump(content, f, indent=2) print(f"✔ homepage.json durch json_homepage_agent.py erzeugt/aktualisiert: {FILE}") EOF chmod +x "$AGENT_SCRIPT" echo "✔ JSON-Agent angelegt: $AGENT_SCRIPT" ######################################## # 4. SELBSTHEILUNG FÜR HOMEPAGE.JSON ######################################## REPAIR_SCRIPT="$WORKSPACE/repair_homepage_json.sh" cat > "$REPAIR_SCRIPT" <<'EOF' #!/usr/bin/env bash set -euo pipefail FILE="/opt/hx-ki/workspaces/homepage/homepage.json" echo "=== Repair homepage.json ===" if [[ ! -f "$FILE" ]]; then echo "✘ homepage.json fehlt – wird neu erstellt." cat > "$FILE" < "$FILE" </dev/null | grep -v "$REPAIR_SCRIPT" || true; echo "$CRON_LINE" ) | crontab - echo "✔ Cronjob für Repair installiert (alle 5 Minuten)." ######################################## # 6. NEXT.JS API-ROUTE FÜR /api/homepage ######################################## ROUTE_FILE="$API_DIR/route.ts" cat > "$ROUTE_FILE" <<'EOF' import { NextResponse } from "next/server"; import fs from "fs"; export async function GET() { const path = "/opt/hx-ki/workspaces/homepage/homepage.json"; try { const raw = fs.readFileSync(path, "utf-8"); const data = JSON.parse(raw); return NextResponse.json(data); } catch (err) { console.error("Error reading homepage.json:", err); return NextResponse.json( { error: "Homepage content not available", details: "Check /opt/hx-ki/workspaces/homepage/homepage.json on Falkenstein." }, { status: 500 } ); } } EOF echo "✔ Next.js API-Route erstellt: $ROUTE_FILE" ######################################## # 7. ERSTEN LAUF DES JSON-AGENTEN AUSFÜHREN ######################################## echo "=== Erster Lauf des JSON-Agents ===" "$AGENT_SCRIPT" || echo "Warnung: JSON-Agent konnte nicht ausgeführt werden." echo echo "=== Fertig. Schritte als Nächstes: ===" echo "1) Stelle sicher, dass WEB_ROOT korrekt ist (aktuell: $WEB_ROOT)." echo "2) Baue/Starte dein hxki-web / Next.js-Container neu." echo "3) Rufe im Browser /api/homepage auf – dort sollte JSON kommen." echo "4) Binde in app/page.tsx o.ä. fetch('https://DEINE-DOMAIN/api/homepage') ein." echo echo "=== HX-KI Homepage Setup (Falkenstein) – COMPLETE ==="